|
|
@@ -1,6 +1,7 @@
|
|
|
import Request from 'luch-request'
|
|
|
import setting from './setting.js'
|
|
|
import crypto from '@/utils/crypto.js'
|
|
|
+import queryParams from '@/utils/queryParams.js'
|
|
|
|
|
|
let baseURL = setting.baseURL
|
|
|
let refreshTokenUrl = baseURL + "blade-auth/oauth/token"
|
|
|
@@ -45,11 +46,9 @@ http.interceptors.request.use((config) => {
|
|
|
"Authorization": "Basic c2FiZXI6c2FiZXJfc2VjcmV0",
|
|
|
"Blade-Auth": getTokenStorage()
|
|
|
}
|
|
|
- console.log(config,"122222222222");
|
|
|
if (setting.enabledCrypto && config.method == 'POST' && config.data) {
|
|
|
- let encrypt= crypto.encrypt(JSON.stringify(config.data))
|
|
|
- console.log(crypto.decrypt(encrypt),"/******************");
|
|
|
- config.data=encrypt
|
|
|
+ let encrypt = crypto.encrypt(JSON.stringify(config.data))
|
|
|
+ config.data = encrypt
|
|
|
}
|
|
|
return config
|
|
|
}, (config) => {
|
|
|
@@ -81,45 +80,45 @@ http.interceptors.response.use(async (response) => {
|
|
|
|
|
|
let tokenInfo = uni.getStorageSync('tokenInfo')
|
|
|
if (!tokenInfo.tenantId) {
|
|
|
+ let phone = uni.getStorageSync("phone")
|
|
|
uni.showModal({
|
|
|
title: "提示",
|
|
|
content: "会话已过期,请重新登录",
|
|
|
- showCancel:false,
|
|
|
- confirmColor:'#EF9944',
|
|
|
- success: (res)=>{
|
|
|
+ showCancel: false,
|
|
|
+ confirmColor: '#EF9944',
|
|
|
+ success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
uni.clearStorageSync()
|
|
|
+ uni.set
|
|
|
uni.reLaunch({
|
|
|
- url:"/pages/login/account-login"
|
|
|
+ url: "/pages/login/account-login?phone=" + phone
|
|
|
})
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
return
|
|
|
}
|
|
|
+ let tokenParams={
|
|
|
+ 'tenantId': tokenInfo.tenantId,
|
|
|
+ 'refresh_token': tokenInfo.refreshToken,
|
|
|
+ 'grant_type': "refresh_token",
|
|
|
+ 'scope': "all",
|
|
|
+ }
|
|
|
let [, res] = await uni.request({
|
|
|
- url: refreshTokenUrl,
|
|
|
+ url: refreshTokenUrl + queryParams(tokenParams),
|
|
|
method: 'POST',
|
|
|
header: {
|
|
|
'Authorization': "Basic c2FiZXI6c2FiZXJfc2VjcmV0",
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
'Tenant-Id': tokenInfo.tenantId
|
|
|
- },
|
|
|
- data: {
|
|
|
- 'tenantId': tokenInfo.tenantId,
|
|
|
- 'refresh_token': tokenInfo.refreshToken,
|
|
|
- 'grant_type': "refresh_token",
|
|
|
- 'scope': "all",
|
|
|
}
|
|
|
})
|
|
|
- if (res.data && res.data.error_description=="用户名或密码不正确") {
|
|
|
+ if (res.data && res.data.error_description == "用户名或密码不正确") {
|
|
|
uni.clearStorage()
|
|
|
uni.reLaunch({
|
|
|
- url:"/pages/login/account-login"
|
|
|
+ url: "/pages/login/account-login"
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
//否则保存新的token
|
|
|
cacheToken(res.data)
|
|
|
|