@utogether/udp-core 1.0.1-beta.2 → 1.0.1-beta.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.
Files changed (159) hide show
  1. package/build/plugins.ts +8 -1
  2. package/dist/{403-BBQoJwTM.js → 403-B_l9Q9w_.js} +1 -1
  3. package/dist/{404-BbJPSIWM.js → 404-33KZO3Vz.js} +1 -1
  4. package/dist/{500-BtFL9R4M.js → 500-oI74ZkQH.js} +1 -1
  5. package/dist/{AuthorityInfo-DhiwCeLN.js → AuthorityInfo-CNoxrmPS.js} +1 -1
  6. package/dist/AuthorityInfo.vue_vue_type_style_index_0_lang-CO01EWKQ.js +100 -0
  7. package/dist/{Company-CGqmslx-.js → Company-DOCRUvUs.js} +3 -3
  8. package/dist/{CompanyPanel-hlDsxD-6.js → CompanyPanel-Do2JlJ3U.js} +26 -26
  9. package/dist/{Department-BZyJtacc.js → Department-BAlx8Am2.js} +3 -3
  10. package/dist/{DepartmentPanel-D-a_EBFt.js → DepartmentPanel-BvQUkRaM.js} +25 -25
  11. package/dist/{DesignPanel-Bl4luWDV.js → DesignPanel-BMr-c76z.js} +1 -1
  12. package/dist/{DesignPanel.vue_vue_type_style_index_0_lang-I8C3iGvz.js → DesignPanel.vue_vue_type_style_index_0_lang-COERxrYp.js} +28 -30
  13. package/dist/DictView-DkG5lo6m.js +109 -0
  14. package/dist/InvOrganization-D_PuTpPt.js +74 -0
  15. package/dist/Org-CtVfZAjI.js +39 -0
  16. package/dist/{Preview-pHD84xqI.js → Preview-Cuj_akRk.js} +2 -2
  17. package/dist/{ReportDefine-DnnCNQWS.js → ReportDefine-CM2aNEVp.js} +1 -1
  18. package/dist/{ReportDesign-BnI_Q4pg.js → ReportDesign-B1y79NKM.js} +43 -43
  19. package/dist/{ReportQuery-Dby2MmtM.js → ReportQuery-CZEfKCWP.js} +1 -1
  20. package/dist/{ReportQueryFrom-Blm1N8P1.js → ReportQueryFrom-C_cUB8bs.js} +1 -1
  21. package/dist/{ReportQueryFrom.vue_vue_type_style_index_0_lang-CnG_Ybnt.js → ReportQueryFrom.vue_vue_type_style_index_0_lang-DBqJnvTQ.js} +1 -1
  22. package/dist/{ReportTemplate-D65RXRY_.js → ReportTemplate-BprAuCb1.js} +28 -28
  23. package/dist/{Role-eFZoTpXc.js → Role-CAaLVGNy.js} +6 -6
  24. package/dist/{RoleAssign-D9-Y3UNz.js → RoleAssign-DuFp2Ty7.js} +9 -9
  25. package/dist/{RolePanel-DlFw6HSf.js → RolePanel-BRStoO0e.js} +1 -1
  26. package/dist/{RolePanel-CoUOc3sX.js → RolePanel-FnyN7LiS.js} +1 -1
  27. package/dist/RolePanel.vue_vue_type_script_setup_true_lang-CNIA7zdk.js +132 -0
  28. package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-Clwk-MHw.js → RolePanel.vue_vue_type_script_setup_true_lang-CS7drFhn.js} +44 -38
  29. package/dist/{ScrollPanel.vue_vue_type_style_index_0_lang-M2FQJwPU.js → ScrollPanel.vue_vue_type_style_index_0_lang-CEnqhlSE.js} +23 -23
  30. package/dist/{Staff-DFBLCsAd.js → Staff-D493jHwR.js} +3 -3
  31. package/dist/{StaffInfo-d2CK0oBA.js → StaffInfo-suU_pcyD.js} +1 -1
  32. package/dist/{StaffInfo.vue_vue_type_script_setup_true_lang-4m8wK9tq.js → StaffInfo.vue_vue_type_script_setup_true_lang-DV16a2Nz.js} +16 -16
  33. package/dist/{StaffPanel-D6aWLKN3.js → StaffPanel-BbYWu-xZ.js} +1 -1
  34. package/dist/{StaffPanel.vue_vue_type_script_setup_true_lang-C7YT2CVb.js → StaffPanel.vue_vue_type_script_setup_true_lang-CfRIanr5.js} +2 -2
  35. package/dist/{SysUser-BdZvYxQH.js → SysUser-YXOsIVpJ.js} +2 -2
  36. package/dist/{SysUserPanel-BIVa6LLr.js → SysUserPanel-C1tQzih_.js} +1 -1
  37. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-BfT40pDr.js +298 -0
  38. package/dist/{SystemMenu-C-5VKlHK.js → SystemMenu-DzKl8RAz.js} +33 -33
  39. package/dist/{UserInfo-DqXCRZts.js → UserInfo-CYeYQNq8.js} +1 -1
  40. package/dist/{UserInfo.vue_vue_type_style_index_0_lang-N3TwfpPx.js → UserInfo.vue_vue_type_style_index_0_lang-DYVdi2Ck.js} +41 -39
  41. package/dist/{childView-B2lSsqS3.js → childView-BNYdfnMx.js} +1 -1
  42. package/dist/{childView-DRUNqgjI.js → childView-C6rHVrT6.js} +1 -1
  43. package/dist/{childView.vue_vue_type_style_index_0_lang-B9XBDDU_.js → childView.vue_vue_type_style_index_0_lang-6o00J0a7.js} +1 -1
  44. package/dist/{childView.vue_vue_type_style_index_0_lang-oGriyFTv.js → childView.vue_vue_type_style_index_0_lang-O_zWFjYY.js} +43 -43
  45. package/dist/{code-rule-DZC9T6cl.js → code-rule-MxcRbYZR.js} +13 -15
  46. package/dist/core.es.js +18 -10
  47. package/dist/{cron-task-BJwPeA5F.js → cron-task-B0yfTtm6.js} +11 -11
  48. package/dist/{frameView-C6wkvok-.js → frameView-DtHY5dLd.js} +1 -1
  49. package/dist/img/l_img.svg +1 -1
  50. package/dist/img/minicolors.png +0 -0
  51. package/dist/img/v_img.svg +1 -1
  52. package/dist/index-BWtOrjW2.js +4603 -0
  53. package/dist/{layoutView-CeJBpZb_.js → layoutView-D0Q7EG0u.js} +1564 -1559
  54. package/dist/{log-in-e7D5Ss1P.js → log-in-CpGqc33f.js} +5 -4
  55. package/dist/{log-out--RRncZhN.js → log-out-D1b4VRMZ.js} +30 -24
  56. package/dist/login-CuO8YgN1.js +249 -0
  57. package/dist/{login-log-CvVnyGi3.js → login-log-BNRXLeMi.js} +4 -3
  58. package/dist/{lov-view-DRF-99U4.js → lov-view-DcRVGqsD.js} +5 -5
  59. package/dist/{menuInfo-3Sjvs9nM.js → menuInfo-ccOqhCC8.js} +1 -1
  60. package/dist/{menuInfo.vue_vue_type_style_index_0_lang-DrQ560nm.js → menuInfo.vue_vue_type_style_index_0_lang-DTBPgTe_.js} +34 -32
  61. package/dist/{pda-app-B9tn7jdv.js → pda-app-D7n4oxyn.js} +202 -188
  62. package/dist/{resource-BqnxbQNe.js → resource-_h2OtsKS.js} +18 -18
  63. package/dist/{su-welcome-VwifUK_O.js → su-welcome-Co6e4akE.js} +118 -120
  64. package/dist/sys-config-C6Es9vZl.js +355 -0
  65. package/dist/udp-core.css +1 -9
  66. package/dist/utogether-MlnyYtNS.js +4 -0
  67. package/index.ts +17 -5
  68. package/package.json +1 -1
  69. package/src/App.vue +2 -7
  70. package/src/api/http.ts +1 -4
  71. package/src/api/index.ts +5 -3
  72. package/src/api/user.ts +2 -2
  73. package/src/components/SuCharts/src/UserInfo.vue +3 -3
  74. package/src/components/SuScrollTree/ScrollPanel.vue +170 -175
  75. package/src/components/udp/form/form.vue +109 -0
  76. package/src/components/udp/grid/index.vue +509 -0
  77. package/src/components/udp/index.ts +4 -4
  78. package/src/components/udp/utils.ts +405 -40
  79. package/src/directives/permission/index.ts +1 -1
  80. package/src/layout/components/lay-navbar/index.vue +9 -7
  81. package/src/layout/components/lay-panel/index.vue +3 -3
  82. package/src/layout/components/lay-search/index.vue +1 -1
  83. package/src/layout/components/lay-select-org/index.vue +4 -9
  84. package/src/layout/components/lay-sidebar/breadCrumb.vue +1 -1
  85. package/src/layout/components/lay-sidebar/horizontal.vue +4 -5
  86. package/src/layout/components/lay-sidebar/mixNav.vue +6 -4
  87. package/src/layout/components/lay-sidebar/sidebar-logo.vue +94 -98
  88. package/src/layout/components/lay-tag/index.vue +596 -625
  89. package/src/layout/hooks/useTag.ts +223 -233
  90. package/src/layout/layoutView.vue +215 -215
  91. package/src/layout/types.ts +3 -2
  92. package/src/main.ts +39 -31
  93. package/src/plugins/i18n/en.ts +26 -13
  94. package/src/plugins/i18n/zh.ts +35 -16
  95. package/src/plugins/vxe-table/index.ts +65 -2
  96. package/src/plugins/vxe-table/render.tsx +945 -817
  97. package/src/router/index.ts +186 -183
  98. package/src/router/modules/remaining.ts +1 -26
  99. package/src/router/utils.ts +393 -377
  100. package/src/store/modules/app.ts +1 -3
  101. package/src/store/modules/multiTags.ts +110 -109
  102. package/src/store/modules/permission.ts +113 -103
  103. package/src/store/modules/system.ts +1 -3
  104. package/src/style/button.scss +10 -3
  105. package/src/style/login.css +1 -1
  106. package/src/style/tailwind.css +1 -68
  107. package/src/style/vxetable.scss +348 -256
  108. package/src/utils/authority/index.ts +1 -1
  109. package/src/utils/index.ts +3 -1
  110. package/src/utils/propTypes.ts +1 -6
  111. package/src/views/login/login-view.vue +6 -20
  112. package/src/views/organization/company/CompanyPanel.vue +2 -2
  113. package/src/views/organization/department/DepartmentPanel.vue +269 -283
  114. package/src/views/organization/inv-org/InvOrganization.vue +23 -9
  115. package/src/views/organization/org/Org.vue +9 -5
  116. package/src/views/system/menu/SystemMenu.vue +183 -197
  117. package/src/views/system/menu/menuInfo.vue +8 -18
  118. package/src/views/system/role/AuthorityInfo.vue +19 -15
  119. package/src/views/system/role/Role.vue +1 -5
  120. package/src/views/system/role/RolePanel.vue +11 -2
  121. package/src/views/system/role/UserInfo.vue +11 -9
  122. package/src/views/system/role-assign/RoleAssign.vue +2 -2
  123. package/src/views/system/role-assign/RolePanel.vue +12 -9
  124. package/src/views/system/sys/sys-config.vue +66 -21
  125. package/src/views/system/sysUser/SysUserPanel.vue +44 -43
  126. package/src/views/uapp/pda/pda-app.vue +48 -16
  127. package/src/views/udev/coderule/code-rule.vue +120 -121
  128. package/src/views/udev/dict/DictView.vue +16 -4
  129. package/src/views/udev/dict/childView.vue +8 -8
  130. package/src/views/ufile/aggregation/File.vue +5 -5
  131. package/src/views/ufile/file/water-mark.vue +14 -14
  132. package/src/views/uhome/components/menu-favorite.vue +314 -331
  133. package/src/views/uhome/su-welcome.vue +3 -3
  134. package/src/views/ulogin/login.vue +19 -12
  135. package/src/views/upms/interface/log-in.vue +100 -106
  136. package/src/views/upms/interface/log-out.vue +2 -8
  137. package/src/views/upms/user/login-log.vue +54 -60
  138. package/src/views/urpt/design/DesignPanel.vue +16 -35
  139. package/src/views/urpt/design/Preview.vue +1 -0
  140. package/src/views/urpt/design/ReportDesign.vue +17 -23
  141. package/src/views/urpt/static-resource/resource.vue +3 -3
  142. package/src/views/urpt/template/ReportTemplate.vue +7 -7
  143. package/types/global.d.ts +4 -9
  144. package/vite.config.ts +6 -2
  145. package/dist/AuthorityInfo.vue_vue_type_style_index_0_lang-Duyweh89.js +0 -102
  146. package/dist/DictView-B4a7Hs1X.js +0 -95
  147. package/dist/InvOrganization-q4T3y8dQ.js +0 -260
  148. package/dist/Org-BTGTrAVz.js +0 -35
  149. package/dist/RolePanel.vue_vue_type_script_setup_true_lang-DKHgNWQP.js +0 -126
  150. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-BsBKpYR7.js +0 -288
  151. package/dist/index-DZc3qRTx.js +0 -2650
  152. package/dist/login-BOxwzwdB.js +0 -252
  153. package/dist/sys-config-C0-gSBFO.js +0 -277
  154. package/dist/utogether-Di1byIum.js +0 -182
  155. package/src/components/udp/form-upload.vue +0 -183
  156. package/src/components/udp/modal-form.vue +0 -180
  157. package/src/utils/http/index.ts +0 -297
  158. package/src/utils/http/types.d.ts +0 -46
  159. package/src/utils/udp/useRender.ts +0 -420
