@utogether/udp-core 1.0.1-beta.2 → 1.0.1-beta.20
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/build/plugins.ts +8 -1
- package/dist/{403-BBQoJwTM.js → 403-Bz5EJPLA.js} +1 -1
- package/dist/{404-BbJPSIWM.js → 404-ClOnaj9V.js} +1 -1
- package/dist/{500-BtFL9R4M.js → 500-DCUfhV7Y.js} +1 -1
- package/dist/{AuthorityInfo-DhiwCeLN.js → AuthorityInfo-q6E-js1r.js} +1 -1
- package/dist/AuthorityInfo.vue_vue_type_style_index_0_lang-BM52QDgn.js +100 -0
- package/dist/{Company-CGqmslx-.js → Company-BSShW3Q4.js} +3 -3
- package/dist/{CompanyPanel-hlDsxD-6.js → CompanyPanel-Dl8eOYLk.js} +26 -26
- package/dist/{Department-BZyJtacc.js → Department-CVIxAnUN.js} +3 -3
- package/dist/{DepartmentPanel-D-a_EBFt.js → DepartmentPanel-Sa3IDl4z.js} +25 -25
- package/dist/{DesignPanel-Bl4luWDV.js → DesignPanel-DnRipagE.js} +1 -1
- package/dist/{DesignPanel.vue_vue_type_style_index_0_lang-I8C3iGvz.js → DesignPanel.vue_vue_type_style_index_0_lang-DGNyp3Vl.js} +28 -30
- package/dist/DictView-uf2K9A1d.js +109 -0
- package/dist/InvOrganization-CG9VCpXl.js +74 -0
- package/dist/Org-W2CBN1B8.js +39 -0
- package/dist/{Preview-pHD84xqI.js → Preview-DPBxdDvW.js} +2 -2
- package/dist/{ReportDefine-DnnCNQWS.js → ReportDefine-Dsx9VM-I.js} +1 -1
- package/dist/{ReportDesign-BnI_Q4pg.js → ReportDesign-DiIGfte0.js} +43 -43
- package/dist/{ReportQuery-Dby2MmtM.js → ReportQuery-9A4Bfs1M.js} +1 -1
- package/dist/{ReportQueryFrom-Blm1N8P1.js → ReportQueryFrom-M5qLoGAa.js} +1 -1
- package/dist/{ReportQueryFrom.vue_vue_type_style_index_0_lang-CnG_Ybnt.js → ReportQueryFrom.vue_vue_type_style_index_0_lang-OQ9pUCKP.js} +1 -1
- package/dist/{ReportTemplate-D65RXRY_.js → ReportTemplate-C34FWAuK.js} +28 -28
- package/dist/{Role-eFZoTpXc.js → Role-jG3VTeOF.js} +6 -6
- package/dist/{RoleAssign-D9-Y3UNz.js → RoleAssign-BfHpCequ.js} +9 -9
- package/dist/{RolePanel-DlFw6HSf.js → RolePanel-DW9pNl0L.js} +1 -1
- package/dist/{RolePanel-CoUOc3sX.js → RolePanel-xRN2-rkk.js} +1 -1
- package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-Clwk-MHw.js → RolePanel.vue_vue_type_script_setup_true_lang-BVEHqEq9.js} +44 -38
- package/dist/RolePanel.vue_vue_type_script_setup_true_lang-C0rTy6vZ.js +132 -0
- package/dist/{ScrollPanel.vue_vue_type_style_index_0_lang-M2FQJwPU.js → ScrollPanel.vue_vue_type_style_index_0_lang-D65sJYWT.js} +23 -23
- package/dist/{Staff-DFBLCsAd.js → Staff-BqBVEjau.js} +3 -3
- package/dist/{StaffInfo-d2CK0oBA.js → StaffInfo-DXeyyEFL.js} +1 -1
- package/dist/{StaffInfo.vue_vue_type_script_setup_true_lang-4m8wK9tq.js → StaffInfo.vue_vue_type_script_setup_true_lang-Dg0iYgRf.js} +16 -16
- package/dist/{StaffPanel-D6aWLKN3.js → StaffPanel-iE-8VtUm.js} +1 -1
- package/dist/{StaffPanel.vue_vue_type_script_setup_true_lang-C7YT2CVb.js → StaffPanel.vue_vue_type_script_setup_true_lang-BrrvE1xm.js} +2 -2
- package/dist/{SysUser-BdZvYxQH.js → SysUser-DSZyW30i.js} +2 -2
- package/dist/{SysUserPanel-BIVa6LLr.js → SysUserPanel-CbiG6GQF.js} +1 -1
- package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-B1Y1fmBe.js +298 -0
- package/dist/{SystemMenu-C-5VKlHK.js → SystemMenu-DreuWY-a.js} +33 -33
- package/dist/{UserInfo-DqXCRZts.js → UserInfo-DXrzKAim.js} +1 -1
- package/dist/{UserInfo.vue_vue_type_style_index_0_lang-N3TwfpPx.js → UserInfo.vue_vue_type_style_index_0_lang-C44E20b4.js} +41 -39
- package/dist/{childView-B2lSsqS3.js → childView-VCidWgY6.js} +1 -1
- package/dist/{childView-DRUNqgjI.js → childView-k5IkJOBr.js} +1 -1
- package/dist/{childView.vue_vue_type_style_index_0_lang-B9XBDDU_.js → childView.vue_vue_type_style_index_0_lang-C6ftwwvZ.js} +1 -1
- package/dist/{childView.vue_vue_type_style_index_0_lang-oGriyFTv.js → childView.vue_vue_type_style_index_0_lang-DmG82dVB.js} +43 -43
- package/dist/{code-rule-DZC9T6cl.js → code-rule-7WQMabpW.js} +13 -15
- package/dist/core.es.js +18 -10
- package/dist/{cron-task-BJwPeA5F.js → cron-task-D1t56MSu.js} +11 -11
- package/dist/{frameView-C6wkvok-.js → frameView-CWsIFBgU.js} +1 -1
- package/dist/img/l_img.svg +1 -1
- package/dist/img/minicolors.png +0 -0
- package/dist/img/v_img.svg +1 -1
- package/dist/index-DxWAYxai.js +5495 -0
- package/dist/{layoutView-CeJBpZb_.js → layoutView-DLpHSner.js} +1564 -1559
- package/dist/{log-in-e7D5Ss1P.js → log-in-CpGqc33f.js} +5 -4
- package/dist/{log-out--RRncZhN.js → log-out-D1b4VRMZ.js} +30 -24
- package/dist/login-OjDiQmz8.js +249 -0
- package/dist/{login-log-CvVnyGi3.js → login-log-BNRXLeMi.js} +4 -3
- package/dist/{lov-view-DRF-99U4.js → lov-view-D28X6m3k.js} +5 -5
- package/dist/{menuInfo-3Sjvs9nM.js → menuInfo-DwPB6rHz.js} +1 -1
- package/dist/{menuInfo.vue_vue_type_style_index_0_lang-DrQ560nm.js → menuInfo.vue_vue_type_style_index_0_lang-l5DNRfb7.js} +34 -32
- package/dist/{pda-app-B9tn7jdv.js → pda-app-Bdms2PRY.js} +202 -188
- package/dist/{resource-BqnxbQNe.js → resource-y6SHrHoq.js} +18 -18
- package/dist/{su-welcome-VwifUK_O.js → su-welcome-D9G6EuK2.js} +118 -120
- package/dist/sys-config-DFnGHiFc.js +355 -0
- package/dist/udp-core.css +1 -9
- package/dist/utogether-MlnyYtNS.js +4 -0
- package/index.ts +17 -5
- package/package.json +1 -1
- package/src/App.vue +2 -7
- package/src/api/http.ts +1 -4
- package/src/api/index.ts +5 -3
- package/src/api/user.ts +2 -2
- package/src/components/SuCharts/src/UserInfo.vue +3 -3
- package/src/components/SuScrollTree/ScrollPanel.vue +170 -175
- package/src/components/udp/form/form.vue +109 -0
- package/src/components/udp/grid/index.vue +509 -0
- package/src/components/udp/index.ts +4 -4
- package/src/components/udp/utils.ts +405 -40
- package/src/directives/permission/index.ts +1 -1
- package/src/layout/components/lay-navbar/index.vue +9 -7
- package/src/layout/components/lay-panel/index.vue +3 -3
- package/src/layout/components/lay-search/index.vue +1 -1
- package/src/layout/components/lay-select-org/index.vue +4 -9
- package/src/layout/components/lay-sidebar/breadCrumb.vue +1 -1
- package/src/layout/components/lay-sidebar/horizontal.vue +4 -5
- package/src/layout/components/lay-sidebar/mixNav.vue +6 -4
- package/src/layout/components/lay-sidebar/sidebar-logo.vue +94 -98
- package/src/layout/components/lay-tag/index.vue +596 -625
- package/src/layout/hooks/useTag.ts +223 -233
- package/src/layout/layoutView.vue +215 -215
- package/src/layout/types.ts +3 -2
- package/src/main.ts +39 -31
- package/src/plugins/i18n/en.ts +26 -13
- package/src/plugins/i18n/zh.ts +35 -16
- package/src/plugins/vxe-table/index.ts +67 -4
- package/src/plugins/vxe-table/render.tsx +945 -817
- package/src/router/index.ts +186 -183
- package/src/router/modules/remaining.ts +1 -26
- package/src/router/utils.ts +393 -377
- package/src/store/modules/app.ts +1 -3
- package/src/store/modules/multiTags.ts +110 -109
- package/src/store/modules/permission.ts +113 -103
- package/src/store/modules/system.ts +1 -3
- package/src/style/button.scss +10 -3
- package/src/style/login.css +1 -1
- package/src/style/tailwind.css +1 -68
- package/src/style/vxetable.scss +348 -256
- package/src/utils/authority/index.ts +1 -1
- package/src/utils/index.ts +3 -1
- package/src/utils/propTypes.ts +1 -6
- package/src/views/login/login-view.vue +6 -20
- package/src/views/organization/company/CompanyPanel.vue +2 -2
- package/src/views/organization/department/DepartmentPanel.vue +269 -283
- package/src/views/organization/inv-org/InvOrganization.vue +23 -9
- package/src/views/organization/org/Org.vue +9 -5
- package/src/views/system/menu/SystemMenu.vue +183 -197
- package/src/views/system/menu/menuInfo.vue +8 -18
- package/src/views/system/role/AuthorityInfo.vue +19 -15
- package/src/views/system/role/Role.vue +1 -5
- package/src/views/system/role/RolePanel.vue +11 -2
- package/src/views/system/role/UserInfo.vue +11 -9
- package/src/views/system/role-assign/RoleAssign.vue +2 -2
- package/src/views/system/role-assign/RolePanel.vue +12 -9
- package/src/views/system/sys/sys-config.vue +66 -21
- package/src/views/system/sysUser/SysUserPanel.vue +44 -43
- package/src/views/uapp/pda/pda-app.vue +48 -16
- package/src/views/udev/coderule/code-rule.vue +120 -121
- package/src/views/udev/dict/DictView.vue +16 -4
- package/src/views/udev/dict/childView.vue +8 -8
- package/src/views/ufile/aggregation/File.vue +5 -5
- package/src/views/ufile/file/water-mark.vue +14 -14
- package/src/views/uhome/components/menu-favorite.vue +314 -331
- package/src/views/uhome/su-welcome.vue +3 -3
- package/src/views/ulogin/login.vue +19 -12
- package/src/views/upms/interface/log-in.vue +100 -106
- package/src/views/upms/interface/log-out.vue +2 -8
- package/src/views/upms/user/login-log.vue +54 -60
- package/src/views/urpt/design/DesignPanel.vue +16 -35
- package/src/views/urpt/design/Preview.vue +1 -0
- package/src/views/urpt/design/ReportDesign.vue +17 -23
- package/src/views/urpt/static-resource/resource.vue +3 -3
- package/src/views/urpt/template/ReportTemplate.vue +7 -7
- package/types/global.d.ts +4 -9
- package/vite.config.ts +6 -2
- package/dist/AuthorityInfo.vue_vue_type_style_index_0_lang-Duyweh89.js +0 -102
- package/dist/DictView-B4a7Hs1X.js +0 -95
- package/dist/InvOrganization-q4T3y8dQ.js +0 -260
- package/dist/Org-BTGTrAVz.js +0 -35
- package/dist/RolePanel.vue_vue_type_script_setup_true_lang-DKHgNWQP.js +0 -126
- package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-BsBKpYR7.js +0 -288
- package/dist/index-DZc3qRTx.js +0 -2650
- package/dist/login-BOxwzwdB.js +0 -252
- package/dist/sys-config-C0-gSBFO.js +0 -277
- package/dist/utogether-Di1byIum.js +0 -182
- package/src/components/udp/form-upload.vue +0 -183
- package/src/components/udp/modal-form.vue +0 -180
- package/src/utils/http/index.ts +0 -297
- package/src/utils/http/types.d.ts +0 -46
- 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>
|
package/src/utils/http/index.ts
DELETED
|
@@ -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
|
-
}
|