preview.vue 2.2 KB
Newer Older
VK1688's avatar
1.2.0  
VK1688 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<template>
	<vk-data-dialog
		v-model="value.show"
		:title="page.title"
		:top="page.top"
		:width="page.width"
		:close-on-click-modal="true"
		:show-fullscreen="false"
		:show-header="false"
		:destroy-on-close="true"
		mode="form"
	>
		<!-- 页面主体内容开始 -->
		<image v-if="value.item.type === 'image'" :src="value.item.url" mode="widthFix" style="width: 100%;display: block;"></image>
VK1688's avatar
1.2.2  
VK1688 已提交
15 16
		<view v-else-if="value.item.type === 'video' && value.show" :style="styleCom" style="margin: auto;">
			<video :src="value.item.url" autoplay object-fit="cover" style="width: 100%;height: 100%;display: block;"></video>
VK1688's avatar
1.2.0  
VK1688 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
		</view>
		<!-- 页面主体内容结束 -->
	</vk-data-dialog>
</template>

<script>
var that; // 当前页面对象
var vk = uni.vk; // vk实例
export default {
	props: {
		value: {
			Type: Object,
			default: function() {
				return {
					show: false,
					mode: "",
					item: {}
				};
			}
		}
	},
	data: function() {
		// 组件创建时,进行数据初始化
		return {
			page: {
				title: "预览",
				submitText: "确定",
				cancelText: "关闭",
				showCancel: true,
				top: "2vh",
				width: "600px"
			},
			styleCom:{}
		};
	},
	mounted() {
		that = this;
		that.init();
	},
	methods: {
		// 初始化
		init() {
			let { value } = that;
			that.$emit("input", value);
		},
		// 监听 - 页面打开
		onOpen() {
			that = this;
			let { item } = that.value;
			let { width, height=700, type } = item;
			//if(type === "video"){
				let showWidth = width;
				let showHeight = height;
				let maxHeight = 700;
				if(height > maxHeight){
					showHeight = maxHeight;
					showWidth = width / height * maxHeight;
				}
				that.styleCom = {
					width : `${showWidth}px`,
					height : `${showHeight}px`
				};
				that.page.width = that.styleCom.width;
				that.$set(that.value.item,"play",true);
			//}
		},
		// 监听 - 页面关闭
		onClose() {
			that.$set(that.value.item,"play",false);
		}
	},
	watch: {
		"value.show": {
			handler(newValue, oldValue) {
				let that = this;
				if (newValue) {
					that.onOpen();
				} else {
					that.onClose();
				}
			}
		}
	},
	// 过滤器
	filters: {},
	// 计算属性
	computed: {}
};
</script>

<style lang="scss" scoped></style>