// app.js const { checkUserWhiteListId } = require('./utils/api/api') const versionConfig = require("./version.js") App({ data: { /*** * 用户信息 */ //用户基础信息-常客 userInfo: null, //用户基础信息-访客 visitorUserInfo: null, //用户额外信息-访客 visitorExtraInfo: null, /*** * 账号信息 */ //账号信息-常客 adminInfo: null, //账号信息-访客 visitorAdminInfo: null, //账号信息-临时 temporaryAdminInfo: null, /*** * 配置项 */ //何种扫码方式 0->普通码 1->常客码 type: 0, //中英文 language: 'ch', /** * 其他业务数据 */ //换取小程序用户信息的密钥 wxCode: null, //二维码信息 qrcodeInfo: null, //人脸识别任务 id faceTaskId: null, //定时器 timer: null, /** * 渲染基础数据 */ //右上角胶囊位置 statusBarCont: {}, //(过审专用,禁止删除)- start fake: true, myAppointment: null, //(过审专用,禁止删除)- end }, onLaunch() { //版本检查 this.checkVersion() //缓存值赋值 this.getStorage() //提前获取 wxCode this.getWxCode() //获取胶囊按钮位置信息 this.getMenuButtonInfo() //检测缓存中的常客是否有效(存在) this.checkAdminInfoOfUser() }, //版本判断 checkVersion() { const oldVersion = wx.getStorageSync('version') || null; //若当前无缓存 let infoList = wx.getStorageInfoSync() if(infoList.keys.length <= 0) { //缓存当前版本 wx.setStorageSync('version', versionConfig.version) return; } //当前无版本号或大版本更新 if (!oldVersion || Number(versionConfig.version.split('.')[0]) > Number(oldVersion.split('.')[0])) { let infoList = wx.getStorageInfoSync() infoList.keys.forEach(item => { wx.removeStorageSync(item) }); wx.showModal({ content: '小程序已升级到2.0.10,请重新认证后使用', complete: (res) => {} }) } //缓存当前版本 wx.setStorageSync('version', versionConfig.version) }, //缓存值赋值 getStorage() { this.data.userInfo = wx.getStorageSync('userInfo') || null this.data.visitorUserInfo = wx.getStorageSync('visitorUserInfo') || null this.data.visitorExtraInfo = wx.getStorageSync('visitorExtraInfo') || null this.data.adminInfo = wx.getStorageSync('adminInfo') || null this.data.visitorAdminInfo = wx.getStorageSync('visitorAdminInfo') || null this.data.language = wx.getStorageSync('language') || 'ch' }, //提前获取 wxCode getWxCode() { wx.login({ success: res => { this.data.wxCode = res.code; } }) }, //获取胶囊按钮位置信息 getMenuButtonInfo() { wx.getSystemInfo({ success: e => { this.data.statusBarCont.StatusBar = e.statusBarHeight; let capsule = wx.getMenuButtonBoundingClientRect(); if (capsule) { this.data.statusBarCont.Custom = capsule; this.data.statusBarCont.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;; } else { this.data.statusBarCont.CustomBar = e.statusBarHeight + 50; } } }); }, //检测缓存中的常客是否有效(存在) checkAdminInfoOfUser() { if (this.data.adminInfo) { checkUserWhiteListId(this.data.adminInfo.userWhitelistId).then(res => { if (!res.data) { wx.removeStorageSync('adminInfo'); this.data.adminInfo = null; } }) } }, globalData: {} })