yuang-framework-ui-common 1.0.19 → 1.0.21

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/.DS_Store ADDED
Binary file
@@ -1,23 +1,20 @@
1
1
  import { http } from '../config/httpConfig';
2
2
  import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from '../utils/storageUtils';
3
3
 
4
- const initGateway = () => {
4
+ const initGatewayConfig = () => {
5
5
  return new Promise<void>(async resolve => {
6
- let gatewayAccessToken = getLocalStorageItem("gatewayAccessToken");
7
- if (!gatewayAccessToken) {
8
- let res = await http.get('/server/gateway/getGatewayConfig');
9
- setLocalStorageItem("gatewayAccessToken", res.data.data.gatewayAccessToken, res.data.data.gatewayTimeout);
10
- setLocalStorageItem("gatewayPublicKey", res.data.data.gatewayPublicKey, res.data.data.gatewayTimeout);
11
- }
6
+ let res = await http.get('/server/gateway/getGatewayConfig');
7
+ setLocalStorageItem("gatewayAccessToken", res.data.data.gatewayAccessToken, res.data.data.gatewayTimeout);
8
+ setLocalStorageItem("gatewayPublicKey", res.data.data.gatewayPublicKey, res.data.data.gatewayTimeout);
12
9
  resolve();
13
10
  })
14
11
  }
15
12
 
16
- const clearGateway = () => {
13
+ const clearGatewayConfig = () => {
17
14
  removeLocalStorageItem("gatewayAccessToken");
18
15
  removeLocalStorageItem("gatewayPublicKey");
19
16
  }
20
17
  export {
21
- initGateway,
22
- clearGateway
18
+ initGatewayConfig,
19
+ clearGatewayConfig
23
20
  }
@@ -3,11 +3,11 @@ import axios from "axios"
3
3
  import { showErrorMessage } from '../utils/messageUtils';
4
4
  import { alertMessageBox } from '../utils/messageBoxUtils';
5
5
 
6
- import { getSsoLoginUrl, clearSsoAccessToken } from '../utils/ssoUtils';
6
+ import { getSsoLoginUrl, clearSsoAccessToken, setSsoAccessToken } from '../utils/ssoUtils';
7
7
 
8
- import { clearGateway } from '../config/gatewayConfig';
8
+ import { clearGatewayConfig, initGatewayConfig } from '../config/gatewayConfig';
9
9
 
10
- import {getLocalStorageItem} from '../utils/storageUtils'
10
+ import { getLocalStorageItem } from '../utils/storageUtils'
11
11
 
12
12
  const messageMap = {
13
13
  requestError: '请求异常',
@@ -22,12 +22,19 @@ const http = axios.create({
22
22
 
23
23
 
24
24
  /* 请求拦截 */
25
- http.interceptors.request.use(config => {
25
+ http.interceptors.request.use(async config => {
26
26
  config.headers["X-Requested-With"] = 'XMLHttpRequest';
27
27
 
28
28
  let gatewayAccessToken = getLocalStorageItem("gatewayAccessToken") ?? '';
29
29
  let gatewayPublicKey = getLocalStorageItem("gatewayPublicKey") ?? '';
30
30
  let ssoAccessToken = getLocalStorageItem("ssoAccessToken") ?? '';
31
+
32
+ debugger
33
+ if(!gatewayAccessToken && config.url != '/server/gateway/getGatewayConfig') {
34
+ await initGatewayConfig();
35
+ return axios.request(config);
36
+ }
37
+
31
38
  if (gatewayAccessToken) {
32
39
  config.headers["Gateway-Access-Token"] = gatewayAccessToken;
33
40
  }
@@ -68,10 +75,25 @@ http.interceptors.response.use((res) => {
68
75
  });
69
76
  return Promise.reject(new Error(res?.data?.message));
70
77
  } else if (res?.data?.statusCode === 822001) {
71
- clearGateway();
78
+ clearGatewayConfig();
72
79
  showErrorMessage(messageMap.requestError);
73
80
  return Promise.reject(new Error(res?.data?.message));
81
+ } else if (res?.data?.statusCode === 815001) {
82
+ showErrorMessage(res?.data?.message);
83
+ clearSsoAccessToken();
84
+ location.href = getSsoLoginUrl();
85
+ return Promise.reject(new Error(res?.data?.message));
86
+ } else if (res?.data?.statusCode === 815002) {
87
+ axios.get('/sso-api/client/auth/getSsoRefreshToken').then(res => {
88
+ setSsoAccessToken(res.data.data);
89
+ // 重发请求
90
+ return axios.request(res.config);
91
+ })
92
+ } else if (res?.data?.statusCode === 815003) {
93
+ showErrorMessage(res?.data?.message);
94
+ return Promise.reject(new Error(res?.data?.message));
74
95
  }
96
+
75
97
  showErrorMessage(res?.data?.message || messageMap.requestError);
76
98
  return Promise.reject(new Error(res?.data?.message));
77
99
  }
@@ -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.19",
3
+ "version": "1.0.21",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
package/src/.DS_Store ADDED
Binary file
package/src/App.vue CHANGED
@@ -1,19 +1,8 @@
1
1
  <template>
2
- <RouterView v-if="isShowRouterView"/>
2
+ <RouterView />
3
3
  </template>
4
4
  <script setup lang="ts">
5
5
  import { RouterView } from 'vue-router'
6
- import { onBeforeMount, ref, getCurrentInstance } from 'vue';
7
- import { initGateway } from '../lib/config/gatewayConfig'
8
-
9
- let isShowRouterView = ref(false);
10
-
11
- const { proxy } = getCurrentInstance() as any;
12
-
13
- onBeforeMount(async () => {
14
- await initGateway();
15
- isShowRouterView.value = true;
16
- })
17
6
  </script>
18
7
 
19
8
  <style scoped>