|
@@ -50,7 +50,7 @@ const ToolClass = {
|
50
|
50
|
if (queryData) {
|
51
|
51
|
config.url += '?' + queryData
|
52
|
52
|
}
|
53
|
|
- let Header = {}
|
|
53
|
+ let Header = { 'Access-Control-Expose-Headers': 'X-Authorization-JWT' }
|
54
|
54
|
if (wx.getStorageSync('token') !== '' && wx.getStorageSync('tokentime') !== '' && wx.getStorageSync('tokentime') - 0 + 24 * 60 * 60 * 1000 >= Date.now()) { // 本地获取token
|
55
|
55
|
Header['X-Authorization-JWT'] = wx.getStorageSync('token')
|
56
|
56
|
}
|
|
@@ -60,7 +60,7 @@ const ToolClass = {
|
60
|
60
|
...(config.data || {}),
|
61
|
61
|
header: { ...Header },
|
62
|
62
|
success: (res) => {
|
63
|
|
- const token = res.header['X-Authorization-JWT'] || res.header['X-Authorization-Jwt']
|
|
63
|
+ const token = res.data?.token
|
64
|
64
|
if (token) { // 更新本地存储token
|
65
|
65
|
wx.setStorageSync('token', token)
|
66
|
66
|
wx.setStorageSync('tokentime', Date.now())
|
|
@@ -95,9 +95,12 @@ const ToolClass = {
|
95
|
95
|
}
|
96
|
96
|
},
|
97
|
97
|
fail: (res) => {
|
98
|
|
- if (res.header['X-Authorization-JWT'] !== undefined) { // 更新本地存储token
|
99
|
|
- wx.setStorageSync('token', res.header['X-Authorization-JWT'])
|
|
98
|
+ const token = res.data?.token
|
|
99
|
+ if (token) { // 更新本地存储token
|
|
100
|
+ wx.setStorageSync('token', token)
|
|
101
|
+ wx.setStorageSync('tokentime', Date.now())
|
100
|
102
|
}
|
|
103
|
+
|
101
|
104
|
if (res.data.code - 0 === 1001) { // token失效
|
102
|
105
|
// wx.navigateTo({ url: '../../pages/SignIn/index' })
|
103
|
106
|
config.error('登录失效')
|