<script>
	import {
		getToken
	} from '@/utils/auth';
	import {
		ParseAccessToken
	} from '@/api/api';
	import {
		loginControlIsEffectiveUser
	} from '@/api/user.js';

	export default {
		onLaunch: function(options) {
			// console.log(window.location);
		},
		onShow: function() {
			// console.log('App Show')
		},
		onHide: function() {
			// console.log('App Hide')
		},
		/* 配置页面未找到 */
		onPageNotFound: function(options) {
			const openShare = 'open/share/exercise';
			const _path = window.location.hash;
			if (_path.includes(openShare)) {
				const share_record_id = options.query.share_record_id;
				uni.getStorage({
					key: 'AccessToken',
					success: function(res) {
						ParseAccessToken({
							access_token: res.data
						}).then(({
							is_effective
						}) => {
							if (is_effective == 'true' && share_record_id) {
								uni.navigateTo({
									url: '/pages/answer_question/answer/index?share_record_id=' + share_record_id +
										'&isScanCode=true'
								})
							} else {
								uni.navigateTo({
									url: '/pages/login/index?share_record_id=' + share_record_id
								})
							}
						});
					},
					fail: function(error) {
						uni.navigateTo({
							url: '/pages/login/index?share_record_id=' + share_record_id
						})
					}
				})
			} else {
				uni.getStorage({
					key: 'AccessToken',
					success: function(res) {
						ParseAccessToken({
							access_token: res.data
						}).then(({
							is_effective
						}) => {
							if (is_effective == 'true') {
								uni.navigateTo({
									url: options.path,
									fail(error) {
										uni.redirectTo({
											url: "pages/404", // 404 页面的路径
										});
									}
								})
							} else {
								uni.navigateTo({
									url: '/pages/login/index'
								})
							}
						});
					},
					fail: function(error) {
						uni.navigateTo({
							url: '/pages/login/index'
						})
					}
				})

			}
		},
	}
</script>

<style>
	/*每个页面公共css */
	body {
		background-color: #f4f2f4;
	}

	/*去掉浏览器输入框自带小眼睛图标*/
	.uni-easyinput__content-input ::-ms-reveal {
		display: none;
	}

	.uni-easyinput__content-input ::-ms-clear {
		display: none;
	}

	.uni-easyinput__content-input ::-o-clear {
		display: none;
	}

	/*图片等比缩放*/
	/deep/ img {
		width: auto;
		height: auto;
		max-width: 100%;
		max-height: 100%;
	}
</style>