Commit ab53f413 by 严立

LL - 增加用户登录判断

parent 9d8c5647
Showing with 29 additions and 7 deletions
......@@ -48,25 +48,25 @@ App({
wxRequest: function (obj) {
var token = this.globalData.token
var param = obj.data ? JSON.stringify(obj.data) : ""
var param = obj.data ? JSON.stringify(obj.data) : ''
var header = obj.header ? obj.header : { 'token': token || '', }
wx.request({
url: this.globalData.baseUrl + obj.url,
data: param,
method: obj.method || "POST",
method: obj.method || 'POST',
header: header,
success: (res) => {
// console.log("接口:", this.globalData.baseUrl + obj.url);
// console.log("参数:", JSON.stringify(obj.data));
// console.log("返回:", res);
let code = res.data.code * 1;
let code = res.data.code * 1
if (200 == code && true == res.data.success) {
if (obj.success) {
obj.success(res.data)
}
} else if (402 == code) { // token失效
} else if (402 == code) {
this.refreshToken({
success: () => {
this.wxRequest(obj)
......@@ -87,9 +87,9 @@ App({
}
},
fail: (err) => {
console.log("接口:", this.globalData.baseUrl + obj.url)
console.log("参数:", obj.data)
console.log("返回:", err)
// console.log("接口:", this.globalData.baseUrl + obj.url)
// console.log("参数:", obj.data)
// console.log("返回:", err)
if (obj.fail) {
let err = {
statusCode: 9999,
......@@ -108,6 +108,12 @@ App({
});
},
/**
* 登录
* @function
* @param
* @returns
*/
login: function (obj) {
let token = this.globalData.token
if (token) {
......@@ -139,8 +145,12 @@ App({
'birthday': funcResponse.birthday,
'sex': funcResponse.sex,
'userType': Number(funcResponse.userType),
'isSignIn': false,
}
// 以返回信息中是否包含手机号码判断用户是否注册过
if (funcUserInfo.phone) funcUserInfo.isSignIn = true
wx.setStorageSync('userInfo', funcUserInfo)
if (obj.success) {
......@@ -153,6 +163,12 @@ App({
}
},
/**
* 注册
* @function
* @param {number} - funcAmountValue 金额,单位分
* @returns
*/
registUserInfo: function (obj) {
this.wxRequest({
url: '/api/v1/login/getDecryptData',
......@@ -170,6 +186,12 @@ App({
})
},
/**
* 刷新令牌
* @function
* @param {number} - funcAmountValue 金额,单位分
* @returns
*/
refreshToken: function (obj) {
this.wxRequest({
url: '/api/v1/login/refreshToken',
......
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 sign in to comment