Commit 0a8390a5 authored by 石盼盼's avatar 石盼盼

Merge branch 'master' of...

Merge branch 'master' of http://gitlab.xueyoubangedu.com/shipanpan/wandouchengzhang_coach into shipanpan
parents 6d10b542 812ab945
import { Base } from './utils/base.js';
const base = new Base()
App({
onLaunch: function () {
this.isReload() // 小程序是否有新版本
this.getToken() // 获取token
this.getSessionKey() // 获取token
},
// 小程序是否有新版本
isReload: function () {
......@@ -59,62 +61,58 @@ App({
codeChangeToken(code, cb) {
// 发起网络请求
let that = this
wx.request({
url: 'https://openapi.xueyoubangedu.com/request/allrequest',
let params = {
data: {
url: 'https://wandoutiyu.test.xueyoubangedu.com/api/getsessionkey',
code: code
url: 'getsessionkey',
code: code
},
method: 'GET',
success: function (res) {
if (res.data.meta.code === 200) {
try {
wx.setStorageSync('token', res.data.data.token)
} catch (e) {
console.log('token缓存失败')
}
that.globalData.token = res.data.data.token
typeof cb == 'function' && cb()
} else {
console.log(res)
callback: (data) => {
try {
wx.setStorageSync('token', data.token)
} catch (e) {
console.log('token缓存失败')
}
that.globalData.token = data.token
typeof cb == 'function' && cb()
}
})
}
base.newRequest(params)
},
// 保存用户信息
saveUserInfo: function (info, cb) {
let that = this
wx.checkSession({
success() {
wx.request({
url: 'https://wandoutiyu.test.xueyoubangedu.com/api/saveinfo',
let params = {
data: {
url: 'saveinfo',
encryptedData: encodeURIComponent(info.encryptedData),
iv: encodeURIComponent(info.iv),
token: wx.getStorageSync('token'),
token: wx.getStorageSync('token')
},
method: 'POST',
success: function (res) {
if (res.data.meta.code == 200) {
type: 'POST',
callback: data => {
// if (res.data.meta.code == 200) {
wx.showToast({
title: '已授权',
icon: 'none',
duration: 1000
})
that.globalData.userInfo = res.data.data;
wx.setStorageSync('userInfo', res.data.data)
} else {
wx.showToast({
title: res.data.meta.message,
icon: 'none',
duration: 1000
})
}
that.globalData.userInfo = data;
wx.setStorageSync('userInfo', data)
// }
// else {
// wx.showToast({
// title: res.data.meta.message,
// icon: 'none',
// duration: 1000
// })
// }
typeof cb == 'function' && cb()
},
fail: function () { }
})
}
}
base.newRequest(params)
},
fail() {
// session_key 已经失效,需要重新执行登录流程
......
......@@ -11,8 +11,8 @@ Page({
getPhoneNumber: function (e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') {
let params = {
url: 'user/switchPhone',
data: {
url: 'user/switchPhone',
encryptedData: e.detail.encryptedData,
iv: e.detail.iv
},
......
// 公共函数库
const app = getApp()
class Base {
constructor() {
// this.baseUrl = 'https://wandoutiyu.xueyoubangedu.com/api/' //线上接口
this.baseUrl = 'https://wandoutiyu.test.xueyoubangedu.com/api/' //测试接口
}
newRequest(params, flag = false, tips = true) {
newRequest(params, flag = false, tips = true) {
let that = this
if (!params.type) {
params.type = 'GET'
}
var cur_url = that.baseUrl + params.url
var cur_url = that.baseUrl + params.data.url
// if (flag) {
// params.url = params.url;
// } else {
......@@ -21,7 +20,8 @@ class Base {
data: params.data,
method: params.type,
header: {
'token': wx.getStorageSync('token')
'token': wx.getStorageSync('token'),
'app': 'coach'
},
success: function (res) {
console.log(res)
......
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