@@ -1,180 +0,0 @@
1
- <!--
2
- * @Author: wei.li
3
- * @Date: 2021-11-29 21:02:43
4
- * @LastEditors: levi7754 levi7754@163.com
5
- * @LastEditTime: 2025-07-14 17:38:19
6
- * @Description: file content
7
- -->
8
-
9
- <template>
10
- <div>
11
- <vxe-modal
12
- v-model="showModal"
13
- :title="title"
14
- :width="width"
15
- :height="height"
16
- :loading="loading"
17
- :show-footer="dataStatus !== 'detail'"
18
- v-bind="modalAttrs"
19
- min-width="240"
20
- min-height="300"
21
- destroy-on-close
22
- resize
23
- @close="onClose"
24
- >
25
- <template #default>
26
- <vxe-form
27
- ref="xForm"
28
- :data="record"
29
- :items="formItems"
30
- :rules="rules"
31
- title-align="right"
32
- :title-width="formAttrs.titleWidth || 90"
33
- v-bind="formAttrs"
34
- />
35
- </template>
36
- <template #footer>
37
- <ut-button status="warning" content="cancel" icon="ri-close-line" @tap="onClose" />
38
- <ut-button status="u-cyan" content="confirm" icon="ri-save-3-line" @tap="onConfirm" />
39
- </template>
40
- </vxe-modal>
41
- </div>
42
- </template>
43
-
44
- <script lang="ts">
45
- export default {
46
- name: 'UtModalForm'
47
- };
48
- </script>
49
- <script lang="ts" setup>
50
- import { onBeforeMount, ref, computed, getCurrentInstance, useAttrs } from 'vue';
51
- import { useI18n } from 'vue-i18n';
52
- import { getAttrs, formatItems } from './utils';
53
- import to from 'await-to-js';
54
- import { formatRules, successMessage } from '@utogether/utils';
55
-
56
- // import type { IRecord, IFormItemProps } from '../../types';
57
-
58
- export interface IProps {
59
- record: IRecord; // 数据对象
60
- formAttrs?: IRecord;
61
- modalAttrs?: IRecord;
62
- items: Array<IFormItemProps>; // form item
63
- url?: string; // 服务路径
64
- method?: string; // 请求方式
65
- title?: string; // 标题
66
- dataStatus?: string; // 状态
67
- width?: number;
68
- height?: number;
69
- }
70
-
71
- const props = withDefaults(defineProps<IProps>(), {
72
- record: (): IRecord => {
73
- return {};
74
- },
75
- formAttrs: (): IRecord => {
76
- return {};
77
- },
78
- items: () => [],
79
- title: '数据记录',
80
- width: 420,
81
- height: 360,
82
- dataStatus: 'detail',
83
- url: '',
84
- method: 'post'
85
- });
86
-
87
- const attrs: IRecord = getAttrs(useAttrs());
88
-
89
- const loading = ref(false);
90
- const instance = getCurrentInstance()!;
91
-
92
- const serviceApi = instance.appContext.config.globalProperties.$serviceApi;
93
-
94
- /**
95
- * @description: 根据items 获取必填选
96
- */
97
- const rules = computed(() => {
98
- if (!props.items.length) return {};
99
- return formatRules(props.items, t);
100
- });
101
-
102
- const formItems = computed(() => {
103
- if (!props.items.length) return props.items;
104
- return formatItems(props.items, props.dataStatus);
105
- });
106
-
107
- const { t } = useI18n();
108
- const showModal = ref(false);
109
-
110
- const xForm = ref(null);
111
- /**
112
- * @description: 弹框确认
113
- */
114
- const onConfirm = () => {
115
- // @ts-ignore
116
- xForm.value.validate(async (valid: boolean) => {
117
- if (!valid) {
118
- const { record, url, method } = props;
119
- if (url) {
120
- showLoading();
121
- const body = attrs?.dataProcessMethod ? attrs?.dataProcessMethod(record) : record;
122
- if (url) {
123
- const [err, data] = await to(serviceApi[method](url, body));
124
- if (!err) {
125
- successMessage();
126
- emit('confirm', data);
127
- }
128
- }
129
- hiddenLoading();
130
- onClose();
131
- } else {
132
- emit('confirm');
133
- }
134
- }
135
- });
136
- };
137
-
138
- /**
139
- * @description: 显示加载框
140
- */
141
- const showLoading = () => {
142
- loading.value = true;
143
- };
144
-
145
- /**
146
- * @description: 关闭加载框
147
- */
148
- const hiddenLoading = () => {
149
- loading.value = false;
150
- };
151
- const validateForm = (cb: Function) => {
152
- // @ts-ignore
153
- xForm.value.validate(cb);
154
- };
155
-
156
- /**
157
- * @description: 关闭弹框
158
- */
159
- const onClose = () => {
160
- showModal.value = false;
161
- emit('close');
162
- };
163
- /**
164
- * @description: 打开弹框
165
- */
166
- const openModal = () => {
167
- showModal.value = true;
168
- };
169
-
170
- const emit = defineEmits<{
171
- (e: 'close'): void;
172
- (e: 'confirm', record?: any): void;
173
- }>();
174
-
175
- defineExpose({ showLoading, hiddenLoading, openModal, validateForm });
176
-
177
- onBeforeMount(() => {
178
- openModal();
179
- });
180
- </script>
@@ -1,297 +0,0 @@
1
- import Axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios';
2
- import type { SuHttpError, RequestMethods, SuHttpResponse, SuHttpRequestConfig } from './types.d';
3
- import { has } from 'xe-utils';
4
- import { NProgress, cookies, errorMessage } from '@utogether/utils';
5
- import { isRef } from 'vue';
6
-
7
- const kTOKENKEY = 'authorized-token';
8
- const defaultConfig: AxiosRequestConfig = {
9
- timeout: 180000,
10
- headers: {
11
- Accept: 'application/json, text/plain, */*',
12
- 'Content-Type': 'application/json',
13
- 'X-Requested-With': 'XMLHttpRequest'
14
- }
15
- };
16
- class SuHttp {
17
- constructor() {
18
- this.httpInterceptorsRequest();
19
- this.httpInterceptorsResponse();
20
- }
21
- baseUrl = null;
22
- router = null;
23
- /** token过期后,暂存待执行的请求 */
24
- private static requests = [];
25
-
26
- /** 防止重复刷新token */
27
- private static isRefreshing = false;
28
-
29
- /** 设置router调整 */
30
- setRouter(router) {
31
- this.router = router;
32
- }
33
-
34
- setBaseUrl(baseUrl) {
35
- this.baseUrl = baseUrl;
36
- }
37
- // 初始化配置对象
38
- private static initConfig: SuHttpRequestConfig = {};
39
-
40
- // 保存当前Axios实例对象
41
- private static axiosInstance: AxiosInstance = Axios.create(defaultConfig);
42
-
43
- /** 重连原始请求 */
44
- private static retryOriginalRequest(config: SuHttpRequestConfig) {
45
- return new Promise(resolve => {
46
- // @ts-ignore
47
- SuHttp.requests.push((token: string) => {
48
- config.headers!['Authorization'] = 'Bearer ' + token;
49
- resolve(config);
50
- });
51
- });
52
- }
53
-
54
- // 请求拦截
55
- private httpInterceptorsRequest(): void {
56
- SuHttp.axiosInstance.interceptors.request.use(
57
- (config: any) => {
58
- if (has(config, 'loading') && isRef(config.loading)) {
59
- config.loading.value = true;
60
- }
61
- // 开启进度条动画
62
- NProgress.start();
63
- // 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
64
- if (typeof config.beforeRequestCallback === 'function') {
65
- config.beforeRequestCallback(config);
66
- return config;
67
- }
68
- if (SuHttp.initConfig.beforeRequestCallback) {
69
- SuHttp.initConfig.beforeRequestCallback(config);
70
- return config;
71
- }
72
- const whiteList = ['/refreshToken', '/login'];
73
- if (whiteList.some(v => config.url.indexOf(v) > -1)) return config;
74
- return new Promise(resolve => {
75
- const token = cookies.get(kTOKENKEY);
76
- if (token) {
77
- const data = JSON.parse(token);
78
- const now = new Date().getTime();
79
- const expired = data.expires - now <= 0;
80
- if (expired) {
81
- if (!SuHttp.isRefreshing) {
82
- SuHttp.isRefreshing = true;
83
- // requests.push(() => SuHttp.axiosInstance(config));
84
-
85
- this.get(this.baseUrl + '/uath/refreshToken', {
86
- refreshToken: data.refreshToken
87
- })
88
- .then((res: any) => {
89
- // 替换token
90
- this.setToken(res);
91
- config.headers['Authorization'] = 'Bearer ' + res.access_token;
92
- // token 刷新后将数组的方法重新执行
93
- // @ts-ignore
94
- SuHttp.requests.forEach(cb => cb(res.access_token));
95
- SuHttp.requests = []; // 重新请求完清空
96
- })
97
- .finally(() => {
98
- SuHttp.isRefreshing = false;
99
- });
100
- }
101
- // @ts-ignore
102
- resolve(SuHttp.retryOriginalRequest(config));
103
- } else {
104
- config.headers['Authorization'] = 'Bearer ' + data.accessToken;
105
- resolve(config);
106
- }
107
- } else {
108
- const sessionKey = cookies.get('kCookies_token') as string;
109
- if (sessionKey) {
110
- config.headers['X-Token'] = sessionKey;
111
- }
112
- resolve(config);
113
- }
114
- });
115
- },
116
- error => {
117
- return Promise.reject(error);
118
- }
119
- );
120
- }
121
-
122
- private setToken(token) {
123
- const { access_token, expires_in, refresh_token } = token;
124
- const cache = {
125
- accessToken: access_token,
126
- refreshToken: refresh_token,
127
- expires: Date.now() + expires_in * 1000
128
- };
129
- cookies.set(kTOKENKEY, JSON.stringify(cache));
130
- // cookies.set(kTOKENKEY, JSON.stringify(cache), { expires: expires_in });
131
- }
132
-
133
- // 响应拦截
134
- private httpInterceptorsResponse(): void {
135
- const instance = SuHttp.axiosInstance;
136
- instance.interceptors.response.use(
137
- (response: SuHttpResponse) => {
138
- const $config = response.config;
139
- if (has($config, 'loading') && isRef($config.loading)) {
140
- $config.loading.value = false;
141
- }
142
- // 关闭进度条动画
143
- NProgress.done();
144
- // 优先判断post/get等方法是否传入回掉,否则执行初始化设置等回掉
145
- if (typeof $config.beforeResponseCallback === 'function') {
146
- $config.beforeResponseCallback(response);
147
- return response.data;
148
- }
149
- if (SuHttp.initConfig.beforeResponseCallback) {
150
- SuHttp.initConfig.beforeResponseCallback(response);
151
- return response.data;
152
- }
153
- return response.data;
154
- },
155
- (error: SuHttpError) => {
156
- // @ts-ignore
157
- if (has(error.config, 'loading') && isRef(error.config.loading)) {
158
- // @ts-ignore
159
- error.config.loading.value = false;
160
- }
161
- const $error = error;
162
- $error.isCancelRequest = Axios.isCancel($error);
163
- // 关闭进度条动画
164
- NProgress.done();
165
- // 所有的响应异常 区分来源为取消请求/非取消请求
166
- return Promise.reject($error);
167
- }
168
- );
169
- }
170
-
171
- private transformConfigByMethod(params: any, config: SuHttpRequestConfig): SuHttpRequestConfig {
172
- const { method } = config;
173
- const methods = ['get'];
174
- const m = method!.toLocaleLowerCase();
175
- const props = methods.includes(m) ? 'params' : 'data';
176
- return {
177
- ...config,
178
- [props]: params
179
- };
180
- }
181
-
182
- // 通用请求工具函数
183
- public request<T>(
184
- method: RequestMethods,
185
- url: string,
186
- param?: AxiosRequestConfig,
187
- axiosConfig?: SuHttpRequestConfig
188
- ): Promise<T> {
189
- const config = this.transformConfigByMethod(param, {
190
- method,
191
- url,
192
- ...axiosConfig
193
- } as SuHttpRequestConfig);
194
- // 单独处理自定义请求/响应回掉
195
- return new Promise((resolve, reject) => {
196
- SuHttp.axiosInstance
197
- .request(config)
198
- .then((res: any) => {
199
- if (res && res?.code === '0') {
200
- resolve(res.data);
201
- } else if (res.code === '500') {
202
- errorMessage(res.msg, { duration: 8000 });
203
- if (config.method === 'get') {
204
- resolve(res);
205
- } else {
206
- reject(res.msg);
207
- }
208
- } else if (res?.code !== '-1') {
209
- resolve(res);
210
- } else {
211
- const msg = res?.msg || '服务异常';
212
- errorMessage(msg, { duration: 8000 });
213
- // const code = res.code;
214
- // if (
215
- // code === "000001" ||
216
- // (code === "-1" && msg.includes("请重新登陆"))
217
- // ) {
218
- // // session过期
219
- // cookies.remove("kCookies_token");
220
- // // @ts-ignore
221
- // this.router?.push({
222
- // path: "/login",
223
- // query: { tokenExpire: "Y" },
224
- // });
225
- // }
226
- reject(msg);
227
- }
228
- })
229
- .catch(e => {
230
- debugger;
231
- if (e?.response?.data?.path === '/refreshToken') {
232
- this.router?.push('/login');
233
- } else if (e?.code) {
234
- if (e?.response?.status === 401) {
235
- // @ts-ignore
236
- return this.router?.push({ path: '/login' });
237
- }
238
- errorMessage(this.getNetworkError(e?.response?.status) || e?.message, { duration: 8000 });
239
- }
240
- if (e.config.method === 'get') {
241
- resolve(e);
242
- } else {
243
- reject(e);
244
- }
245
- });
246
- });
247
- }
248
-
249
- getNetworkError = code => {
250
- if (!code) return null;
251
- const msgMap = {
252
- 400: '错误的请求',
253
- 401: '服务未授权,请重新登录',
254
- 403: '拒绝访问',
255
- 404: '请求错误,未找到该资源',
256
- 408: '请求超时',
257
- 500: '服务器端出差',
258
- 502: '网络超时',
259
- 503: '服务不可用',
260
- 504: '网络超时'
261
- };
262
- return msgMap[code];
263
- };
264
-
265
- // 单独抽离的post工具函数
266
- public post<T, P>(url: string, params?: T, config?: SuHttpRequestConfig): Promise<P> {
267
- // @ts-ignore
268
- return this.request<P>('post', url, params, config);
269
- }
270
-
271
- // 单独抽离的delete工具函数
272
- public delete<T, P>(url: string, params?: T, config?: SuHttpRequestConfig): Promise<P> {
273
- // @ts-ignore
274
- return this.request<P>('delete', url, params, config);
275
- }
276
-
277
- // 单独抽离的put工具函数
278
- public put<T, P>(url: string, params?: T, config?: SuHttpRequestConfig): Promise<P> {
279
- // @ts-ignore
280
- return this.request<P>('put', url, params, config);
281
- }
282
-
283
- // 单独抽离的get工具函数
284
- public get<T, P>(url: string, params?: T, config?: SuHttpRequestConfig): Promise<P> {
285
- for (const key in params) {
286
- if (!params[key]) delete params[key];
287
- }
288
- // @ts-ignore
289
- return this.request<P>('get', url, params, config);
290
- }
291
-
292
- public postRouter<T>(params?: any): Promise<T> {
293
- return this.request<T>('post', 'route/service', params);
294
- }
295
- }
296
-
297
- export const http = new SuHttp();
@@ -1,46 +0,0 @@
1
- /*
2
- * @Author: wei.li
3
- * @Date: 2022-03-08 15:17:39
4
- * @LastEditors: levi7754 levi7754@163.com
5
- * @LastEditTime: 2023-12-01 11:59:12
6
- * @Description: SuHttp Axios 类型定义文件
7
- */
8
- import type { Method, AxiosError, AxiosResponse, AxiosRequestConfig } from 'axios';
9
-
10
- export type resultType = {
11
- access_token: string;
12
- refresh_token: string;
13
- expires_in: number;
14
- };
15
-
16
- export type RequestMethods = Extract<
17
- Method,
18
- 'get' | 'post' | 'put' | 'delete' | 'patch' | 'option' | 'head'
19
- >;
20
-
21
- export interface SuHttpError extends AxiosError {
22
- isCancelRequest?: boolean;
23
- loading?: boolean;
24
- }
25
-
26
- export interface SuHttpResponse extends AxiosResponse {
27
- config: SuHttpRequestConfig;
28
- }
29
-
30
- export interface SuHttpRequestConfig extends AxiosRequestConfig {
31
- beforeRequestCallback?: (request: SuHttpRequestConfig) => void;
32
- beforeResponseCallback?: (response: SuHttpResponse) => void;
33
- loading?: any;
34
- }
35
-
36
- export default class SuHttp {
37
- request<T>(
38
- method: RequestMethods,
39
- url: string,
40
- param?: AxiosRequestConfig,
41
- axiosConfig?: SuHttpRequestConfig
42
- ): Promise<T>;
43
- post<T, P>(url: string, params?: T, config?: SuHttpRequestConfig): Promise<P>;
44
- postRouter<T, P>(url: string, params?: T, config?: SuHttpRequestConfig): Promise<P>;
45
- get<T, P>(url: string, params?: T, config?: SuHttpRequestConfig): Promise<P>;
46
- }