1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| App({ onLaunch: function () { this.globalData = { openId: wx.getStorageSync('openId'), userInfo: wx.getStorageSync('userInfo') }; if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { wx.cloud.init({ traceUser: true, }); } const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { }) updateManager.onUpdateReady(function () { wx.showModal({ title: '小韩提示', content: '新版来袭,速来体验!', success: function (res) { if (res.confirm) { updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { });
this._getOpenId() }, _getOpenId() { ((this.globalData.openId || '') == '') && wx.cloud.callFunction({ name: 'login' }).then(res => { this.globalData.openId = res.result.openid; wx.setStorageSync('openId', res.result.openid) }).catch(res => { console.error(res) }); }, async _checkLogin() { const _this = this return new Promise((resolve) => { wx.checkSession({ success: function (_res) { const _userInfo = wx.getStorageSync('userInfo'); resolve((_userInfo || '') === '') }, fail: async function (_res) { await wx.login({}) resolve(true) } }) }) }, async _getUserInfo() { return new Promise((resolve) => { wx.getUserProfile({ desc: 'get用户信息', success: async res => { res.userInfo.openid = this.globalData.openId this.globalData.userInfo = res.userInfo wx.setStorageSync('userInfo', res.userInfo) resolve(true) }, fail: () => { resolve(false) } }); }) }, }); });
|