@utogether/udp-core 2.0.0-beta.26 → 2.0.0-beta.27
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/dist/403-gdcH0-Bo.js +65 -0
- package/dist/404-Se2SF97M.js +65 -0
- package/dist/500-B6j9AqLo.js +67 -0
- package/dist/AuthorityInfo-CQ8ydZvr.js +4 -0
- package/dist/AuthorityInfo.vue_vue_type_style_index_0_lang-C4NRvS8p.js +100 -0
- package/dist/AuthorityPanel-lVnZ5bce.js +4 -0
- package/dist/AuthorityPanel.vue_vue_type_style_index_0_lang-nsfhDlvV.js +113 -0
- package/dist/Company-BzSVBSC4.js +25 -0
- package/dist/CompanyPanel-DBjZB4aJ.js +204 -0
- package/dist/DataSet-iBHzs75s.js +147 -0
- package/dist/Department-BkgseHo8.js +25 -0
- package/dist/DepartmentPanel-Sen93_2M.js +249 -0
- package/dist/DesignPanel-pqDcwaFC.js +4 -0
- package/dist/DesignPanel.vue_vue_type_style_index_0_lang-BjtYyEw7.js +1013 -0
- package/dist/DictView-CJLG4LlE.js +110 -0
- package/dist/InvOrganization-D0Jq1IAa.js +74 -0
- package/dist/Org-CO_1WT39.js +39 -0
- package/dist/Preview-DLI4Bwel.js +48 -0
- package/dist/ReportDefine-Cw46OnJ_.js +10 -0
- package/dist/ReportDesign-D4sHTXT7.js +165 -0
- package/dist/ReportQuery-DtOCvQSN.js +74 -0
- package/dist/ReportQueryFrom-QjL-ETPq.js +4 -0
- package/dist/ReportQueryFrom.vue_vue_type_style_index_0_lang-Dj9ne87n.js +177 -0
- package/dist/ReportTemplate-BxAgc_Aj.js +161 -0
- package/dist/Role-Df77BBD-.js +25 -0
- package/dist/RoleAssign-BrunouML.js +26 -0
- package/dist/RolePanel-DSVwqhiD.js +4 -0
- package/dist/RolePanel-HLA7XBlN.js +4 -0
- package/dist/RolePanel.vue_vue_type_script_setup_true_lang-CKlbqRa5.js +132 -0
- package/dist/RolePanel.vue_vue_type_script_setup_true_lang-CN0rUxKz.js +152 -0
- package/dist/ScrollPanel.vue_vue_type_style_index_0_lang-D_FeSXKv.js +99 -0
- package/dist/Staff-BeL1xcRf.js +26 -0
- package/dist/StaffInfo-CIfnltyX.js +4 -0
- package/dist/StaffInfo.vue_vue_type_script_setup_true_lang-DbLFwWfG.js +107 -0
- package/dist/StaffPanel-BV2CHWac.js +4 -0
- package/dist/StaffPanel.vue_vue_type_script_setup_true_lang-CvT-Vp2G.js +153 -0
- package/dist/SysUser-DPfNvthk.js +15 -0
- package/dist/SysUserPanel-CoLKYlQE.js +4 -0
- package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-lcO3Cjbq.js +353 -0
- package/dist/SystemMenu-sdj1dRDA.js +156 -0
- package/dist/UserInfo-CTX4hhFl.js +4 -0
- package/dist/UserInfo.vue_vue_type_style_index_0_lang-ClhCd_8z.js +160 -0
- package/dist/await-to-js.es5-Bv3Eu4mi.js +10 -0
- package/dist/childView-BDmWwJO5.js +4 -0
- package/dist/childView-Dx3ACtHa.js +4 -0
- package/dist/childView.vue_vue_type_style_index_0_lang-CfKq_0FN.js +183 -0
- package/dist/childView.vue_vue_type_style_index_0_lang-DxZNtkhd.js +143 -0
- package/dist/code-rule-cvN4gYC_.js +148 -0
- package/dist/core.es.js +24 -6
- package/dist/cron-task-B0TkxFdp.js +135 -0
- package/dist/flow-task-PoDnE_kE.js +10 -0
- package/dist/frameView-5cy5BSgS.js +43 -0
- package/dist/img/minicolors.png +0 -0
- package/dist/index-C5WRTwvI.js +3006 -0
- package/dist/layout-home-DrARg-3o.js +232 -0
- package/dist/layoutView-25v_ngk5.js +3191 -0
- package/dist/log-in-Bmz5Uhbt.js +116 -0
- package/dist/log-out-B-8m3oNj.js +130 -0
- package/dist/login-Cmp2RvvW.js +217 -0
- package/dist/login-log-CVvRgZSu.js +70 -0
- package/dist/lov-view-BATtzw2X.js +99 -0
- package/dist/menuInfo-BIvrE7nm.js +4 -0
- package/dist/menuInfo.vue_vue_type_style_index_0_lang-B6USomit.js +360 -0
- package/dist/pda-app-CzHVyeEa.js +707 -0
- package/dist/redirect-DTz8GSnv.js +15 -0
- package/dist/resource-Y5lGB38n.js +97 -0
- package/dist/su-welcome-CXA6OzBw.js +878 -0
- package/dist/sys-config-CqO03LeC.js +385 -0
- package/dist/udp-core.css +1 -2
- package/dist/useNav-C-rCgubt.js +84 -0
- package/dist/utogether-MlnyYtNS.js +4 -0
- package/dist/wecom-push-B75FLee5.js +70 -0
- package/index.ts +3 -2
- package/package.json +1 -1
- package/src/App.vue +79 -78
- package/src/api/index.ts +1 -1
- package/src/components/SuQrcode/src/index.tsx +231 -236
- package/src/layout/components/lay-panel/index.vue +2 -6
- package/src/layout/components/lay-search/components/SearchModal.vue +7 -3
- package/src/main.ts +25 -23
- package/src/router/index.ts +156 -187
- package/src/store/modules/system.ts +7 -0
- package/src/style/vxetable.scss +372 -364
- package/src/utils/authority/index.ts +46 -29
- package/src/utils/udp/http/index.ts +115 -64
- package/src/utils/udp/http/types.d.ts +15 -14
- package/src/views/login/login-view.vue +4 -21
- package/src/views/organization/department/DepartmentPanel.vue +3 -4
- package/src/views/system/sys/sys-config.vue +344 -344
- package/src/views/uhome/components/home-todo.vue +179 -178
- package/src/views/ulogin/login.vue +5 -9
- package/tsconfig.json +2 -3
- package/types/global.d.ts +234 -234
- package/vite.config.ts +2 -1
- package/dist/403-D6Wb3JJh.js +0 -72
- package/dist/404-B_HNbPNV.js +0 -72
- package/dist/500-BMemTTy1.js +0 -77
- package/dist/AuthorityInfo-6wHxwiFM.js +0 -91
- package/dist/AuthorityPanel-OqF_DvXA.js +0 -98
- package/dist/Company-BLXSfow0.js +0 -21
- package/dist/CompanyPanel-B4kRZ5Cg.js +0 -199
- package/dist/DataSet-CuGZcKC-.js +0 -141
- package/dist/Department-oFhsa7cd.js +0 -21
- package/dist/DepartmentPanel-B1UGpu-r.js +0 -242
- package/dist/DepartmentPanel-BL58AdoT.js +0 -2
- package/dist/DesignPanel-DmkFVw1N.js +0 -1196
- package/dist/DictView-CC5yMzOq.js +0 -100
- package/dist/File-WJXjGYxr.js +0 -89
- package/dist/InvOrganization-BwMmD8Ua.js +0 -76
- package/dist/Org-HgnOWubi.js +0 -76
- package/dist/Preview-CAzWxLmP.js +0 -45
- package/dist/ReIcon-DecitXmg.js +0 -413
- package/dist/ReportDefine-BgLM-Rjk.js +0 -10
- package/dist/ReportDesign-DwchGG2P.js +0 -158
- package/dist/ReportQuery-D5jaRJEn.js +0 -101
- package/dist/ReportQueryFrom-CNlmtYey.js +0 -198
- package/dist/ReportTemplate-CNcTmccs.js +0 -162
- package/dist/Role-Be8WfdCA.js +0 -21
- package/dist/RoleAssign-CtehGAUf.js +0 -22
- package/dist/RolePanel-CAwITg_q.js +0 -131
- package/dist/RolePanel-SN0FGFZ7.js +0 -176
- package/dist/ScrollPanel-DW30pGz1.js +0 -88
- package/dist/Staff-V2YsNKcj.js +0 -22
- package/dist/StaffInfo-CKRPW0r4.js +0 -149
- package/dist/StaffPanel-BxcgMg7u.js +0 -143
- package/dist/SysUser-Dxyj5w5m.js +0 -12
- package/dist/SysUserPanel-DI6CWcZo.js +0 -365
- package/dist/SystemMenu-BBHREM8T.js +0 -154
- package/dist/UserInfo-BMVQ0xwE.js +0 -194
- package/dist/_plugin-vue_export-helper-C6QCLu9I.js +0 -8
- package/dist/api-BFNxcxSN.js +0 -30
- package/dist/authority-BJFEUdrh.js +0 -20
- package/dist/await-to-js.es5-DkWYmPXW.js +0 -10
- package/dist/childView-BBjPEraB.js +0 -184
- package/dist/childView-DNqG2UVm.js +0 -181
- package/dist/code-rule-QFrhqFrW.js +0 -151
- package/dist/contant-Q77dU_V3.js +0 -4
- package/dist/cron-task-BpUDKEAU.js +0 -131
- package/dist/flow-task-DAc2NrDU.js +0 -11
- package/dist/frameView-Di0zJZUR.js +0 -39
- package/dist/layout-home-BVp7vYLR.js +0 -239
- package/dist/layoutView-B6Mx2ERA.js +0 -2662
- package/dist/log-in-BrNB0mLz.js +0 -117
- package/dist/log-out-dYfqvzy6.js +0 -111
- package/dist/login-D_Hjy3Jd.js +0 -231
- package/dist/login-log-CJak-ANA.js +0 -79
- package/dist/lov-view-DM5Nm5tW.js +0 -95
- package/dist/menuInfo-BlOY1KZW.js +0 -346
- package/dist/mitt-CQgI7DYU.js +0 -27
- package/dist/pda-app-CA7YI37u.js +0 -589
- package/dist/redirect-N0k4tImU.js +0 -16
- package/dist/resource-CfQTHFcs.js +0 -94
- package/dist/su-welcome-DVD3S_du.js +0 -799
- package/dist/sys-config-Ddb3vBpK.js +0 -316
- package/dist/system-Cm3lyBas.js +0 -1528
- package/dist/udp-core-DaQd5CF1.js +0 -2028
- package/dist/useDataThemeChange-DJ4K3VGp.js +0 -226
- package/dist/useNav-BhOJIdrJ.js +0 -106
- package/dist/utogether-l7JXs4Lv.js +0 -4
- package/dist/water-mark-WDQZ9YqB.js +0 -119
- package/dist/wecom-push-kWkAVRCj.js +0 -77
|
@@ -1,29 +1,46 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: wei.li
|
|
3
|
-
* @Date: 2021-11-17 16:26:34
|
|
4
|
-
* @LastEditors: levi7754 levi7754@163.com
|
|
5
|
-
* @LastEditTime:
|
|
6
|
-
* @Description: file content
|
|
7
|
-
*/
|
|
8
|
-
import { usePermissionStoreHook } from '../../store/modules/permission';
|
|
9
|
-
import { isArray } from 'xe-utils';
|
|
10
|
-
import { router } from '../../router';
|
|
11
|
-
const hasAuthority = auth => {
|
|
12
|
-
if (!auth) return true;
|
|
13
|
-
const permissionCode = router.currentRoute.value.meta?.permissionCode;
|
|
14
|
-
if (!permissionCode) return true;
|
|
15
|
-
if (!isArray(auth)) {
|
|
16
|
-
auth = [auth];
|
|
17
|
-
}
|
|
18
|
-
const buttonAuth = usePermissionStoreHook().getButtonAuth;
|
|
19
|
-
if (!buttonAuth) return true;
|
|
20
|
-
let hasAuth = false;
|
|
21
|
-
auth.forEach(item => {
|
|
22
|
-
if (!hasAuth) {
|
|
23
|
-
const authRoles = `${permissionCode}.${item}`;
|
|
24
|
-
hasAuth = buttonAuth.includes(authRoles);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return hasAuth;
|
|
28
|
-
};
|
|
29
|
-
|
|
1
|
+
/*
|
|
2
|
+
* @Author: wei.li
|
|
3
|
+
* @Date: 2021-11-17 16:26:34
|
|
4
|
+
* @LastEditors: levi7754 levi7754@163.com
|
|
5
|
+
* @LastEditTime: 2026-07-01 13:55:44
|
|
6
|
+
* @Description: file content
|
|
7
|
+
*/
|
|
8
|
+
import { usePermissionStoreHook } from '../../store/modules/permission';
|
|
9
|
+
import { isArray } from 'xe-utils';
|
|
10
|
+
import { router } from '../../router';
|
|
11
|
+
export const hasAuthority = auth => {
|
|
12
|
+
if (!auth) return true;
|
|
13
|
+
const permissionCode = router.currentRoute.value.meta?.permissionCode;
|
|
14
|
+
if (!permissionCode) return true;
|
|
15
|
+
if (!isArray(auth)) {
|
|
16
|
+
auth = [auth];
|
|
17
|
+
}
|
|
18
|
+
const buttonAuth = usePermissionStoreHook().getButtonAuth;
|
|
19
|
+
if (!buttonAuth) return true;
|
|
20
|
+
let hasAuth = false;
|
|
21
|
+
auth.forEach(item => {
|
|
22
|
+
if (!hasAuth) {
|
|
23
|
+
const authRoles = `${permissionCode}.${item}`;
|
|
24
|
+
hasAuth = buttonAuth.includes(authRoles);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return hasAuth;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @description: 只能查看权限
|
|
31
|
+
* @param {*} queryAuth 查询权限
|
|
32
|
+
* @param {*} editAuth 编辑权限
|
|
33
|
+
* @return {*} 是否仅有查询权限
|
|
34
|
+
*/
|
|
35
|
+
export const isViewonly = (queryAuth = 'fetch', editAuth = 'edit') => {
|
|
36
|
+
if (!queryAuth) return true;
|
|
37
|
+
const permissionCode = router.currentRoute.value.meta?.permissionCode;
|
|
38
|
+
if (!permissionCode) return true;
|
|
39
|
+
const buttonAuth = usePermissionStoreHook().getButtonAuth;
|
|
40
|
+
if (!buttonAuth) return true;
|
|
41
|
+
|
|
42
|
+
const fetchAuth = `${permissionCode}.${queryAuth}`;
|
|
43
|
+
const hasAuth = buttonAuth.includes(fetchAuth) && !buttonAuth.includes(`${permissionCode}.${editAuth}`);
|
|
44
|
+
return hasAuth;
|
|
45
|
+
};
|
|
46
|
+
export default hasAuthority;
|
|
@@ -1,25 +1,66 @@
|
|
|
1
1
|
import Axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|
2
|
-
import type {
|
|
2
|
+
import type { XHttpError, RequestMethods, XHttpRequestConfig } from './types.d';
|
|
3
3
|
import { NProgress, cookies, errorMessage } from '@utogether/utils';
|
|
4
4
|
import { isRef } from 'vue';
|
|
5
5
|
import { has } from 'xe-utils';
|
|
6
6
|
|
|
7
7
|
const kTOKENKEY = 'authorized-token';
|
|
8
8
|
const defaultConfig: AxiosRequestConfig = {
|
|
9
|
-
timeout:
|
|
9
|
+
timeout: 300000,
|
|
10
10
|
headers: {
|
|
11
11
|
Accept: 'application/json, text/plain, */*',
|
|
12
12
|
'Content-Type': 'application/json',
|
|
13
13
|
'X-Requested-With': 'XMLHttpRequest'
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
// 存储pending中的请求
|
|
18
|
+
const pendingMap = new Map<string, (message?: string) => void>();
|
|
19
|
+
|
|
20
|
+
// 生成请求唯一标识
|
|
21
|
+
const getRequestKey = config => {
|
|
22
|
+
try {
|
|
23
|
+
const { method, url, params, data } = config;
|
|
24
|
+
const paramString = params ? JSON.stringify(params) : '';
|
|
25
|
+
const dataString = data ? JSON.stringify(data) : '';
|
|
26
|
+
return [method?.toUpperCase(), url, paramString, dataString].filter(Boolean).join('&');
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn('Failed to generate request key:', error);
|
|
29
|
+
return `${config.method || 'GET'}_${config.url || ''}_${Date.now()}`;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 添加pending请求
|
|
34
|
+
const addPending = (config: any): void => {
|
|
35
|
+
const key = getRequestKey(config);
|
|
36
|
+
console.log(key, pendingMap.has(key));
|
|
37
|
+
if (pendingMap.has(key)) {
|
|
38
|
+
const cancel = pendingMap.get(key);
|
|
39
|
+
if (cancel) {
|
|
40
|
+
cancel(`Duplicate request canceled: ${key}`);
|
|
41
|
+
}
|
|
42
|
+
pendingMap.delete(key);
|
|
43
|
+
}
|
|
44
|
+
config.cancelToken = new Axios.CancelToken(cancel => {
|
|
45
|
+
pendingMap.set(key, cancel);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 移除pending请求
|
|
50
|
+
const removePending = config => {
|
|
51
|
+
const key = getRequestKey(config);
|
|
52
|
+
if (pendingMap.has(key)) {
|
|
53
|
+
pendingMap.delete(key);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
class XHttp {
|
|
17
58
|
constructor() {
|
|
18
59
|
this.httpInterceptorsRequest();
|
|
19
60
|
this.httpInterceptorsResponse();
|
|
20
61
|
}
|
|
21
62
|
router = undefined;
|
|
22
|
-
baseUrl =
|
|
63
|
+
baseUrl = null;
|
|
23
64
|
/** token过期后,暂存待执行的请求 */
|
|
24
65
|
private static requests = [];
|
|
25
66
|
|
|
@@ -34,17 +75,14 @@ class SuHttp {
|
|
|
34
75
|
setBaseUrl(baseUrl) {
|
|
35
76
|
this.baseUrl = baseUrl;
|
|
36
77
|
}
|
|
37
|
-
// 初始化配置对象
|
|
38
|
-
private static initConfig: SuHttpRequestConfig = {};
|
|
39
78
|
|
|
40
79
|
// 保存当前Axios实例对象
|
|
41
80
|
private static axiosInstance: AxiosInstance = Axios.create(defaultConfig);
|
|
42
81
|
|
|
43
82
|
/** 重连原始请求 */
|
|
44
|
-
private static retryOriginalRequest(config:
|
|
83
|
+
private static retryOriginalRequest(config: XHttpRequestConfig) {
|
|
45
84
|
return new Promise(resolve => {
|
|
46
|
-
|
|
47
|
-
SuHttp.requests.push((token: string) => {
|
|
85
|
+
XHttp.requests.push((token: string) => {
|
|
48
86
|
config.headers!['Authorization'] = 'Bearer ' + token;
|
|
49
87
|
resolve(config);
|
|
50
88
|
});
|
|
@@ -53,34 +91,37 @@ class SuHttp {
|
|
|
53
91
|
|
|
54
92
|
// 请求拦截
|
|
55
93
|
private httpInterceptorsRequest(): void {
|
|
56
|
-
|
|
94
|
+
XHttp.axiosInstance.interceptors.request.use(
|
|
57
95
|
(config: any) => {
|
|
58
96
|
if (has(config, 'loading') && isRef(config.loading)) {
|
|
59
97
|
config.loading.value = true;
|
|
60
98
|
}
|
|
99
|
+
|
|
100
|
+
// 重复请求取消前一个
|
|
101
|
+
addPending(config);
|
|
102
|
+
|
|
61
103
|
// 开启进度条动画
|
|
62
104
|
NProgress.start();
|
|
105
|
+
|
|
63
106
|
// 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
|
|
64
107
|
if (typeof config.beforeRequestCallback === 'function') {
|
|
65
108
|
config.beforeRequestCallback(config);
|
|
66
109
|
return config;
|
|
67
110
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return new Promise(resolve => {
|
|
111
|
+
|
|
112
|
+
// 服务白名单,判断是否需要token
|
|
113
|
+
const whiteList = [/\/refreshToken$/, /\/login$/];
|
|
114
|
+
if (whiteList.some(pattern => pattern.test(config.url))) return config;
|
|
115
|
+
|
|
116
|
+
return new Promise(async resolve => {
|
|
75
117
|
const token = cookies.get(kTOKENKEY);
|
|
76
118
|
if (token) {
|
|
77
119
|
const data = JSON.parse(token);
|
|
78
120
|
const now = new Date().getTime();
|
|
79
121
|
const expired = data.expires - now <= 0;
|
|
80
122
|
if (expired) {
|
|
81
|
-
if (!
|
|
82
|
-
|
|
83
|
-
// requests.push(() => SuHttp.axiosInstance(config));
|
|
123
|
+
if (!XHttp.isRefreshing) {
|
|
124
|
+
XHttp.isRefreshing = true;
|
|
84
125
|
this.get(this.baseUrl + '/uath/refreshToken', {
|
|
85
126
|
refreshToken: data.refreshToken
|
|
86
127
|
})
|
|
@@ -92,19 +133,18 @@ class SuHttp {
|
|
|
92
133
|
this.setToken(res);
|
|
93
134
|
config.headers['Authorization'] = 'Bearer ' + res.access_token;
|
|
94
135
|
// token 刷新后将数组的方法重新执行
|
|
95
|
-
|
|
96
|
-
|
|
136
|
+
XHttp.requests.forEach(cb => cb(res.access_token));
|
|
137
|
+
XHttp.requests = []; // 重新请求完清空
|
|
97
138
|
}
|
|
98
139
|
})
|
|
99
140
|
.catch(() => {
|
|
100
141
|
this.routeToLogin();
|
|
101
142
|
})
|
|
102
143
|
.finally(() => {
|
|
103
|
-
|
|
144
|
+
XHttp.isRefreshing = false;
|
|
104
145
|
});
|
|
105
146
|
}
|
|
106
|
-
|
|
107
|
-
resolve(SuHttp.retryOriginalRequest(config));
|
|
147
|
+
return XHttp.retryOriginalRequest(config);
|
|
108
148
|
} else {
|
|
109
149
|
config.headers['Authorization'] = 'Bearer ' + data.accessToken;
|
|
110
150
|
resolve(config);
|
|
@@ -132,11 +172,10 @@ class SuHttp {
|
|
|
132
172
|
expires: Date.now() + expires_in * 1000
|
|
133
173
|
};
|
|
134
174
|
cookies.set(kTOKENKEY, JSON.stringify(cache));
|
|
135
|
-
// cookies.set(kTOKENKEY, JSON.stringify(cache), { expires: expires_in });
|
|
136
175
|
}
|
|
137
176
|
|
|
138
177
|
private routeToLogin() {
|
|
139
|
-
|
|
178
|
+
XHttp.requests = []; // 重新请求完清空
|
|
140
179
|
cookies.remove('kCookies_token');
|
|
141
180
|
cookies.remove('authorized-token');
|
|
142
181
|
cookies.remove('loginer');
|
|
@@ -145,43 +184,58 @@ class SuHttp {
|
|
|
145
184
|
|
|
146
185
|
// 响应拦截
|
|
147
186
|
private httpInterceptorsResponse(): void {
|
|
148
|
-
const instance =
|
|
187
|
+
const instance = XHttp.axiosInstance;
|
|
149
188
|
instance.interceptors.response.use(
|
|
150
|
-
(response:
|
|
151
|
-
const $config = response.config;
|
|
189
|
+
(response: any) => {
|
|
190
|
+
const $config = response.config as XHttpRequestConfig;
|
|
191
|
+
|
|
152
192
|
if (has($config, 'loading') && isRef($config.loading)) {
|
|
153
193
|
$config.loading.value = false;
|
|
154
194
|
}
|
|
195
|
+
|
|
196
|
+
// 请求完成,移除pending记录
|
|
197
|
+
removePending(response.config);
|
|
198
|
+
|
|
155
199
|
// 关闭进度条动画
|
|
156
200
|
NProgress.done();
|
|
201
|
+
|
|
157
202
|
// 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
|
|
158
203
|
if (typeof $config.beforeResponseCallback === 'function') {
|
|
159
204
|
$config.beforeResponseCallback(response);
|
|
160
205
|
return response.data;
|
|
161
206
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return response.
|
|
207
|
+
|
|
208
|
+
if (!response.data && response?.msg) {
|
|
209
|
+
return Promise.reject(response.msg);
|
|
165
210
|
}
|
|
211
|
+
|
|
166
212
|
return response.data;
|
|
167
213
|
},
|
|
168
|
-
(error:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
error.config.loading.value = false;
|
|
214
|
+
(error: XHttpError) => {
|
|
215
|
+
// 被取消的请求不做错误提示
|
|
216
|
+
if (Axios.isCancel(error)) {
|
|
217
|
+
console.warn('请求已取消:', error.message);
|
|
218
|
+
return Promise.reject(error);
|
|
174
219
|
}
|
|
175
|
-
|
|
220
|
+
|
|
221
|
+
// 移除pending记录
|
|
222
|
+
error.config && removePending(error.config);
|
|
223
|
+
|
|
224
|
+
const config = error.config as XHttpRequestConfig;
|
|
225
|
+
|
|
226
|
+
if (has(config, 'loading') && isRef(config?.loading)) {
|
|
227
|
+
config.loading.value = false;
|
|
228
|
+
}
|
|
229
|
+
|
|
176
230
|
// 关闭进度条动画
|
|
177
231
|
NProgress.done();
|
|
178
232
|
// 所有的响应异常 区分来源为取消请求/非取消请求
|
|
179
|
-
return Promise.reject(
|
|
233
|
+
return Promise.reject(error);
|
|
180
234
|
}
|
|
181
235
|
);
|
|
182
236
|
}
|
|
183
237
|
|
|
184
|
-
private transformConfigByMethod(params: any, config:
|
|
238
|
+
private transformConfigByMethod(params: any, config: XHttpRequestConfig): XHttpRequestConfig {
|
|
185
239
|
const { method } = config;
|
|
186
240
|
const methods = ['get'];
|
|
187
241
|
const m = method!.toLocaleLowerCase();
|
|
@@ -197,27 +251,27 @@ class SuHttp {
|
|
|
197
251
|
method: RequestMethods,
|
|
198
252
|
url: string,
|
|
199
253
|
param?: AxiosRequestConfig,
|
|
200
|
-
axiosConfig?:
|
|
254
|
+
axiosConfig?: XHttpRequestConfig
|
|
201
255
|
): Promise<T> {
|
|
202
256
|
const config = this.transformConfigByMethod(param, {
|
|
203
257
|
method,
|
|
204
258
|
url,
|
|
205
259
|
...axiosConfig
|
|
206
|
-
} as
|
|
260
|
+
} as XHttpRequestConfig);
|
|
207
261
|
// 单独处理自定义请求/响应回掉
|
|
208
262
|
return new Promise((resolve, reject) => {
|
|
209
|
-
|
|
263
|
+
XHttp.axiosInstance
|
|
210
264
|
.request(config)
|
|
211
265
|
.then((res: any) => {
|
|
212
|
-
if (res
|
|
213
|
-
resolve(res.data);
|
|
214
|
-
} else if (res.code === '500') {
|
|
266
|
+
if (res.code === '500') {
|
|
215
267
|
errorMessage(res.msg, { duration: 8000 });
|
|
216
268
|
if (config.method === 'get') {
|
|
217
269
|
resolve(res);
|
|
218
270
|
} else {
|
|
219
271
|
reject(res.msg);
|
|
220
272
|
}
|
|
273
|
+
} else if (res?.code === '0') {
|
|
274
|
+
resolve(res.data);
|
|
221
275
|
} else if (res?.code !== '-1') {
|
|
222
276
|
resolve(res);
|
|
223
277
|
} else {
|
|
@@ -229,12 +283,13 @@ class SuHttp {
|
|
|
229
283
|
.catch(e => {
|
|
230
284
|
if (e?.code) {
|
|
231
285
|
if (e?.response?.status === 401) {
|
|
232
|
-
// @ts-ignore
|
|
233
286
|
return this.router?.push({ path: '/login' });
|
|
234
287
|
}
|
|
235
|
-
|
|
288
|
+
if (e.code !== 'ERR_CANCELED') {
|
|
289
|
+
errorMessage(this.getNetworkError(e?.response?.status) || e?.message, { duration: 8000 });
|
|
290
|
+
}
|
|
236
291
|
}
|
|
237
|
-
if (e.config
|
|
292
|
+
if (e.config?.method === 'get') {
|
|
238
293
|
resolve(e);
|
|
239
294
|
} else {
|
|
240
295
|
reject(e);
|
|
@@ -246,12 +301,12 @@ class SuHttp {
|
|
|
246
301
|
getNetworkError = code => {
|
|
247
302
|
if (!code) return null;
|
|
248
303
|
const msgMap = {
|
|
249
|
-
400: '
|
|
250
|
-
401: '
|
|
251
|
-
403: '
|
|
304
|
+
400: '请求参数错误',
|
|
305
|
+
401: '登录已过期,请重新登录',
|
|
306
|
+
403: '没有权限访问',
|
|
252
307
|
404: '请求错误,未找到该资源',
|
|
253
308
|
408: '请求超时',
|
|
254
|
-
500: '
|
|
309
|
+
500: '服务器内部错误',
|
|
255
310
|
502: '网络超时',
|
|
256
311
|
503: '服务不可用',
|
|
257
312
|
504: '网络超时'
|
|
@@ -260,29 +315,25 @@ class SuHttp {
|
|
|
260
315
|
};
|
|
261
316
|
|
|
262
317
|
// 单独抽离的post工具函数
|
|
263
|
-
public post<T, P>(url: string, params?: T, config?:
|
|
264
|
-
// @ts-ignore
|
|
318
|
+
public post<T, P>(url: string, params?: T, config?: XHttpRequestConfig): Promise<P> {
|
|
265
319
|
return this.request<P>('post', url, params, config);
|
|
266
320
|
}
|
|
267
321
|
|
|
268
322
|
// 单独抽离的delete工具函数
|
|
269
|
-
public delete<T, P>(url: string, params?: T, config?:
|
|
270
|
-
// @ts-ignore
|
|
323
|
+
public delete<T, P>(url: string, params?: T, config?: XHttpRequestConfig): Promise<P> {
|
|
271
324
|
return this.request<P>('delete', url, params, config);
|
|
272
325
|
}
|
|
273
326
|
|
|
274
327
|
// 单独抽离的put工具函数
|
|
275
|
-
public put<T, P>(url: string, params?: T, config?:
|
|
276
|
-
// @ts-ignore
|
|
328
|
+
public put<T, P>(url: string, params?: T, config?: XHttpRequestConfig): Promise<P> {
|
|
277
329
|
return this.request<P>('put', url, params, config);
|
|
278
330
|
}
|
|
279
331
|
|
|
280
332
|
// 单独抽离的get工具函数
|
|
281
|
-
public get<T, P>(url: string, params?: T, config?:
|
|
333
|
+
public get<T, P>(url: string, params?: T, config?: XHttpRequestConfig): Promise<P> {
|
|
282
334
|
for (const key in params) {
|
|
283
335
|
if (!params[key]) delete params[key];
|
|
284
336
|
}
|
|
285
|
-
// @ts-ignore
|
|
286
337
|
return this.request<P>('get', url, params, config);
|
|
287
338
|
}
|
|
288
339
|
|
|
@@ -291,4 +342,4 @@ class SuHttp {
|
|
|
291
342
|
}
|
|
292
343
|
}
|
|
293
344
|
|
|
294
|
-
export const http = new
|
|
345
|
+
export const http = new XHttp();
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @Author: wei.li
|
|
3
3
|
* @Date: 2022-03-08 15:17:39
|
|
4
4
|
* @LastEditors: levi7754 levi7754@163.com
|
|
5
|
-
* @LastEditTime:
|
|
6
|
-
* @Description:
|
|
5
|
+
* @LastEditTime: 2026-05-18 10:46:33
|
|
6
|
+
* @Description: XHttp Axios 类型定义文件
|
|
7
7
|
*/
|
|
8
8
|
import type { Method, AxiosError, AxiosResponse, AxiosRequestConfig } from 'axios';
|
|
9
9
|
|
|
@@ -15,28 +15,29 @@ export type resultType = {
|
|
|
15
15
|
|
|
16
16
|
export type RequestMethods = Extract<Method, 'get' | 'post' | 'put' | 'delete' | 'patch' | 'option' | 'head'>;
|
|
17
17
|
|
|
18
|
-
export interface
|
|
18
|
+
export interface XHttpError extends AxiosError {
|
|
19
19
|
isCancelRequest?: boolean;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export interface
|
|
23
|
-
config:
|
|
22
|
+
export interface XHttpResponse extends AxiosResponse {
|
|
23
|
+
config: XHttpRequestConfig;
|
|
24
|
+
msg: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export interface
|
|
27
|
-
beforeRequestCallback?: (request:
|
|
28
|
-
beforeResponseCallback?: (response:
|
|
29
|
-
loading?:
|
|
27
|
+
export interface XHttpRequestConfig extends AxiosRequestConfig {
|
|
28
|
+
beforeRequestCallback?: (request: XHttpRequestConfig) => void;
|
|
29
|
+
beforeResponseCallback?: (response: XHttpResponse) => void;
|
|
30
|
+
loading?: boolean;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export default class
|
|
33
|
+
export default class XHttp {
|
|
33
34
|
request<T>(
|
|
34
35
|
method: RequestMethods,
|
|
35
36
|
url: string,
|
|
36
37
|
param?: AxiosRequestConfig,
|
|
37
|
-
axiosConfig?:
|
|
38
|
+
axiosConfig?: XHttpRequestConfig
|
|
38
39
|
): Promise<T>;
|
|
39
|
-
post<T, P>(url: string, params?: T, config?:
|
|
40
|
-
postRouter<T, P>(url: string, params?: T, config?:
|
|
41
|
-
get<T, P>(url: string, params?: T, config?:
|
|
40
|
+
post<T, P>(url: string, params?: T, config?: XHttpRequestConfig): Promise<P>;
|
|
41
|
+
postRouter<T, P>(url: string, params?: T, config?: XHttpRequestConfig): Promise<P>;
|
|
42
|
+
get<T, P>(url: string, params?: T, config?: XHttpRequestConfig): Promise<P>;
|
|
42
43
|
}
|
|
@@ -91,7 +91,6 @@ import { ref, reactive, onMounted, onBeforeMount, onBeforeUnmount } from 'vue';
|
|
|
91
91
|
import { useRouter } from 'vue-router';
|
|
92
92
|
import type { FormInstance } from 'element-plus';
|
|
93
93
|
import { storageLocal, cookies, successMessage, delay } from '@utogether/utils';
|
|
94
|
-
import { toDateString } from 'xe-utils';
|
|
95
94
|
import to from 'await-to-js';
|
|
96
95
|
|
|
97
96
|
import Motion from './utils/motion';
|
|
@@ -100,15 +99,12 @@ import TypeIt from '@/components/SuTypeit';
|
|
|
100
99
|
import { useRenderIcon } from '@/components/ReIcon/src/hooks';
|
|
101
100
|
// import { useTranslationLang } from '@/layout/hooks/useTranslationLang';
|
|
102
101
|
import { useLayout } from '@/layout/hooks/useLayout';
|
|
103
|
-
|
|
104
|
-
// import { useDataThemeChange } from '@/layout/hooks/useDataThemeChange';
|
|
102
|
+
|
|
105
103
|
import { useSystemStoreHook } from '@/store/modules/system';
|
|
106
104
|
|
|
107
105
|
import { getServiceApi } from '../../api';
|
|
108
|
-
import {
|
|
109
|
-
|
|
110
|
-
// import darkIcon from '@/assets/svg/dark.svg?component';
|
|
111
|
-
// import globalization from '@/assets/svg/globalization.svg?component';
|
|
106
|
+
import { userMonitor } from '../../api/user';
|
|
107
|
+
|
|
112
108
|
import Lock from '@iconify-icons/ri/lock-fill';
|
|
113
109
|
import User from '@iconify-icons/ri/user-3-fill';
|
|
114
110
|
|
|
@@ -176,7 +172,7 @@ const onLogin = async (formEl: FormInstance | undefined) => {
|
|
|
176
172
|
cookies.set('loginer', username);
|
|
177
173
|
await delay(300);
|
|
178
174
|
router.push('/');
|
|
179
|
-
|
|
175
|
+
userMonitor(username);
|
|
180
176
|
})
|
|
181
177
|
.finally(() => {
|
|
182
178
|
loading.value = false;
|
|
@@ -204,19 +200,6 @@ const cacheToken = token => {
|
|
|
204
200
|
expires_in > 0 ? cookies.set(kTOKENKEY, dataString) : cookies.set(kTOKENKEY, dataString);
|
|
205
201
|
};
|
|
206
202
|
|
|
207
|
-
const insertLoginInfo = username => {
|
|
208
|
-
const userAgent = navigator.userAgent.toLowerCase();
|
|
209
|
-
const { browser, browserVersion } = getBrower(userAgent);
|
|
210
|
-
const obj = {
|
|
211
|
-
userName: username,
|
|
212
|
-
loginTime: toDateString(new Date()),
|
|
213
|
-
browser,
|
|
214
|
-
browserVersion,
|
|
215
|
-
operatingSystem: getPlatform(userAgent)
|
|
216
|
-
};
|
|
217
|
-
serviceApi.post('/upfm/v1/userMonitor', obj);
|
|
218
|
-
};
|
|
219
|
-
|
|
220
203
|
/** 使用公共函数,避免`removeEventListener`失效 */
|
|
221
204
|
function onkeypress({ code }: KeyboardEvent) {
|
|
222
205
|
if (['Enter', 'NumpadEnter'].includes(code)) {
|
|
@@ -113,15 +113,14 @@
|
|
|
113
113
|
|
|
114
114
|
<script setup lang="ts">
|
|
115
115
|
import { useI18n } from 'vue-i18n';
|
|
116
|
-
import { reactive, watch, inject } from 'vue';
|
|
117
|
-
import { templateRef } from '@vueuse/core';
|
|
116
|
+
import { reactive, watch, inject, ref } from 'vue';
|
|
118
117
|
import { clone } from 'xe-utils';
|
|
119
118
|
import to from 'await-to-js';
|
|
120
119
|
import { VxeUI } from 'vxe-table';
|
|
121
120
|
import { successMessage, warnMessage } from '@utogether/utils';
|
|
122
121
|
import { useSystemStoreHook } from '../../../store/modules/system';
|
|
123
122
|
import { getServiceApi } from '../../../api';
|
|
124
|
-
import hasAuthority from '../../../utils/authority';
|
|
123
|
+
import { hasAuthority } from '../../../utils/authority';
|
|
125
124
|
|
|
126
125
|
const data = reactive<IRecord>({
|
|
127
126
|
record: {},
|
|
@@ -186,7 +185,7 @@ const handleEdit = dataStatus => {
|
|
|
186
185
|
data.dialogFormVisible = true;
|
|
187
186
|
};
|
|
188
187
|
|
|
189
|
-
const xForm =
|
|
188
|
+
const xForm = ref<any>('xForm');
|
|
190
189
|
const handleComfirm = () => {
|
|
191
190
|
xForm.value.validate(async valid => {
|
|
192
191
|
if (!valid) {
|