You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB

//TODO 门卫扫码的页面 没做
//TODO 一堆接口
import constant from './utils/constant';
import {wxLogin} from './utils/util';
// 路由守卫 next() 放行
const routerBeforeEach = (next: Function) => {
const token = wx.getStorageSync('SYS_TOKEN');
// TODO 获取用户信息 存储
if (token) {
// 登录成功
next()
return;
}
// 登录失败 的操作
next()
}
const OldPage = Page;
Page = function (options) {
const oldLoad = options.onLoad
const oldShow = options.onShow
options.onLoad = function () {
routerBeforeEach(() => {
oldLoad?.apply(this, arguments as any)
})
}
options.onShow = function () {
routerBeforeEach(() => {
oldShow?.apply(this, arguments as any)
})
}
OldPage(options)
}
// app.ts
App<IAppOption>({
globalData: {
navBarHeight: 0, // 导航栏高度
menuRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
menuTop: 0, // 胶囊距底部间距(保持底部间距一致)
menuHeight: 0, // 胶囊高度(自定义内容可与胶囊高度保证一致)
},
onLaunch() {
// 展示本地存储能力
const that = this;
// 获取系统信息
const systemInfo = wx.getSystemInfoSync();
// 胶囊按钮位置信息
const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
// 导航栏高度 = 状态栏高度 + 44
that.globalData.navBarHeight = systemInfo.statusBarHeight + 44;
that.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
that.globalData.menuTop = menuButtonInfo.top;
that.globalData.menuHeight = menuButtonInfo.height;
// 登录
console.log("app.ts============")
let userinfo = wx.getStorageSync(constant.USER_INFO);
if(!userinfo){
wxLogin();
}
},
})