app.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
assets/js/login.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
assets/request/index.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
pages/home/home.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
app.js
@@ -7,15 +7,5 @@ onLaunch: function () {}, onShow: function () { updateManager(); MG.identity.refreshToken({ appRefCode: config.appRefCode, token: wx.getStorageSync(config.tokenKey) }).then(res => { console.log(res, '已刷新') if (res.token) { wx.setStorageSync(config.tokenKey, res.token); } }) }, }); assets/js/login.js
@@ -2,9 +2,11 @@ setSessionGuid } from "./userAction" const app = getApp(); import MG from './middleGround/WebMiddleGroundApi'; import config from './config'; export const loginInfo = (app, callback) => { if (app.config.appId == 27) { if (config.appId == 27) { wx.navigateTo({ url: "/pages/testLogin/index", }); @@ -13,9 +15,9 @@ success: (res) => { wx.getUserInfo({ success: (infoRes) => { app.MG.identity.checkWeChatAppAccount({ MG.identity.checkWeChatAppAccount({ code: res.code, appCode: app.config.appRefCode, appCode: config.appRefCode, encryptedData: infoRes.encryptedData, iv: infoRes.iv }).then(loginRes => { @@ -42,22 +44,22 @@ } else { wx.login({ success: (res) => { app.MG.identity.loginByWeChatAppCode({ MG.identity.loginByWeChatAppCode({ code: res.code, appRefCode: app.config.appRefCode, appRefCode: 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); wx.setStorageSync(config.tokenKey, res.token); // 获取用户信息 getUserInfo(app, callback, res.token) // 记录登录统计 setSessionGuid() //登录记录积分 app.MG.app.creatUserBehavior({ MG.app.creatUserBehavior({ refCode: "sign" }) } else { @@ -90,7 +92,7 @@ } // 获取登录用户身份 const getUserInfo = (app, callback, token) => { app.MG.identity.getCurrentAppUser().then(res => { MG.identity.getCurrentAppUser().then(res => { // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认) if (res) { let defaultUser = {}; @@ -122,7 +124,7 @@ defaultUser.phoneNumber = phoneNumber.credential } wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); wx.setStorageSync(config.userInfoKey, JSON.stringify(defaultUser)); } callback(token); }); assets/request/index.js
@@ -1,6 +1,11 @@ import config from "../js/config" import { loginInfo } from '../js/login'; const app = getApp() let clearStorage = false; let timer = null; let backUrl = null const request = (params) => { let fullUrl = `${config.requestCtx}${params.url}` let token = wx.getStorageSync(config.tokenKey) ? wx.getStorageSync(config.tokenKey) : '' @@ -22,7 +27,7 @@ const url = currentPage.route let options = currentPage.options let urlargs = `/${url}?` wx.clearStorageSync(); // wx.clearStorageSync(); if (!clearStorage) { clearStorage = true; if (!timer) { @@ -31,16 +36,39 @@ }, 4000); } // urlargs = JSON.stringify(urlargs) console.log() let strOpt = JSON.stringify(options) let currentUrl = { options: options, backUrl: urlargs } currentUrl = JSON.stringify(currentUrl) // currentUrl = JSON.stringify(currentUrl) // 不去首页登录,直接调用公共登录方法 // wx.reLaunch({ // url: urlargs ? '/pages/home/home?backUrl=' + encodeURIComponent(currentUrl) : '/pages/home/home' // }) console.log(currentUrl, 123) loginInfo(app, (data) => { if (data) { if (currentUrl.options) { for (let key in options) { const value = currentUrl.options[key] currentUrl.backUrl += `${key}=${value}&` } backUrl = currentUrl.backUrl console.log(backUrl, "url") if (backUrl) { wx.reLaunch({ url: backUrl }) } else { wx.reLaunch({ url: '/pages/home/home' }) } } } else {} }) } } else { wx.showToast({ pages/home/home.js
@@ -1,7 +1,6 @@ import { fetchHome } from '../../services/home/home'; import moment from 'moment' import { loginInfo } from '../../assets/js/login';