| | |
| | | export const requestCtx = "http://182.92.203.7:3001"; // 请求地址 |
| | | export const appId = 27; |
| | | // export const requestCtx = "http://182.92.203.7:3001"; // 请求地址 |
| | | // export const appId = 27; |
| | | // export const requestCtx = "http://jsysf.bnuic.com"; // 请求地址 |
| | | // export const requestCtx = "https://jsek.bnuic.com" // 请求地址 |
| | | // export const appId = 3; |
| | | export const requestCtx = "https://jsek.bnuic.com" // 请求地址 |
| | | export const appId = 3; |
| | | // export const epubUrl = "http://182.92.203.7:3007/epubReadMobile/"; |
| | | export const epubUrl = "http://jsysf.bnuic.com/epubReadMobile/#/"; |
| | | export const requestTimeOut = 300000; // 请求超时时间 |
| | |
| | | import { setSessionGuid } from "./userAction" |
| | | |
| | | |
| | | export const checkLoginInfo = (app, callback) => { |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (!token) { |
| | | export const loginInfo = (app, callback) => { |
| | | wx.login({ |
| | | success: (res) => { |
| | | wx.getUserInfo({ |
| | |
| | | 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] |
| | | } |
| | | } |
| | | url += "?" + option |
| | | } |
| | | debugger |
| | | console.log(url); |
| | | wx.navigateTo({ |
| | | url: "/pages/bindInfo/index?code=" + res.code, |
| | | url: "/pages/bindInfo/index?page=" + encodeURIComponent(url), |
| | | }); |
| | | } else { |
| | | wx.login({ |
| | |
| | | app.MG.identity.loginByWeChatAppCode({ |
| | | code: res.code, |
| | | appRefCode: app.config.appRefCode, |
| | | platform: "weChatAppCustom", |
| | | platform: "WeChatAppCustom", |
| | | encryptedData: infoRes.encryptedData, |
| | | iv: infoRes.iv |
| | | }).then(res => { |
| | | if (res && res.status == "Ok") { |
| | | // 储存token |
| | | wx.setStorageSync(app.config.tokenKey, res.token); |
| | | // 记录登录统计 |
| | | setSessionGuid() |
| | | callback(res.token) |
| | | // 获取用户信息 |
| | | getUserInfo(app, callback, res.token) |
| | | } else { |
| | | console.log(res); |
| | | callback(false) |
| | |
| | | callback(false) |
| | | } |
| | | }) |
| | | } else { |
| | | callback(token) |
| | | } |
| | | |
| | | // 获取登录用户身份 |
| | | const getUserInfo = (app, callback, token) => { |
| | | app.MG.identity.getCurrentAppUser().then(res => { |
| | | // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认) |
| | | if (res) { |
| | | let defaultUser = {}; |
| | | let WeChatInfo = res.infoList.find((item) => item.type === "WeChat"); |
| | | let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone') |
| | | |
| | | if (WeChatInfo) { |
| | | defaultUser = { |
| | | nickName: WeChatInfo.name, |
| | | avatarUrl: WeChatInfo.icon, |
| | | weChatId: WeChatInfo.id |
| | | } |
| | | } |
| | | if (phoneNumber) { |
| | | defaultUser.phoneNumber = phoneNumber.credential |
| | | } |
| | | wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); |
| | | } |
| | | callback(token); |
| | | }); |
| | | } |
| | |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad(options) { |
| | | |
| | | const systInfo = wx.getSystemInfoSync(); |
| | | const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 |
| | | const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 |
| | |
| | | // pages/index/bindInfo/index.js |
| | | import { setSessionGuid } from "../../assets/js/userAction" |
| | | const app = getApp(); |
| | | Page({ |
| | | |
| | |
| | | data: { |
| | | avatarUrl: "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0", |
| | | nickName: "", |
| | | wxCode: null, |
| | | redirectPage: "" |
| | | }, |
| | | |
| | | onChooseAvatar(res) { |
| | |
| | | app.MG.identity.loginByWeChatAppCode({ |
| | | code: res.code, |
| | | appRefCode: app.config.appRefCode, |
| | | platform: "weChatApp", |
| | | platform: "WeChatAppCustom", |
| | | icon: this.data.avatarUrl, |
| | | encryptedData: infoRes.encryptedData, |
| | | iv: infoRes.iv, |
| | | name: this.data.nickName, |
| | | }).then(res => { |
| | | if (res && res.status == "Ok") { |
| | | // 储存token |
| | | wx.setStorageSync(app.config.tokenKey, res.token); |
| | | // 记录登录统计 |
| | | setSessionGuid() |
| | | // 获取用户信息 |
| | | this.getUserInfo() |
| | | } else { |
| | | wx.showToast({ |
| | | icon: "error", |
| | | title: res.message, |
| | | }); |
| | | } |
| | | }) |
| | | }, |
| | |
| | | // 获取登录用户身份 |
| | | getUserInfo() { |
| | | app.MG.identity.getCurrentAppUser().then(res => { |
| | | // console.log(res, "userInfo"); |
| | | // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认) |
| | | if (res) { |
| | | let defaultUser = {}; |
| | | // let secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword') |
| | | let WeChatInfo = res.infoList.find((item) => item.type === "WeChat"); |
| | | let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone') |
| | | |
| | |
| | | weChatId: WeChatInfo.id |
| | | } |
| | | } |
| | | |
| | | if (phoneNumber) { |
| | | defaultUser.phoneNumber = phoneNumber.credential |
| | | } |
| | | this.setData({ |
| | | userInfo: defaultUser, |
| | | loading: false |
| | | }) |
| | | wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo)); |
| | | wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser)); |
| | | } |
| | | wx.switchTab({ |
| | | url: '/pages/index/index' |
| | | url: this.data.redirectPage ? this.data.redirectPage : '/pages/home/home' |
| | | }) |
| | | }); |
| | | }, |
| | |
| | | */ |
| | | onLoad(options) { |
| | | console.log(options, "options"); |
| | | console.log(decodeURIComponent(options.page)); |
| | | this.setData({ |
| | | wxCode: options.code |
| | | redirectPage: decodeURIComponent(options.page) |
| | | }) |
| | | }, |
| | | |
| | |
| | | import { fetchHome } from '../../services/home/home'; |
| | | import moment from 'moment' |
| | | import { checkLoginInfo } from '../../assets/js/login'; |
| | | import { loginInfo } from '../../assets/js/login'; |
| | | const app = getApp() |
| | | Page({ |
| | | data: { |
| | |
| | | navBarHeight: '', |
| | | searchVal: '', |
| | | isWhite: false, |
| | | backUrl: null, |
| | | userInfo: {}, |
| | | tabList: [], //目录 |
| | | current: 1,//轮播图参数 |
| | |
| | | |
| | | }, |
| | | |
| | | onLoad(options) { |
| | | onLoad() { |
| | | const systInfo = wx.getSystemInfoSync(); |
| | | const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 |
| | | const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 |
| | |
| | | barHeight: systInfo.statusBarHeight, |
| | | navBarHeight: navBarHeight, |
| | | }); |
| | | if (options.backUrl) { |
| | | let backUrl = JSON.parse(decodeURIComponent(options.backUrl)); |
| | | if (backUrl.options) { |
| | | for (let key in backUrl.options) { |
| | | const value = backUrl.options[key] |
| | | backUrl.backUrl += `${key}=${value}&` |
| | | } |
| | | } |
| | | this.setData({ |
| | | backUrl: backUrl.backUrl |
| | | }) |
| | | } |
| | | |
| | | // checkLoginInfo(app, (data) => { |
| | | // if (data) { |
| | | // this.getCurrentUserInfo(); |
| | | // } |
| | | // }) |
| | | // 首页测试登录功能,后续注释 |
| | | // 检查登录状态 |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (!token) { |
| | | loginInfo(app, (data) => { |
| | | // 如果不是第一次登录,会执行回调 |
| | | if (data) { |
| | | // 登录成功,自动记录token和用户信息,并返回true |
| | | } else { |
| | | // 出现错误,返回false |
| | | } |
| | | }) |
| | | } else { |
| | | // 如果是第一次登录,会跳转至绑定用户信息页面,填写完用户信息后进行登录并储存token和用户信息,结束后跳转回当前页面(携带页面参数) |
| | | } |
| | | |
| | | this.init(); |
| | | }, |
| | |
| | | }, 500); |
| | | }, |
| | | |
| | | getCurrentUserInfo() { |
| | | app.MG.identity.getCurrentAppUser().then(res => { |
| | | // 用户信息优先级:教师认证 > 微信 > 学生(注册时默认) |
| | | if (res) { |
| | | let defaultUser = {}; |
| | | let WeChatInfo = res.infoList.find((item) => item.type === "WeChat"); |
| | | let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone') |
| | | if (WeChatInfo) { |
| | | defaultUser = { |
| | | nickName: WeChatInfo.name, |
| | | avatarUrl: WeChatInfo.icon, |
| | | weChatId: WeChatInfo.id |
| | | } |
| | | } |
| | | if (phoneNumber) { |
| | | defaultUser.phoneNumber = phoneNumber.credential |
| | | } |
| | | this.setData({ |
| | | userInfo: defaultUser, |
| | | }) |
| | | wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo)); |
| | | } |
| | | if (this.data.backUrl) { |
| | | wx.navigateTo({ |
| | | url: this.data.backUrl, |
| | | }) |
| | | } else { |
| | | wx.switchTab({ |
| | | url: '/pages/home/home' |
| | | }) |
| | | } |
| | | }); |
| | | }, |
| | | getBannerList() { |
| | | const list = [] |
| | | app.MG.resource.getItem({ |