Commit 3fe0e702 by 赵雅纹

登陆

parent 6f56e39b
...@@ -112,9 +112,13 @@ class Http { ...@@ -112,9 +112,13 @@ class Http {
// return resp; // return resp;
return Promise.resolve(resp) return Promise.resolve(resp)
} else { } else {
var error = new Error(`status: ${resp.statusCode}`) // var error = new Error(`status: ${resp.statusCode}`)
error.response = resp // error.response = resp
return Promise.reject(error) // return Promise.reject(resp.statusCode)
return Promise.reject({
state: resp.data.result,
msg: resp.data.desc
})
} }
} }
...@@ -124,7 +128,7 @@ class Http { ...@@ -124,7 +128,7 @@ class Http {
if (!baseUserInfo || baseUserInfo.isMember !== '1') { if (!baseUserInfo || baseUserInfo.isMember !== '1') {
return Promise.reject({ return Promise.reject({
state: 401, state: 401,
msg: '没有领取会员卡' msg: '登录过期'
}) })
} else { } else {
return Promise.reject({ return Promise.reject({
...@@ -144,9 +148,9 @@ class Http { ...@@ -144,9 +148,9 @@ class Http {
content: '请求数据超时' content: '请求数据超时'
}) })
} }
if(error.response.data.desc){ if(error.msg){
wx.showToast({ wx.showToast({
title: `${error.response.data.desc}`, title: `${error.msg}`,
icon: 'none' icon: 'none'
}) })
} }
......
...@@ -12,6 +12,7 @@ import { cEvent } from './event' ...@@ -12,6 +12,7 @@ import { cEvent } from './event'
import Http from './Http' import Http from './Http'
const Promise = require('../lib/bluebird') const Promise = require('../lib/bluebird')
const config = require('../config/index').envInfo const config = require('../config/index').envInfo
import utils from './util'
let openCardLister = null let openCardLister = null
/** /**
* 单例 * 单例
...@@ -29,7 +30,7 @@ class WXService extends Http { ...@@ -29,7 +30,7 @@ class WXService extends Http {
} }
/** /**
* 所有接口中返回401就开卡 * 所有接口中返回401就登录
* 返回402 重试 (getUserInfoLimitCount:重试次数),超过重试次数提示会员系统异常,请联系管理员 * 返回402 重试 (getUserInfoLimitCount:重试次数),超过重试次数提示会员系统异常,请联系管理员
*/ */
request ({ request ({
...@@ -46,8 +47,38 @@ class WXService extends Http { ...@@ -46,8 +47,38 @@ class WXService extends Http {
this.setPageLoadStatus() this.setPageLoadStatus()
wx.hideLoading() wx.hideLoading()
}).catch(res => { }).catch(res => {
console.log('res', res)
if (res.state === 401) { if (res.state === 401) {
this.openCard() // this.openCard()
var _this = this
wx.showModal({
title: '温馨提示',
content: '登录已过期,请重新登录',
success(res) {
if (res.confirm) {
let userInfo = wx.getStorageSync('_baseUserInfo')
_this.login().then(result=>{
if(result.code){
_this.post(`/member/minaLogin`, {
code: result.code,
wechatInfo: userInfo,
brandId: 2005,
}).then(data=>{
const { token } = data
if (token) {
wx.setStorageSync('token', token)
} else {
wx.setStorageSync('token', '')
}
wx.setStorageSync('_baseUserInfo', data)
})
}
})
} else if (res.cancel) {
}
}
})
} else if (res.state === 402) { } else if (res.state === 402) {
return this.getUserInfo().then(() => { return this.getUserInfo().then(() => {
if (!this.getUserInfoLimitCount) { if (!this.getUserInfoLimitCount) {
...@@ -512,6 +543,16 @@ class WXService extends Http { ...@@ -512,6 +543,16 @@ class WXService extends Http {
return Math.floor(random * precision) return Math.floor(random * precision)
} }
//打开登录弹框
openAuthModal(){
return new Promise((resolve,reject)=>{
resolve({
isAuthorization: true
})
})
}
} }
const wxService = new WXService() const wxService = new WXService()
......
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