video-preview.vue 2.22 KB
<template>
	<view class="video-preview-container">
		<view class="video-header">
			<view class="header-left" @click="goBack">
				<u-icon name="arrow-left" color="#fff" size="20"></u-icon>
			</view>
			<view class="header-title">{{ videoName }}</view>
			<view class="header-right"></view>
		</view>
		<view class="video-wrapper">
			<video 
				:src="videoUrl" 
				controls 
				:show-center-play-btn="true"
				:enable-play-gesture="true"
				:show-fullscreen-btn="true"
				class="video-player"
				@error="onVideoError"
			></video>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				videoUrl: '',
				videoName: '视频'
			}
		},
		onLoad() {
			const url = uni.getStorageSync('videoUrl');
			const name = uni.getStorageSync('videoName');
			
			if (!url) {
				uni.showToast({
					title: '视频地址不存在',
					icon: 'none'
				});
				setTimeout(() => {
					this.goBack();
				}, 1500);
				return;
			}
			
			this.videoUrl = url;
			this.videoName = name || '视频';
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			onVideoError(e) {
				console.error('视频加载失败:', e);
				uni.showToast({
					title: '视频加载失败',
					icon: 'none',
					duration: 2000
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.video-preview-container {
		width: 100%;
		height: 100vh;
		background-color: #000;
		display: flex;
		flex-direction: column;
	}
	
	.video-header {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		height: 80px;
		background-color: rgba(0, 0, 0, 0.7);
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 15px;
		z-index: 100;
		padding-top: 20px;
		
		.header-left {
			width: 40px;
			height: 40px;
			display: flex;
			align-items: center;
			justify-content: center;
		}
		
		.header-title {
			flex: 1;
			text-align: center;
			color: #fff;
			font-size: 16px;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			padding: 0 20px;
		}
		
		.header-right {
			width: 40px;
		}
	}
	
	.video-wrapper {
		flex: 1;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		padding-top: 80px;
		
		.video-player {
			width: 100%;
			height: 100%;
		}
	}
</style>