From 366de5b4636679392a1e3d2984fc23bd5eaa5ac3 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期二, 27 八月 2024 17:48:03 +0800 Subject: [PATCH] wenti --- assets/js/login.js | 147 ++++++++++++++++++++++++++---------------------- 1 files changed, 79 insertions(+), 68 deletions(-) diff --git a/assets/js/login.js b/assets/js/login.js index 1ddfc12..e685eab 100644 --- a/assets/js/login.js +++ b/assets/js/login.js @@ -4,78 +4,86 @@ export const loginInfo = (app, callback) => { - wx.login({ - success: (res) => { - wx.getUserInfo({ - success: (infoRes) => { - app.MG.identity.checkWeChatAppAccount({ - code: res.code, - appCode: app.config.appRefCode, - encryptedData: infoRes.encryptedData, - iv: infoRes.iv - }).then(loginRes => { - if (!loginRes) { - const pages = getCurrentPages(); - const currentPage = pages[pages.length - 1]; - let url = `/${currentPage.route}`; - if (Object.keys(currentPage.options).length) { - let option = ""; - for (const key in currentPage.options) { - if (currentPage.options[key]) { - if (option) { - option += "&" + if (app.config.appId == 27) { + wx.navigateTo({ + url: "/pages/testLogin/index", + }); + } else { + wx.login({ + success: (res) => { + wx.getUserInfo({ + success: (infoRes) => { + // debugger + app.MG.identity.checkWeChatAppAccount({ + code: res.code, + appCode: app.config.appRefCode, + encryptedData: infoRes.encryptedData, + iv: infoRes.iv + }).then(loginRes => { + if (!loginRes) { + const pages = getCurrentPages(); + const currentPage = pages[pages.length - 1]; + let url = `/${currentPage.route}`; + if (Object.keys(currentPage.options).length) { + let option = ""; + for (const key in currentPage.options) { + if (currentPage.options[key]) { + if (option) { + option += "&" + } + option += key + "=" + currentPage.options[key] } - option += key + "=" + currentPage.options[key] } + url += "?" + option } - url += "?" + option + console.log(url); + wx.navigateTo({ + url: "/pages/bindInfo/index?page=" + encodeURIComponent(url), + }); + } else { + wx.login({ + success: (res) => { + app.MG.identity.loginByWeChatAppCode({ + code: res.code, + appRefCode: app.config.appRefCode, + platform: "WeChatAppCustom", + encryptedData: infoRes.encryptedData, + iv: infoRes.iv + }).then(res => { + if (res && res.status == "Ok") { + // 鍌ㄥ瓨token + wx.setStorageSync(app.config.tokenKey, res.token); + // 鑾峰彇鐢ㄦ埛淇℃伅 + getUserInfo(app, callback, res.token) + // 璁板綍鐧诲綍缁熻 + setSessionGuid() + } else { + console.log(res); + callback(false) + } + }) + }, + fail: (err) => { + console.log(err); + callback(false) + } + }) } - console.log(url); - wx.navigateTo({ - url: "/pages/bindInfo/index?page=" + encodeURIComponent(url), - }); - } else { - wx.login({ - success: (res) => { - app.MG.identity.loginByWeChatAppCode({ - code: res.code, - appRefCode: app.config.appRefCode, - platform: "WeChatAppCustom", - encryptedData: infoRes.encryptedData, - iv: infoRes.iv - }).then(res => { - if (res && res.status == "Ok") { - // 鍌ㄥ瓨token - wx.setStorageSync(app.config.tokenKey, res.token); - // 鑾峰彇鐢ㄦ埛淇℃伅 - getUserInfo(app, callback, res.token) - // 璁板綍鐧诲綍缁熻 - setSessionGuid() - } else { - console.log(res); - callback(false) - } - }) - }, - fail: (err) => { - console.log(err); - callback(false) - } - }) - } - }) - }, - fail: (err) => { - console.log(err); - callback(false) - } - }) - }, - fail: (err) => { - console.log(err); - callback(false) - } - }) + }) + + }, + fail: (err) => { + console.log(err); + callback(false) + } + }) + }, + fail: (err) => { + console.log(err); + callback(false) + } + }) + } } // 鑾峰彇鐧诲綍鐢ㄦ埛韬唤 @@ -89,6 +97,7 @@ let teacherRole = res.roleLinks.find((item) => item.role.refCode == 'teacher') let teacherInfos = res.infoList.find((item) => item.type == 'teacherInfo') let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone') + let emailInfo = res.secretList.find((item) => item.type == 'EMail') if (teacherRole && teacherInfos) { defaultUser = { ...teacherInfos, @@ -97,6 +106,7 @@ userId: res.userId, role: 'Teacher', roleId: teacherRole.role.id, + Email: emailInfo ? emailInfo.credential : JSON.parse(teacherInfos.data).email, } } else if (WeChatInfo) { defaultUser = { @@ -109,6 +119,7 @@ if (phoneNumber) { defaultUser.phoneNumber = phoneNumber.credential } + wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); } callback(token); -- Gitblit v1.9.1