<template>
	<view class="main">
		<!-- <code-elf-guide v-if="guidePages"></code-elf-guide> -->
		<!-- #ifdef APP-PLUS -->
		<video :enable-progress-gesture="false" class="video" v-if="guidePages" @ended="goPage" src="@/static/start.mp4" :show-center-play-btn="false" object-fit="fill" :autoplay="true" :controls="false"></video>
		<cover-view class="mask_bg"></cover-view>
		<!-- #endif -->
	</view>
</template>

<script>
	import codeElfGuide from '@/components/code-elf-guide/code-elf-guide.vue'
	export default {
        components: {
            codeElfGuide
        },
		data() {
			return {
				guidePages: false
			}
		},
		onLoad(){
			// #ifdef APP-PLUS
			this.loadExecution();
			// #endif
			// #ifdef H5
			uni.reLaunch({
				url: '/pages/index/index'
			});
			// #endif
		},
		methods: {
			goPage () {
				uni.setStorage({
					key: 'launchFlag', 
					data: true, 
					success: function () {
						console.log('error时存储launchFlag');
					} 
				}); 
				uni.reLaunch({
					url: '/pages/index/index'
				});
			},
			loadExecution: function(){
				/**
				 * 获取本地存储中launchFlag的值
				 * 若存在，说明不是首次启动，直接进入首页；
				 * 若不存在，说明是首次启动，进入引导页；
				 */
				try {
					// 获取本地存储中launchFlag标识
				    const value = uni.getStorageSync('launchFlag');
				    if (value) {
						// launchFlag=true直接跳转到首页
						uni.reLaunch({
							url: '/pages/index/index'
						});
				    } else {
						// launchFlag!=true显示引导页
				        setTimeout(() => {
							this.guidePages = true
						}, 7*1000)
				    }
				} catch(e) { 
					error 
					uni.setStorage({ 
						key: 'launchFlag', 
						data: true, 
						success: function () {
							console.log('error时存储launchFlag');
						} 
					}); 
					setTimeout(() => {
						this.guidePages = true
					}, 7*1000)
				}
				return;
				uni.reLaunch({
				    url: '/pages/index/index'
				});
			},
		}
	}
</script>

<style>
	page,.main{
		width: 100%;
		height: 100%;
	}
	.video {
		width: 100%;
		height: 100vh;
	}
	.mask_bg {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background-color: transparent;
		z-index: 2;
	}
</style>
