miniAPP图片上传等api触发项目onhide等周期函数问题
h5跳转到小程序后:在切入后台,从后台切入前台时需要提示用户从h5跳过来;首次进入不需要提示
App({globalData: {// h5-miniisFromH5: false,isFirstFromH5: true,h5Data: {}},onLaunch(options) {this.checkUpdate()// 展示本地存储能力const logs = wx.getStorageSync('logs') || []logs.unshift(Date.now())var firstvisit = wx.getStorageSync("isfirstvisit");if (firstvisit == 1 || firstvisit == 2) {this.globalData.firstvisit = firstvisit;}/* h5判断 */const query = options.query || {};const {ticket,source,code} = query;// 判断来源是否为 H5console.log(options, 'options', ticket,source,code)this.globalData.h5Data = {ticket,code}this.globalData.isFromH5 = source == 'h5'this.globalData.isFirstFromH5 = source == 'h5'},onShow(options) {// 热启动时检查版本是否变化this.checkVersionChange();// 首次进入时,不执行以下逻辑if (this.globalData.isFirstFromH5) {this.firstShow = falsereturn}// 判断:如果上次是 H5 调过来的 && 后台切回前台if (this.globalData.isFromH5) {wx.showModal({title: '提示',content: '请从商网APP重新跳转进入登录,不可直接使用小程序',showCancel: false,confirmText: '我知道了',success: () => {this.globalData.isFromH5 = falsewx.reLaunch({url: '/pages/index/index',})}})return}},onHide() {this.globalData.isFirstFromH5 = false},// 检查版本是否变化checkVersionChange() {const currentVersion = this.globalData.version_num;const lastVersion = wx.getStorageSync('last_version_num') || '';console.log(currentVersion, lastVersion, currentVersion !== lastVersion)if (currentVersion !== lastVersion) {console.log('检测到版本变化,触发更新检查');wx.setStorageSync('last_version_num', currentVersion); // 存储新版本this.checkUpdate(); // 触发检查更新}},checkUpdate: function () {if (!wx.canIUse('getUpdateManager')) {return}const updateManager = wx.getUpdateManager()updateManager.onCheckForUpdate(function (res) {// 请求完新版本信息的回调if (res.hasUpdate) {console.log('发现新版本')}})updateManager.onUpdateReady(function () {wx.showModal({title: '更新提示',content: '新版本已经准备好,请重启小程序!',showCancel: false,success: function