<script>
import $api from 'static/js/api.js';
import $app from 'static/js/app.js';
export default {
	onLaunch: function (options) {
		console.log('App Launch')
	},
	onShow: function (options) {
		// 判断用户是否通过分销码进入------------------------------------------------------
		if (options.scene === 1011 || options.scene === 1012 || options.scene === 1013) {
			const decodedUrl = decodeURIComponent(options.query.q);
			const urlParts = decodedUrl.split('?');
			if (urlParts.length > 1) {
				const queryParams = urlParts[1];
				const paramPairs = queryParams.split('&');
				const resultObj = {};
				paramPairs.forEach(pair => {
					const [key, value] = pair.split('=');
					resultObj[key] = value;
				});
				const adminUserId = resultObj['adminUserId'];
				const frimId = resultObj['frimId'];
				console.log(frimId, '----企业用户');
				uni.setStorageSync('FRIM_ID', frimId)
				uni.setStorageSync('ADMIN_USERID', adminUserId);
				console.info(uni.getStorageSync('ADMIN_USERID'), '---用户通过扫码进入')
			}
		}

		// 自动更新管理-------------------------------------------------------------------
		const updateManager = uni.getUpdateManager();
		updateManager.onUpdateReady(function (res) {
			uni.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启应用？',
				success(res) {
					if (res.confirm) updateManager.applyUpdate();
				}
			});
		});
		updateManager.onUpdateFailed(function (res) {
			uni.showModal({
				title: '更新失败',
				content: '小程序已有新版本,请稍后重试更新!',
				showCancel: false
			});
		});

		// 自动登录用户-------------------------------------------------------------------
		//#ifdef MP-WEIXIN
		const userInfo = $app.storage.get("USER_INFO");
		// if (!userInfo) $api.login();
		//#endif
	},
	onHide: function () {
		console.log('App Hide')
	}
}
</script>

<style>
/*每个页面公共css */
@import "components/ax/ax.css";
@import "static/css/app.css";
</style>