yuang-framework-ui-common 1.0.20 → 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 }
@@ -12,7 +12,7 @@ import 'vant/lib/index.css';
12
12
  import {http} from './httpConfig';
13
13
  import moment from 'moment';
14
14
 
15
- const initConfig = (app) => {
15
+ const initConfig = (app: any) => {
16
16
  app.config.globalProperties.$http = http;
17
17
  app.config.globalProperties.$moment = moment;
18
18
 
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 某个时间在当前时间的多久前
3
+ * @param time 需要语义化的时间
4
+ * @param onlyDate 超过30天是否仅返回日期
5
+ * @returns {string} 语义化后的时间
6
+ */
7
+ const getTimeAgoString = (time, onlyDate) => {
8
+ if (!time) return '';
9
+ if (typeof time === 'string') time = time.replace(/-/g, '/');
10
+ let arr = [[], []], stamp = new Date().getTime() - new Date(time).getTime();
11
+ // 30天以上返回具体日期
12
+ if (stamp > 1000 * 60 * 60 * 24 * 31) {
13
+ stamp = new Date(time);
14
+ arr[0][0] = this.digit(stamp.getFullYear(), 4);
15
+ arr[0][1] = this.digit(stamp.getMonth() + 1);
16
+ arr[0][2] = this.digit(stamp.getDate());
17
+ if (!onlyDate) { // 是否输出时间
18
+ arr[1][0] = this.digit(stamp.getHours());
19
+ arr[1][1] = this.digit(stamp.getMinutes());
20
+ arr[1][2] = this.digit(stamp.getSeconds());
21
+ }
22
+ return arr[0].join('-') + ' ' + arr[1].join(':');
23
+ }
24
+ // 30天以内,返回“多久前”
25
+ if (stamp >= 1000 * 60 * 60 * 24) {
26
+ return ((stamp / 1000 / 60 / 60 / 24) | 0) + '天前';
27
+ } else if (stamp >= 1000 * 60 * 60) {
28
+ return ((stamp / 1000 / 60 / 60) | 0) + '小时前';
29
+ } else if (stamp >= 1000 * 60 * 3) { // 3分钟以内为:刚刚
30
+ return ((stamp / 1000 / 60) | 0) + '分钟前';
31
+ } else if (stamp < 0) {
32
+ return '未来';
33
+ } else {
34
+ return '刚刚';
35
+ }
36
+ }
37
+
38
+ export {
39
+ getTimeAgoString,
40
+
41
+ }
@@ -1,6 +1,5 @@
1
1
  import { cloneDeep } from 'lodash';
2
2
 
3
3
  export {
4
-
5
4
  cloneDeep
6
5
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 生成UUID
3
+ * @returns {string}
4
+ */
5
+ const getUuid = () => {
6
+ let d = new Date().getTime();
7
+ if (window.performance && typeof window.performance.now === "function") {
8
+ d += performance.now(); //use high-precision timer if available
9
+ }
10
+ let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
11
+ var r = (d + Math.random() * 16) % 16 | 0;
12
+ d = Math.floor(d / 16);
13
+ return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
14
+ });
15
+ return uuid;
16
+ }
17
+ const getShortUuid = () => {
18
+ let uuid = this.getUuid();
19
+ uuid = uuid.replace(/-/g, '');
20
+ return uuid;
21
+ }
22
+
23
+ export {
24
+ getUuid,
25
+ getShortUuid
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.20",
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>