yuang-framework-ui-common 1.0.30 → 1.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/config/httpConfig.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import axios from "axios"
|
2
|
+
import { useRouter } from 'vue-router';
|
3
|
+
|
2
4
|
import type { AxiosResponse } from 'axios';
|
3
5
|
|
4
6
|
import { showErrorMessage } from '../utils/messageUtils';
|
@@ -10,6 +12,8 @@ import { clearGatewayConfig, initGatewayConfig, getGatewayConfigUrl } from '../c
|
|
10
12
|
|
11
13
|
import { getLocalStorageItem } from '../utils/storageUtils'
|
12
14
|
|
15
|
+
const router = useRouter();
|
16
|
+
|
13
17
|
const messageMap = {
|
14
18
|
requestError: '请求异常',
|
15
19
|
responseSturctError: '响应结构错误',
|
@@ -39,7 +43,7 @@ http.interceptors.request.use(async config => {
|
|
39
43
|
|
40
44
|
|
41
45
|
/* 响应拦截器 */
|
42
|
-
http.interceptors.response.use((res: any) => {
|
46
|
+
http.interceptors.response.use(async (res: any) => {
|
43
47
|
if (!res?.data?.statusCode) {
|
44
48
|
showErrorMessage(messageMap.responseSturctError);
|
45
49
|
return Promise.reject(new Error(messageMap.responseSturctError));
|
@@ -69,24 +73,17 @@ http.interceptors.response.use((res: any) => {
|
|
69
73
|
window.location.href = getSsoLoginUrl() || '';
|
70
74
|
return Promise.reject(new Error(res?.data?.message));
|
71
75
|
} else if (res?.data?.statusCode === 815002) {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
return;
|
79
|
-
}
|
80
|
-
setSsoAccessToken(innerRes.data.data);
|
81
|
-
// 重发请求
|
82
|
-
return axios.request(res.config);
|
83
|
-
});
|
76
|
+
await refreshSsoAccessToken(res);
|
77
|
+
// 重发请求
|
78
|
+
return axios.request(res.config);
|
79
|
+
} else if (res?.data?.statusCode === 815004) {
|
80
|
+
const fullPath = router.currentRoute.value.fullPath;
|
81
|
+
router.push(`/sso/login/index?redirectRoutePath=${fullPath}`);
|
84
82
|
return;
|
85
83
|
} else if (res?.data?.statusCode === 815003) {
|
86
84
|
showErrorMessage(res?.data?.message || messageMap.requestError);
|
87
85
|
return Promise.reject(new Error(res?.data?.message));
|
88
86
|
}
|
89
|
-
|
90
87
|
showErrorMessage(res?.data?.message || messageMap.requestError);
|
91
88
|
return Promise.reject(new Error(res?.data?.message));
|
92
89
|
}
|
@@ -134,4 +131,24 @@ const beforeRequestConfig = (config: any) => {
|
|
134
131
|
}
|
135
132
|
|
136
133
|
|
134
|
+
/**
|
135
|
+
* 刷新ssoAccessToken
|
136
|
+
* @param res
|
137
|
+
*/
|
138
|
+
const refreshSsoAccessToken = (res: any) => {
|
139
|
+
return new Promise((resolve, reject) => {
|
140
|
+
const config = res.config
|
141
|
+
config.params = {
|
142
|
+
ssoRefreshToken: encodeURIComponent(getLocalStorageItem("ssoRefreshToken") ?? ''),
|
143
|
+
}
|
144
|
+
axios.get(`/sso-api/client/auth/getSsoRefreshToken`, config).then(res => {
|
145
|
+
if (res?.data?.statusCode !== 200) {
|
146
|
+
return reject();
|
147
|
+
}
|
148
|
+
setSsoAccessToken(res.data.data);
|
149
|
+
return resolve(void 0);
|
150
|
+
});
|
151
|
+
});
|
152
|
+
}
|
153
|
+
|
137
154
|
export { http }
|
package/package.json
CHANGED