zant-admin 2.0.2 → 2.0.4
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/.editorconfig +6 -0
- package/.env.development +3 -0
- package/.env.production +1 -0
- package/.env.test +1 -0
- package/.gitignore +36 -0
- package/.prettierrc.json +9 -0
- package/README.en.md +461 -272
- package/README.md +4 -3
- package/bin/cli.js +1 -1
- package/eslint.config.js +30 -0
- package/index.html +13 -0
- package/jsconfig.json +8 -0
- package/package.json +11 -3
- package/src/App.vue +16 -16
- package/src/api/methods/logError.js +8 -8
- package/src/api/methods/logOperation.js +8 -8
- package/src/api/methods/login.js +6 -6
- package/src/api/methods/quartz.js +36 -36
- package/src/api/methods/region.js +16 -16
- package/src/api/methods/sysAccount.js +29 -29
- package/src/api/methods/sysDict.js +29 -29
- package/src/api/methods/sysDictItem.js +26 -26
- package/src/api/methods/sysMenu.js +42 -42
- package/src/api/methods/sysRole.js +35 -35
- package/src/api/methods/sysUser.js +25 -25
- package/src/api/methods/system.js +15 -15
- package/src/api/request.js +225 -225
- package/src/assets/css/zcui.css +1023 -1023
- package/src/components/IconPicker.vue +351 -351
- package/src/components/MainPage.vue +838 -838
- package/src/components/details/logErrorDetails.vue +58 -58
- package/src/components/details/logOperationDetails.vue +76 -76
- package/src/components/edit/QuartzEdit.vue +221 -221
- package/src/components/edit/SysAccountEdit.vue +185 -185
- package/src/components/edit/SysDictEdit.vue +116 -116
- package/src/components/edit/SysDictItemEdit.vue +136 -136
- package/src/components/edit/SysRoleEdit.vue +111 -111
- package/src/config/index.js +74 -74
- package/src/directives/permission.js +49 -49
- package/src/main.js +37 -37
- package/src/stores/config.js +43 -43
- package/src/stores/dict.js +33 -33
- package/src/stores/menu.js +81 -81
- package/src/stores/user.js +21 -21
- package/src/utils/baseEcharts.js +661 -661
- package/src/utils/dictTemplate.js +26 -26
- package/src/utils/regionUtils.js +173 -173
- package/src/utils/useFormCRUD.js +59 -59
- package/src/views/baiscstatis/center.vue +474 -474
- package/src/views/baiscstatis/iframePage.vue +29 -29
- package/src/views/baiscstatis/notFound.vue +192 -192
- package/src/views/console.vue +821 -821
- package/src/views/demo/button.vue +269 -269
- package/src/views/demo/importexport.vue +119 -119
- package/src/views/demo/region.vue +322 -322
- package/src/views/demo/statistics.vue +214 -214
- package/src/views/home.vue +6 -6
- package/src/views/operations/log/logError.vue +78 -78
- package/src/views/operations/log/logLogin.vue +66 -66
- package/src/views/operations/log/logOperation.vue +103 -103
- package/src/views/operations/log/logQuartz.vue +56 -56
- package/src/views/operations/quartz.vue +179 -179
- package/src/views/operations/serviceMonitoring.vue +134 -134
- package/src/views/system/sysAccount.vue +128 -128
- package/src/views/system/sysDict.vue +159 -159
- package/src/views/system/sysDictItem.vue +118 -118
- package/src/views/system/sysMenu.vue +225 -225
- package/src/views/system/sysRole.vue +207 -207
- package/vite.config.js +33 -0
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { post, get } from '@/api/request'
|
|
2
|
-
|
|
3
|
-
const sysUser = {
|
|
4
|
-
//根据id获取信息
|
|
5
|
-
get(params) {
|
|
6
|
-
return get('sysUser/get', params)
|
|
7
|
-
},
|
|
8
|
-
//新增
|
|
9
|
-
add(params) {
|
|
10
|
-
return post('sysUser/add', params)
|
|
11
|
-
},
|
|
12
|
-
//保存
|
|
13
|
-
save(params) {
|
|
14
|
-
return post('sysUser/save', params)
|
|
15
|
-
},
|
|
16
|
-
//修改是否启用
|
|
17
|
-
updateIsEnabled(params) {
|
|
18
|
-
return get('sysUser/updateIsEnabled', params)
|
|
19
|
-
},
|
|
20
|
-
//发送短信
|
|
21
|
-
sendCode(params) {
|
|
22
|
-
return get('sysUser/sendCode', params)
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
export default sysUser
|
|
1
|
+
import { post, get } from '@/api/request'
|
|
2
|
+
|
|
3
|
+
const sysUser = {
|
|
4
|
+
//根据id获取信息
|
|
5
|
+
get(params) {
|
|
6
|
+
return get('sysUser/get', params)
|
|
7
|
+
},
|
|
8
|
+
//新增
|
|
9
|
+
add(params) {
|
|
10
|
+
return post('sysUser/add', params)
|
|
11
|
+
},
|
|
12
|
+
//保存
|
|
13
|
+
save(params) {
|
|
14
|
+
return post('sysUser/save', params)
|
|
15
|
+
},
|
|
16
|
+
//修改是否启用
|
|
17
|
+
updateIsEnabled(params) {
|
|
18
|
+
return get('sysUser/updateIsEnabled', params)
|
|
19
|
+
},
|
|
20
|
+
//发送短信
|
|
21
|
+
sendCode(params) {
|
|
22
|
+
return get('sysUser/sendCode', params)
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
export default sysUser
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { get } from '@/api/request'
|
|
2
|
-
const system = {
|
|
3
|
-
/// 获取系统描述
|
|
4
|
-
|
|
5
|
-
getSystemDescription() {
|
|
6
|
-
return get('server/getSystemDescription')
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
/// 获取系统更新记录
|
|
10
|
-
|
|
11
|
-
projectUpdateRecord() {
|
|
12
|
-
return get('server/projectUpdateRecord')
|
|
13
|
-
},
|
|
14
|
-
}
|
|
15
|
-
export default system
|
|
1
|
+
import { get } from '@/api/request'
|
|
2
|
+
const system = {
|
|
3
|
+
/// 获取系统描述
|
|
4
|
+
|
|
5
|
+
getSystemDescription() {
|
|
6
|
+
return get('server/getSystemDescription')
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
/// 获取系统更新记录
|
|
10
|
+
|
|
11
|
+
projectUpdateRecord() {
|
|
12
|
+
return get('server/projectUpdateRecord')
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
export default system
|
package/src/api/request.js
CHANGED
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
import { createAlova } from 'alova'
|
|
2
|
-
import VueHook from 'alova/vue'
|
|
3
|
-
import adapterFetch from 'alova/fetch'
|
|
4
|
-
import { message } from 'ant-design-vue'
|
|
5
|
-
import { useUserStore } from '@/stores/user'
|
|
6
|
-
import router from '../router'
|
|
7
|
-
/**
|
|
8
|
-
* 创建 alova 实例
|
|
9
|
-
* 用于处理 HTTP 请求,包含请求拦截、响应拦截等配置
|
|
10
|
-
*/
|
|
11
|
-
const serviceAlova = createAlova({
|
|
12
|
-
// 基础URL,从环境变量中获取
|
|
13
|
-
baseURL: import.meta.env.VITE_BASE_API,
|
|
14
|
-
// 请求超时时间(毫秒)
|
|
15
|
-
timeout: 20000,
|
|
16
|
-
// 缓存时间设置为0,即不缓存
|
|
17
|
-
cacheFor: 0,
|
|
18
|
-
// 使用 Vue Hook 管理状态
|
|
19
|
-
statesHook: VueHook,
|
|
20
|
-
// 请求前拦截器
|
|
21
|
-
beforeRequest(method) {
|
|
22
|
-
const userStore = useUserStore()
|
|
23
|
-
// 如果存在 token,则添加到请求头中
|
|
24
|
-
if (userStore.token) {
|
|
25
|
-
method.config.headers.authorization = 'Bearer ' + userStore.token
|
|
26
|
-
} else {
|
|
27
|
-
// 如果没有 token 且当前不在登录页,则跳转到登录页
|
|
28
|
-
if (router.currentRoute.value.path !== '/login') {
|
|
29
|
-
router.push('/login')
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
// 使用 fetch 作为请求适配器
|
|
34
|
-
requestAdapter: adapterFetch(),
|
|
35
|
-
// 响应拦截器配置
|
|
36
|
-
responded: {
|
|
37
|
-
/**
|
|
38
|
-
* 请求成功拦截器
|
|
39
|
-
* @param {Response} response - 原始响应对象
|
|
40
|
-
* @param {Method} method - 当前请求的 method 实例
|
|
41
|
-
* @returns {Promise} 处理后的结果
|
|
42
|
-
*/
|
|
43
|
-
onSuccess: async (response, method) => {
|
|
44
|
-
message.destroy() // 请求成功后销毁加载提示
|
|
45
|
-
// 检查是否为文件流响应
|
|
46
|
-
const contentType = response.headers.get('content-type')
|
|
47
|
-
const isFileResponse =
|
|
48
|
-
contentType &&
|
|
49
|
-
(contentType.includes('application/octet-stream') ||
|
|
50
|
-
contentType.includes('text/plain') ||
|
|
51
|
-
contentType.includes('application/pdf') ||
|
|
52
|
-
contentType.includes(
|
|
53
|
-
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
54
|
-
)) // 添加其他需要的文件类型
|
|
55
|
-
|
|
56
|
-
if (isFileResponse) {
|
|
57
|
-
// 处理文件流响应
|
|
58
|
-
const blob = await response.blob()
|
|
59
|
-
|
|
60
|
-
// 尝试获取文件名
|
|
61
|
-
let fileName = ''
|
|
62
|
-
|
|
63
|
-
// 1. 尝试从 Content-Disposition 获取
|
|
64
|
-
const contentDisposition = response.headers.get('content-disposition')
|
|
65
|
-
|
|
66
|
-
if (contentDisposition) {
|
|
67
|
-
// 匹配标准格式: attachment; filename="encodedFileName"
|
|
68
|
-
const match = contentDisposition.match(
|
|
69
|
-
/filename\*?=['"]?(?:UTF-\d['"]*)?([^;]+)/i,
|
|
70
|
-
)
|
|
71
|
-
if (match && match[1]) {
|
|
72
|
-
// 解码 URL 编码的文件名
|
|
73
|
-
fileName = decodeURIComponent(match[1].trim())
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return { blob, fileName }
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (response.status == 200) {
|
|
81
|
-
const json = await response.json()
|
|
82
|
-
switch (json.code) {
|
|
83
|
-
case 200:
|
|
84
|
-
return Promise.resolve(json)
|
|
85
|
-
case 201:
|
|
86
|
-
message.error(json.msg)
|
|
87
|
-
return Promise.reject(json)
|
|
88
|
-
case 202:
|
|
89
|
-
message.error(json.errors)
|
|
90
|
-
return Promise.reject(json)
|
|
91
|
-
case 401:
|
|
92
|
-
const userStore = useUserStore()
|
|
93
|
-
userStore.token = '' // 清空 token
|
|
94
|
-
message.error({
|
|
95
|
-
content: json.errors + ',请重新登录',
|
|
96
|
-
duration: 1,
|
|
97
|
-
onClose: () => {
|
|
98
|
-
router.push('/login')
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
return Promise.reject(json)
|
|
102
|
-
case 500:
|
|
103
|
-
message.error(json.errors)
|
|
104
|
-
return Promise.reject(json)
|
|
105
|
-
}
|
|
106
|
-
// 解析的响应数据将传给method实例的transformData钩子函数,这些函数将在后续讲解
|
|
107
|
-
return Promise.reject(json)
|
|
108
|
-
} else {
|
|
109
|
-
message.error(response.status + ':请求地址无效')
|
|
110
|
-
return Promise.reject(response.status)
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
/**
|
|
114
|
-
* 请求失败拦截器
|
|
115
|
-
* @param {Error} error - 错误对象
|
|
116
|
-
* @param {Method} method - 当前请求的 method 实例
|
|
117
|
-
* @returns {Promise} 处理后的结果
|
|
118
|
-
*/
|
|
119
|
-
onError: (error, method) => {
|
|
120
|
-
message.destroy() // 请求完成后销毁加载提示
|
|
121
|
-
message.error(error.message)
|
|
122
|
-
return Promise.reject(error.message)
|
|
123
|
-
},
|
|
124
|
-
/**
|
|
125
|
-
* 请求完成拦截器(无论成功或失败都会执行)
|
|
126
|
-
* 用于处理请求完成后的统一逻辑
|
|
127
|
-
*/
|
|
128
|
-
onComplete: () => {
|
|
129
|
-
// 处理请求完成逻辑
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 封装 GET 请求
|
|
136
|
-
* @param {string} url - 请求地址
|
|
137
|
-
* @param {Object} params - 请求参数
|
|
138
|
-
* @returns {Promise} 请求结果的 Promise
|
|
139
|
-
*/
|
|
140
|
-
export const get = (url, params) => {
|
|
141
|
-
return new Promise((resolve, reject) => {
|
|
142
|
-
serviceAlova
|
|
143
|
-
.Get(url, { params })
|
|
144
|
-
.then(result => {
|
|
145
|
-
resolve(result)
|
|
146
|
-
}) // 请求成功,解析数据
|
|
147
|
-
.catch(error => {
|
|
148
|
-
reject(error) // 请求失败,抛出错误
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* 封装 POST 请求
|
|
155
|
-
* @param {string} url - 请求地址
|
|
156
|
-
* @param {Object} data - 请求数据
|
|
157
|
-
* @returns {Promise} 请求结果的 Promise
|
|
158
|
-
*/
|
|
159
|
-
export const post = (url, data = {}) => {
|
|
160
|
-
return new Promise((resolve, reject) => {
|
|
161
|
-
serviceAlova
|
|
162
|
-
.Post(url, data)
|
|
163
|
-
.then(result => {
|
|
164
|
-
resolve(result)
|
|
165
|
-
}) // 请求成功,解析数据
|
|
166
|
-
.catch(error => {
|
|
167
|
-
reject(error) // 请求失败,抛出错误
|
|
168
|
-
})
|
|
169
|
-
})
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* 封装 GET 方式的文件下载方法
|
|
174
|
-
* @param {string} url - 下载地址
|
|
175
|
-
* @param {Object} params - 请求参数
|
|
176
|
-
* @returns {Promise} 包含文件数据的 Promise
|
|
177
|
-
*/
|
|
178
|
-
export const downloadFileGet = (url, params = {}) => {
|
|
179
|
-
return new Promise((resolve, reject) => {
|
|
180
|
-
serviceAlova
|
|
181
|
-
.Get(url, {
|
|
182
|
-
params,
|
|
183
|
-
config: {
|
|
184
|
-
responseType: 'blob', // 关键:指定响应类型为 blob
|
|
185
|
-
headers: {
|
|
186
|
-
Accept: 'application/octet-stream', // 明确表示接受文件流
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
})
|
|
190
|
-
.then(result => {
|
|
191
|
-
// 这里会收到拦截器返回的 { blob, fileName }
|
|
192
|
-
resolve(result)
|
|
193
|
-
})
|
|
194
|
-
.catch(error => {
|
|
195
|
-
reject(error)
|
|
196
|
-
})
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* 封装 POST 方式的文件下载方法
|
|
202
|
-
* @param {string} url - 下载地址
|
|
203
|
-
* @param {Object} data - 请求数据
|
|
204
|
-
* @returns {Promise} 包含文件数据的 Promise
|
|
205
|
-
*/
|
|
206
|
-
export const downloadFilePost = (url, data = {}) => {
|
|
207
|
-
return new Promise((resolve, reject) => {
|
|
208
|
-
serviceAlova
|
|
209
|
-
.Post(url, data, {
|
|
210
|
-
config: {
|
|
211
|
-
responseType: 'blob', // 关键:指定响应类型为 blob
|
|
212
|
-
headers: {
|
|
213
|
-
Accept: 'application/octet-stream', // 明确表示接受文件流
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
})
|
|
217
|
-
.then(result => {
|
|
218
|
-
// 这里会收到拦截器返回的 { blob, fileName }
|
|
219
|
-
resolve(result)
|
|
220
|
-
})
|
|
221
|
-
.catch(error => {
|
|
222
|
-
reject(error)
|
|
223
|
-
})
|
|
224
|
-
})
|
|
225
|
-
}
|
|
1
|
+
import { createAlova } from 'alova'
|
|
2
|
+
import VueHook from 'alova/vue'
|
|
3
|
+
import adapterFetch from 'alova/fetch'
|
|
4
|
+
import { message } from 'ant-design-vue'
|
|
5
|
+
import { useUserStore } from '@/stores/user'
|
|
6
|
+
import router from '../router'
|
|
7
|
+
/**
|
|
8
|
+
* 创建 alova 实例
|
|
9
|
+
* 用于处理 HTTP 请求,包含请求拦截、响应拦截等配置
|
|
10
|
+
*/
|
|
11
|
+
const serviceAlova = createAlova({
|
|
12
|
+
// 基础URL,从环境变量中获取
|
|
13
|
+
baseURL: import.meta.env.VITE_BASE_API,
|
|
14
|
+
// 请求超时时间(毫秒)
|
|
15
|
+
timeout: 20000,
|
|
16
|
+
// 缓存时间设置为0,即不缓存
|
|
17
|
+
cacheFor: 0,
|
|
18
|
+
// 使用 Vue Hook 管理状态
|
|
19
|
+
statesHook: VueHook,
|
|
20
|
+
// 请求前拦截器
|
|
21
|
+
beforeRequest(method) {
|
|
22
|
+
const userStore = useUserStore()
|
|
23
|
+
// 如果存在 token,则添加到请求头中
|
|
24
|
+
if (userStore.token) {
|
|
25
|
+
method.config.headers.authorization = 'Bearer ' + userStore.token
|
|
26
|
+
} else {
|
|
27
|
+
// 如果没有 token 且当前不在登录页,则跳转到登录页
|
|
28
|
+
if (router.currentRoute.value.path !== '/login') {
|
|
29
|
+
router.push('/login')
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
// 使用 fetch 作为请求适配器
|
|
34
|
+
requestAdapter: adapterFetch(),
|
|
35
|
+
// 响应拦截器配置
|
|
36
|
+
responded: {
|
|
37
|
+
/**
|
|
38
|
+
* 请求成功拦截器
|
|
39
|
+
* @param {Response} response - 原始响应对象
|
|
40
|
+
* @param {Method} method - 当前请求的 method 实例
|
|
41
|
+
* @returns {Promise} 处理后的结果
|
|
42
|
+
*/
|
|
43
|
+
onSuccess: async (response, method) => {
|
|
44
|
+
message.destroy() // 请求成功后销毁加载提示
|
|
45
|
+
// 检查是否为文件流响应
|
|
46
|
+
const contentType = response.headers.get('content-type')
|
|
47
|
+
const isFileResponse =
|
|
48
|
+
contentType &&
|
|
49
|
+
(contentType.includes('application/octet-stream') ||
|
|
50
|
+
contentType.includes('text/plain') ||
|
|
51
|
+
contentType.includes('application/pdf') ||
|
|
52
|
+
contentType.includes(
|
|
53
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
54
|
+
)) // 添加其他需要的文件类型
|
|
55
|
+
|
|
56
|
+
if (isFileResponse) {
|
|
57
|
+
// 处理文件流响应
|
|
58
|
+
const blob = await response.blob()
|
|
59
|
+
|
|
60
|
+
// 尝试获取文件名
|
|
61
|
+
let fileName = ''
|
|
62
|
+
|
|
63
|
+
// 1. 尝试从 Content-Disposition 获取
|
|
64
|
+
const contentDisposition = response.headers.get('content-disposition')
|
|
65
|
+
|
|
66
|
+
if (contentDisposition) {
|
|
67
|
+
// 匹配标准格式: attachment; filename="encodedFileName"
|
|
68
|
+
const match = contentDisposition.match(
|
|
69
|
+
/filename\*?=['"]?(?:UTF-\d['"]*)?([^;]+)/i,
|
|
70
|
+
)
|
|
71
|
+
if (match && match[1]) {
|
|
72
|
+
// 解码 URL 编码的文件名
|
|
73
|
+
fileName = decodeURIComponent(match[1].trim())
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return { blob, fileName }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (response.status == 200) {
|
|
81
|
+
const json = await response.json()
|
|
82
|
+
switch (json.code) {
|
|
83
|
+
case 200:
|
|
84
|
+
return Promise.resolve(json)
|
|
85
|
+
case 201:
|
|
86
|
+
message.error(json.msg)
|
|
87
|
+
return Promise.reject(json)
|
|
88
|
+
case 202:
|
|
89
|
+
message.error(json.errors)
|
|
90
|
+
return Promise.reject(json)
|
|
91
|
+
case 401:
|
|
92
|
+
const userStore = useUserStore()
|
|
93
|
+
userStore.token = '' // 清空 token
|
|
94
|
+
message.error({
|
|
95
|
+
content: json.errors + ',请重新登录',
|
|
96
|
+
duration: 1,
|
|
97
|
+
onClose: () => {
|
|
98
|
+
router.push('/login')
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
return Promise.reject(json)
|
|
102
|
+
case 500:
|
|
103
|
+
message.error(json.errors)
|
|
104
|
+
return Promise.reject(json)
|
|
105
|
+
}
|
|
106
|
+
// 解析的响应数据将传给method实例的transformData钩子函数,这些函数将在后续讲解
|
|
107
|
+
return Promise.reject(json)
|
|
108
|
+
} else {
|
|
109
|
+
message.error(response.status + ':请求地址无效')
|
|
110
|
+
return Promise.reject(response.status)
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
/**
|
|
114
|
+
* 请求失败拦截器
|
|
115
|
+
* @param {Error} error - 错误对象
|
|
116
|
+
* @param {Method} method - 当前请求的 method 实例
|
|
117
|
+
* @returns {Promise} 处理后的结果
|
|
118
|
+
*/
|
|
119
|
+
onError: (error, method) => {
|
|
120
|
+
message.destroy() // 请求完成后销毁加载提示
|
|
121
|
+
message.error(error.message)
|
|
122
|
+
return Promise.reject(error.message)
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* 请求完成拦截器(无论成功或失败都会执行)
|
|
126
|
+
* 用于处理请求完成后的统一逻辑
|
|
127
|
+
*/
|
|
128
|
+
onComplete: () => {
|
|
129
|
+
// 处理请求完成逻辑
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 封装 GET 请求
|
|
136
|
+
* @param {string} url - 请求地址
|
|
137
|
+
* @param {Object} params - 请求参数
|
|
138
|
+
* @returns {Promise} 请求结果的 Promise
|
|
139
|
+
*/
|
|
140
|
+
export const get = (url, params) => {
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
serviceAlova
|
|
143
|
+
.Get(url, { params })
|
|
144
|
+
.then(result => {
|
|
145
|
+
resolve(result)
|
|
146
|
+
}) // 请求成功,解析数据
|
|
147
|
+
.catch(error => {
|
|
148
|
+
reject(error) // 请求失败,抛出错误
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 封装 POST 请求
|
|
155
|
+
* @param {string} url - 请求地址
|
|
156
|
+
* @param {Object} data - 请求数据
|
|
157
|
+
* @returns {Promise} 请求结果的 Promise
|
|
158
|
+
*/
|
|
159
|
+
export const post = (url, data = {}) => {
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
serviceAlova
|
|
162
|
+
.Post(url, data)
|
|
163
|
+
.then(result => {
|
|
164
|
+
resolve(result)
|
|
165
|
+
}) // 请求成功,解析数据
|
|
166
|
+
.catch(error => {
|
|
167
|
+
reject(error) // 请求失败,抛出错误
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 封装 GET 方式的文件下载方法
|
|
174
|
+
* @param {string} url - 下载地址
|
|
175
|
+
* @param {Object} params - 请求参数
|
|
176
|
+
* @returns {Promise} 包含文件数据的 Promise
|
|
177
|
+
*/
|
|
178
|
+
export const downloadFileGet = (url, params = {}) => {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
serviceAlova
|
|
181
|
+
.Get(url, {
|
|
182
|
+
params,
|
|
183
|
+
config: {
|
|
184
|
+
responseType: 'blob', // 关键:指定响应类型为 blob
|
|
185
|
+
headers: {
|
|
186
|
+
Accept: 'application/octet-stream', // 明确表示接受文件流
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
})
|
|
190
|
+
.then(result => {
|
|
191
|
+
// 这里会收到拦截器返回的 { blob, fileName }
|
|
192
|
+
resolve(result)
|
|
193
|
+
})
|
|
194
|
+
.catch(error => {
|
|
195
|
+
reject(error)
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 封装 POST 方式的文件下载方法
|
|
202
|
+
* @param {string} url - 下载地址
|
|
203
|
+
* @param {Object} data - 请求数据
|
|
204
|
+
* @returns {Promise} 包含文件数据的 Promise
|
|
205
|
+
*/
|
|
206
|
+
export const downloadFilePost = (url, data = {}) => {
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
serviceAlova
|
|
209
|
+
.Post(url, data, {
|
|
210
|
+
config: {
|
|
211
|
+
responseType: 'blob', // 关键:指定响应类型为 blob
|
|
212
|
+
headers: {
|
|
213
|
+
Accept: 'application/octet-stream', // 明确表示接受文件流
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
})
|
|
217
|
+
.then(result => {
|
|
218
|
+
// 这里会收到拦截器返回的 { blob, fileName }
|
|
219
|
+
resolve(result)
|
|
220
|
+
})
|
|
221
|
+
.catch(error => {
|
|
222
|
+
reject(error)
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
}
|