<script>
	import {
		useI18n
	} from 'vue-i18n'
	import {
		getAppVersion
	} from './common/request/api/api'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// #ifdef APP-NVUE
			domModule.addRule('fontFace', {
				'fontFamily': "Regular",
				'src': "url('https://dushuba.oss-cn-guangzhou.aliyuncs.com/fonts/MiSans-Regular.ttf')"
			});
			domModule.addRule('fontFace', {
				'fontFamily': "Medium",
				'src': "url('https://dushuba.oss-cn-guangzhou.aliyuncs.com/fonts/MiSans-Medium.ttf')"
			});
			domModule.addRule('fontFace', {
				'fontFamily': "Bold",
				'src': "url('https://dushuba.oss-cn-guangzhou.aliyuncs.com/fonts/MiSans-Demibold.ttf')"
			});
			domModule.addRule('fontFace', {
				'fontFamily': "DOUYU",
				'src': "url('https://dushuba.oss-cn-guangzhou.aliyuncs.com/fonts/douyuFont.otf')"
			});
			domModule.addRule('fontFace', {
				'fontFamily': "Bebas",
				'src': "url('https://dushuba.oss-cn-guangzhou.aliyuncs.com/fonts/BEBAS.ttf')"
			});
			// #endif

		},
		onShow: function() {
			//语言变更
			console.log('App Show')
			const getI18n = useI18n()
			const {
				t,
				locale
			} = getI18n
			if (!uni.getStorageSync('locale')) {
				locale.value = 'en'
				uni.setStorageSync('locale', locale.value)
			} else {
				locale.value = uni.getStorageSync('locale')
			}

			//登录状态变更
			let tokenStr = ''
			tokenStr = uni.getStorageSync('TOKEN')
			if (tokenStr === '') {
				uni.reLaunch({
					url: '/pages/client/account/login',
				})
			}

			//不要问我为什么这么写，但你先别觉得，去问客户
			const appVersion = '0.0.1' //珠海版本号
			const appTaiGuoVersion = '0.0.1' //泰国版本号

			//版本信息获取以及更新
			getAppVersion().then(res => {
				console.log(res);
				let appLoginInfo = uni.getStorageSync('appLoginInfo')
				let patternId = appLoginInfo.organizationObj['FOrgOrgId.FNumber']
				var pages = getCurrentPages();
				var page = pages[pages.length - 1];
				var currentWebview = page.$getAppWebview();
				let pageUrl = '/uni_modules/uni-upgrade-center-app/pages/upgrade-popup'
				if (pageUrl.indexOf(currentWebview.__uniapp_route) == -1) {
					uni.setStorageSync('local_storage_key', res.data)
					if (Object.keys(appLoginInfo).length !== 0) {
						//珠海
						if (patternId === '101') {
							if (appVersion !== res.data.version) {
								uni.$u.route({
									url: pageUrl,
									params: {
										local_storage_key: 'local_storage_key',
										patternId: '101'
									}
								})
							}
						}
						//泰国
						if (patternId === '103') {
							if (appTaiGuoVersion !== res.data.taiGuoVersion) {
								uni.$u.route({
									url: pageUrl,
									params: {
										local_storage_key: 'local_storage_key',
										patternId: '103'
									}
								})
							}
						}
					}
				}

			})
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {

		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-plus/index.scss";
	@import '@/static/css/main.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/css/vue.scss';
	/* #endif */
	@import '@/static/css/animista.scss';

	:deep(.uni-tabbar-bottom) {
		z-index: 0 !important;
	}
</style>