Commit 39dab9f5 authored by 吴颖's avatar 吴颖

Merge branch 'wuying' into 'master'

'修改页面登录'

See merge request !3
parents 945588be 28b06958
import { Base } from './utils/base.js';
import {
Base
} from './utils/base.js';
const base = new Base()
App({
onLaunch: function () {
......@@ -39,15 +41,6 @@ App({
}
},
// 将token从缓存中 赋值到全局变量
getToken: function () {
try {
var token = wx.getStorageSync('token')
if (token) {
this.globalData.token = token
}
} catch (e) { }
},
// 获取sessionkey 提交后台换取基本openid unionid
getSessionKey: function (cb) {
let that = this
......@@ -59,63 +52,65 @@ App({
},
// sessionkey 换取token
codeChangeToken(code, cb) {
// 发起网络请求
let that = this
let params = {
wx.request({
url: 'https://wandoutiyu.test.xueyoubangedu.com/api/getsessionkey',
data: {
url: 'getsessionkey',
code: code
},
callback: (data) => {
header: {
'app': 'coach'
},
method: 'GET',
success: function (res) {
if (res.data.meta.code === 200) {
try {
wx.setStorageSync('token', data.token)
wx.setStorageSync('token', res.data.data.token)
} catch (e) {
console.log('token缓存失败')
}
that.globalData.token = data.token
that.globalData.token = res.data.data.token
typeof cb == 'function' && cb()
} else {
console.log(res)
}
}
base.newRequest(params)
})
},
// 保存用户信息
saveUserInfo: function (info, cb) {
let that = this
wx.checkSession({
success() {
let params = {
wx.request({
url: 'https://wandoutiyu.test.xueyoubangedu.com/api/saveinfo',
data: {
url: 'saveinfo',
encryptedData: encodeURIComponent(info.encryptedData),
iv: encodeURIComponent(info.iv),
token: wx.getStorageSync('token')
},
type: 'POST',
callback: data => {
// if (res.data.meta.code == 200) {
header: {
'app': 'coach'
},
method: 'POST',
success: function (res) {
if (res.data.meta.code == 200) {
that.globalData.userInfo = res.data.data;
wx.setStorageSync('userInfo', res.data.data)
} else {
console.log(res.data.meta.message)
wx.showToast({
title: '已授权',
title: res.data.meta.message,
icon: 'none',
duration: 1000
duration: 2000
})
that.globalData.userInfo = data;
wx.setStorageSync('userInfo', data)
// }
// else {
// wx.showToast({
// title: res.data.meta.message,
// icon: 'none',
// duration: 1000
// })
// }
typeof cb == 'function' && cb()
}
}
base.newRequest(params)
typeof cb == 'function' && cb()
},
fail: function () {}
})
},
fail() {
// session_key 已经失效,需要重新执行登录流程
fail() {// session_key 已经失效,需要重新执行登录流程
that.getSessionKey(() => that.saveUserInfo(info, cb))
}
})
......
......@@ -43,27 +43,21 @@
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"game": {
"current": -1,
"list": []
},
"gamePlugin": {
"current": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": [
{
"id": -1,
......
......@@ -9,12 +9,13 @@ class Base {
if (!params.type) {
params.type = 'GET'
}
var cur_url = that.baseUrl + params.data.url
var cur_url = that.baseUrl + params.url
// if (flag) {
// params.url = params.url;
// } else {
// params.url = that.baseUrl + params.url;
// }
console.log(cur_url)
wx.request({
url: cur_url,
data: params.data,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment