uni-app移动端-H5-微信小程序在线预览pdf,图片,视频

封装了一个插件,可直接导入hbuilderx查看使用;
插件地址:uni-app移动端-H5-微信小程序在线预览pdf,图片,视频

<template>
	<view class="page">
		<!-- 预览图片 -->
		<view v-if="previews.type === '1'" class="g-p-16" style="width:100%;height:100vh;margin:0 auto;">
			<image :src="src" style="width:100%;height:100%;" mode="aspectFit"></image>
		</view>
		<!-- 预览文件 -->
		<web-view :webview-styles="webviewStyles" :src="src" v-if="previews.type === '2'"></web-view>
		<!-- 预览视频 -->
		<view class="video-detail-page" v-if="previews.type === '3'">
			<view class="video-box">
				<video v-if="src" :src="src"></video>
			</view>
		</view>	
	</view>
</template>

<script>
export default {
	data() {
		return {
			fileSrc: '',
			webviewStyles: {
				progress: {
					color: '#FF3333'
				}
			},
			url: '',
			src: '',
			previews: {
				type: '1'
			}
		};
	},
	onLoad(option) {
		console.log('file', option.file);
		
		if (option.file) {
			console.log(333, option);
			this.previews.type = option.type;
			let types = option.file.substr(option.file.lastIndexOf('.'));
			if (types === '.doc' || types === '.docx' || types === '.xls' || types === '.xlsx' || types === '.pdf') {
				let url = option.file;
				this.fileSrc = encodeURIComponent(url);
				this.src = `/hybrid/html/pdf-reader/index.html?file=${this.fileSrc}`;
			}else{
				this.src = option.file;
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.page {
	height: 100%;
	.video-detail-page{
		width:100%;
		uni-video{
			width:100%;
		}
		video{
			width:100%;
		}
	}
}
</style>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值