yuang-framework-ui-common 1.0.21 → 1.0.22

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,9 +1,10 @@
1
1
  import { http } from '../config/httpConfig';
2
2
  import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from '../utils/storageUtils';
3
3
 
4
+ const getGatewayConfigUrl = '/server/gateway/getGatewayConfig';
4
5
  const initGatewayConfig = () => {
5
6
  return new Promise<void>(async resolve => {
6
- let res = await http.get('/server/gateway/getGatewayConfig');
7
+ let res = await http.get(getGatewayConfigUrl);
7
8
  setLocalStorageItem("gatewayAccessToken", res.data.data.gatewayAccessToken, res.data.data.gatewayTimeout);
8
9
  setLocalStorageItem("gatewayPublicKey", res.data.data.gatewayPublicKey, res.data.data.gatewayTimeout);
9
10
  resolve();
@@ -15,6 +16,7 @@ const clearGatewayConfig = () => {
15
16
  removeLocalStorageItem("gatewayPublicKey");
16
17
  }
17
18
  export {
19
+ getGatewayConfigUrl,
18
20
  initGatewayConfig,
19
21
  clearGatewayConfig
20
22
  }
@@ -5,7 +5,7 @@ import { alertMessageBox } from '../utils/messageBoxUtils';
5
5
 
6
6
  import { getSsoLoginUrl, clearSsoAccessToken, setSsoAccessToken } from '../utils/ssoUtils';
7
7
 
8
- import { clearGatewayConfig, initGatewayConfig } from '../config/gatewayConfig';
8
+ import { clearGatewayConfig, initGatewayConfig, getGatewayConfigUrl } from '../config/gatewayConfig';
9
9
 
10
10
  import { getLocalStorageItem } from '../utils/storageUtils'
11
11
 
@@ -21,31 +21,14 @@ const http = axios.create({
21
21
  })
22
22
 
23
23
 
24
+
24
25
  /* 请求拦截 */
25
26
  http.interceptors.request.use(async config => {
26
- config.headers["X-Requested-With"] = 'XMLHttpRequest';
27
-
28
27
  let gatewayAccessToken = getLocalStorageItem("gatewayAccessToken") ?? '';
29
- let gatewayPublicKey = getLocalStorageItem("gatewayPublicKey") ?? '';
30
- let ssoAccessToken = getLocalStorageItem("ssoAccessToken") ?? '';
31
-
32
- debugger
33
- if(!gatewayAccessToken && config.url != '/server/gateway/getGatewayConfig') {
28
+ if(!gatewayAccessToken && config.url != getGatewayConfigUrl) {
34
29
  await initGatewayConfig();
35
- return axios.request(config);
36
- }
37
-
38
- if (gatewayAccessToken) {
39
- config.headers["Gateway-Access-Token"] = gatewayAccessToken;
40
30
  }
41
- if (gatewayPublicKey) {
42
- config.headers["Gateway-Public-Key"] = gatewayPublicKey;
43
- }
44
-
45
- if (ssoAccessToken) {
46
- config.headers["Sso-Access-Token"] = ssoAccessToken;
47
- }
48
- config.headers["Request-Id"] = 'test';
31
+ beforeRequestConfig(config);
49
32
  return config;
50
33
  }, error => {
51
34
  showErrorMessage(error?.message || messageMap.requestError);
@@ -103,5 +86,32 @@ http.interceptors.response.use((res) => {
103
86
  return Promise.reject(error);
104
87
  });
105
88
 
89
+ /**
90
+ * 请求之前的配置
91
+ * @param config
92
+ */
93
+ const beforeRequestConfig = (config) => {
94
+ if(!config.url){
95
+ return console.error('参数[url]不存在');
96
+ }
97
+ config.headers["X-Requested-With"] = 'XMLHttpRequest';
98
+
99
+ let gatewayAccessToken = getLocalStorageItem("gatewayAccessToken") ?? '';
100
+ let gatewayPublicKey = getLocalStorageItem("gatewayPublicKey") ?? '';
101
+ let ssoAccessToken = getLocalStorageItem("ssoAccessToken") ?? '';
102
+
103
+ if (gatewayAccessToken) {
104
+ config.headers["Gateway-Access-Token"] = gatewayAccessToken;
105
+ }
106
+ if (gatewayPublicKey) {
107
+ config.headers["Gateway-Public-Key"] = gatewayPublicKey;
108
+ }
109
+
110
+ if (ssoAccessToken) {
111
+ config.headers["Sso-Access-Token"] = ssoAccessToken;
112
+ }
113
+ config.headers["Request-Id"] = 'test';
114
+ }
115
+
106
116
 
107
117
  export { http }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -4,6 +4,11 @@ import {getExceptionRoutes} from '../../lib/utils/vueRouterUtils'
4
4
  const router = createRouter({
5
5
  history: createWebHistory(import.meta.env.BASE_URL),
6
6
  routes: [
7
+ {
8
+ path: '/config/gateway-config',
9
+ component: () => import('@/views/config/gateway-config.vue')
10
+ },
11
+
7
12
  {
8
13
  path: '/utils/aes-utils',
9
14
  component: () => import('@/views/utils/aes-utils.vue')
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <div></div>
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { onMounted, ref, getCurrentInstance } from 'vue';
7
+ const { proxy } = getCurrentInstance() as any;
8
+
9
+
10
+ onMounted(() => {
11
+ proxy.$http.get('/sso-api/standard/captcha/getCaptcha', { params: {} }).then((res: any) => {
12
+
13
+ });
14
+ })
15
+ </script>
16
+
17
+ <style scoped>
18
+
19
+ </style>
package/lib/.DS_Store DELETED
Binary file
package/src/.DS_Store DELETED
Binary file