| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //app.js
- const utils = require('/utils/util.js').Utils; //载入模块
- import { Watch } from './utils/watch'
- App({
- /**
- * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
- */
- onLaunch: function () {
- new Watch(wx, this.watchData);
- if (!wx.getStorageSync('hasClear')) {
- wx.clearStorage({
- success: (res) => {
- wx.setStorageSync('hasClear', true)
- },
- })
- }
- },
- /**
- * 当小程序启动,或从后台进入前台显示,会触发 onShow
- */
- onShow: function (options) {
- if (!this.captchaTicketExpire) this.captchaTicketExpire = {};
- if (options.referrerInfo.appId === 'wx5a3a7366fd07e119') {
- const result = options.referrerInfo.extraData;
- if (result.ret === 0) {
- const ticket = result.ticket;
- if (!this.captchaTicketExpire[ticket]) {
- this.captchaResult = result;
- this.captchaTicketExpire[ticket] = true;
- }
- }
- }
- if (wx.getUpdateManager) {
- const updateManager = wx.getUpdateManager();
- updateManager.onCheckForUpdate(res => {
- if (res.hasUpdate) {
- updateManager.onUpdateReady(res => {
- wx.showModal({
- title: '更新提示',
- content: '新版本上线了,请点击确定按钮更新!',
- showCancel: false,
- success: res => {
- if (res.confirm) {
- updateManager.applyUpdate()
- }
- }
- })
- })
- updateManager.onUpdateFailed(res => {
- wx.showModal({
- title: '更新提示',
- content: '新版本已上线,请删除当前小程序,重新搜索进入',
- showCancel: false,
- })
- })
- }
- })
- }
- },
- /**
- * 当小程序从前台进入后台,会触发 onHide
- */
- onHide: function () {
- // if (wx.getStorageSync('userinfo').registerFrom === 2) {
- // } else {
- // wx.clearStorage();
- // }
- },
- /**
- * 当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
- */
- onError: function (msg) {
- },
- /**
- * 工具类
- */
- utils: new utils(wx),
- /**
- * 全局变量集合
- */
- globalData: {
- userInfo: null,
- phone_zz: /1[0-9]{10}/,
- webview: null,
- version: '1.1.6',
- platformId: 1
- },
- /**
- * 需要监测的全局变量
- */
- watchData: {
- offline: false,
- is_login: Boolean(wx.getStorageSync('userid'))
- },
- })
|