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.

79 lines
2.6 KiB

//TODO 门卫扫码的页面 没做
//TODO 一堆接口
import userApi from './api/userApi/userApi';
import constant from './utils/constant';
import {LOGIN_URL} from './utils/util';
// app.ts
App<IAppOption>({
globalData: {
navBarHeight: 0, // 导航栏高度
menuRight: 0, // 胶囊距右方间距(方保持左、右间距一致)
menuTop: 0, // 胶囊距底部间距(保持底部间距一致)
menuHeight: 0, // 胶囊高度(自定义内容可与胶囊高度保证一致)
wechatID:""
},
onLaunch() {
console.log("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;
// 登录
let userinfo = wx.getStorageSync(constant.WECHATID);
if(!userinfo){
wx.qy.login({
success: (res:any) => {
let code = res.code
// 发起登录请求
wx.request({
method: 'POST',
url: LOGIN_URL + '/api/user/login?weChatCode='+code,
data: {weChatCode:code},
success: (res: any) => {
if(res&&res.data&&res.data.data){
let sessionKey = res.data.data;
if(!sessionKey.weChatId){
wx.showModal({
title:"登录失败",
content:"请联系管理员:"+sessionKey.errmsg,
showCancel:false
})
}else{
wx.showToast({
title: '登录成功',
icon: 'success'
});
wx.setStorageSync(constant.WECHATID, sessionKey.weChatId);
this.globalData.wechatID = sessionKey.weChatId
if (this.userInfoReadyCallback){
this.userInfoReadyCallback(sessionKey.weChatId);
}
}
}else{
wx.showToast({
title: '登录失败: '+res.msg,
icon: 'none'
});
}
}
})
},
fail:(res:any)=>{
wx.showToast({
title: '登录失败: '+res.errMsg,
icon: 'none'
});
}
})
}
},
})