70 lines
1.4 KiB
JavaScript
70 lines
1.4 KiB
JavaScript
|
const {
|
||
|
etmsPostTemp
|
||
|
} = require("./com");
|
||
|
|
||
|
App({
|
||
|
onLaunch(opts, data) {
|
||
|
this.etmsLogin("onLaunch");
|
||
|
},
|
||
|
onShow() {
|
||
|
if (!this.globalData.s) {
|
||
|
this.etmsLogin("onShow");
|
||
|
}
|
||
|
},
|
||
|
async etmsLogin(msg) {
|
||
|
if (this.globalData.islogin) {
|
||
|
return
|
||
|
} else {
|
||
|
// 登录
|
||
|
this.globalData.islogin = true
|
||
|
const data = await this.login();
|
||
|
}
|
||
|
|
||
|
|
||
|
},
|
||
|
async login() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
wx.login({
|
||
|
success: (res) => {
|
||
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
||
|
|
||
|
resolve(etmsPostTemp(
|
||
|
"openParent2/WxMiniLogin", {
|
||
|
code: res.code,
|
||
|
},
|
||
|
this.setLoginInfo,
|
||
|
|
||
|
))
|
||
|
},
|
||
|
});
|
||
|
})
|
||
|
},
|
||
|
setLoginInfo(res) {
|
||
|
this.globalData.s = res.s;
|
||
|
this.globalData.u = res.u;
|
||
|
this.globalData.openId = res.openId;
|
||
|
this.globalData.unionid = res.unionid;
|
||
|
this.globalData.nickName = res.nickName;
|
||
|
this.globalData.name = res.name;
|
||
|
this.globalData.avatarUrl = res.avatarUrl;
|
||
|
this.globalData.phone = res.phone;
|
||
|
if (res.avatarUrl) {
|
||
|
this.globalData.isGetUser = true;
|
||
|
}
|
||
|
},
|
||
|
globalData: {
|
||
|
islogin: false,
|
||
|
s: "",
|
||
|
u: "",
|
||
|
openId: "",
|
||
|
unionid: "",
|
||
|
nickName: "",
|
||
|
name: "",
|
||
|
avatarUrl: "",
|
||
|
isGetUser: false,
|
||
|
microWebHomeUrl: "https://baidu.com",
|
||
|
currentActivityBag: {},
|
||
|
currentActivityBag2: {},
|
||
|
|
||
|
},
|
||
|
});
|