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.
@@ -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
- const config = res.config
73
- config.params = {
74
- ssoRefreshToken: encodeURIComponent(getLocalStorageItem("ssoRefreshToken") ?? ''),
75
- }
76
- axios.get(`/sso-api/client/auth/getSsoRefreshToken`, config).then(innerRes => {
77
- if (innerRes?.data?.statusCode !== 200) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -12,7 +12,6 @@ let ssoEncrypt = ref('');
12
12
 
13
13
  onMounted(async () => {
14
14
  ssoEncrypt.value = getSsoEncrypt('测试');
15
-
16
15
  })
17
16
 
18
17
  </script>