import updateManager from './common/updateManager'; var util = require('utils/util.js'); var api = require('config/api.js'); App({ onLaunch: function () { wx.$api = api wx.$util = util // 展示本地存储能力 var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) // 登录 wx.login({ success: (res) => { util.request(api.AuthLoginByWeixin, { code: res.code }, 'POST').then(function (res) { console.log('App Launch') if (res.code === 1) { let userInfo = res.data.userinfo; wx.setStorageSync('token', res.data.token); wx.setStorageSync('userInfo', userInfo); } }); }, }); }, onShow: function () { updateManager(); //从后台切回前台时刷新一次未读红点(不使用定时轮询,避免请求堆积导致页面卡死) this.refreshUnread(); }, onHide: function () {}, globalData: { unread: 0, //未读消息数(tabbar红点共享缓存) refreshDemandId: 0, //操作后需要刷新状态的需求ID(跨页面通知列表页) }, /** * 刷新当前 tab 页 tabbar 实例的红点(非tab页无tabbar实例,自动跳过) */ refreshUnread: function () { if (!wx.getStorageSync('token')) { return; } const page = getCurrentPages().pop(); const tabBar = page && typeof page.getTabBar === 'function' ? page.getTabBar() : null; if (tabBar && typeof tabBar.refreshUnread === 'function') { tabBar.refreshUnread(); } }, });