Commit 28b06958 authored by 吴颖's avatar 吴颖

'修改页面登录'

parent 945588be
import { Base } from './utils/base.js'; import {
Base
} from './utils/base.js';
const base = new Base() const base = new Base()
App({ App({
onLaunch: function () { onLaunch: function () {
...@@ -39,15 +41,6 @@ App({ ...@@ -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 // 获取sessionkey 提交后台换取基本openid unionid
getSessionKey: function (cb) { getSessionKey: function (cb) {
let that = this let that = this
...@@ -59,63 +52,65 @@ App({ ...@@ -59,63 +52,65 @@ App({
}, },
// sessionkey 换取token // sessionkey 换取token
codeChangeToken(code, cb) { codeChangeToken(code, cb) {
// 发起网络请求
let that = this let that = this
let params = { wx.request({
url: 'https://wandoutiyu.test.xueyoubangedu.com/api/getsessionkey',
data: { data: {
url: 'getsessionkey',
code: code code: code
}, },
callback: (data) => { header: {
'app': 'coach'
},
method: 'GET',
success: function (res) {
if (res.data.meta.code === 200) {
try { try {
wx.setStorageSync('token', data.token) wx.setStorageSync('token', res.data.data.token)
} catch (e) { } catch (e) {
console.log('token缓存失败') console.log('token缓存失败')
} }
that.globalData.token = data.token that.globalData.token = res.data.data.token
typeof cb == 'function' && cb() typeof cb == 'function' && cb()
} else {
console.log(res)
} }
} }
base.newRequest(params) })
}, },
// 保存用户信息 // 保存用户信息
saveUserInfo: function (info, cb) { saveUserInfo: function (info, cb) {
let that = this let that = this
wx.checkSession({ wx.checkSession({
success() { success() {
let params = { wx.request({
url: 'https://wandoutiyu.test.xueyoubangedu.com/api/saveinfo',
data: { data: {
url: 'saveinfo',
encryptedData: encodeURIComponent(info.encryptedData), encryptedData: encodeURIComponent(info.encryptedData),
iv: encodeURIComponent(info.iv), iv: encodeURIComponent(info.iv),
token: wx.getStorageSync('token') token: wx.getStorageSync('token')
}, },
type: 'POST', header: {
callback: data => { 'app': 'coach'
// if (res.data.meta.code == 200) { },
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({ wx.showToast({
title: '已授权', title: res.data.meta.message,
icon: 'none', 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()
} }
} typeof cb == 'function' && cb()
base.newRequest(params) },
fail: function () {}
})
}, },
fail() { fail() {// session_key 已经失效,需要重新执行登录流程
// session_key 已经失效,需要重新执行登录流程
that.getSessionKey(() => that.saveUserInfo(info, cb)) that.getSessionKey(() => that.saveUserInfo(info, cb))
} }
}) })
......
...@@ -43,27 +43,21 @@ ...@@ -43,27 +43,21 @@
"simulatorPluginLibVersion": {}, "simulatorPluginLibVersion": {},
"condition": { "condition": {
"search": { "search": {
"current": -1,
"list": [] "list": []
}, },
"conversation": { "conversation": {
"current": -1,
"list": [] "list": []
}, },
"plugin": { "plugin": {
"current": -1,
"list": [] "list": []
}, },
"game": { "game": {
"current": -1,
"list": [] "list": []
}, },
"gamePlugin": { "gamePlugin": {
"current": -1,
"list": [] "list": []
}, },
"miniprogram": { "miniprogram": {
"current": -1,
"list": [ "list": [
{ {
"id": -1, "id": -1,
......
...@@ -9,12 +9,13 @@ class Base { ...@@ -9,12 +9,13 @@ class Base {
if (!params.type) { if (!params.type) {
params.type = 'GET' params.type = 'GET'
} }
var cur_url = that.baseUrl + params.data.url var cur_url = that.baseUrl + params.url
// if (flag) { // if (flag) {
// params.url = params.url; // params.url = params.url;
// } else { // } else {
// params.url = that.baseUrl + params.url; // params.url = that.baseUrl + params.url;
// } // }
console.log(cur_url)
wx.request({ wx.request({
url: cur_url, url: cur_url,
data: params.data, 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