Commit b085f35dfeb7a83e213bb942a7ed99298f330fdc

Authored by xingyu
1 parent 611e11ae

feat: vue3 axios add download function

yudao-ui-admin-vue3/src/api/infra/apiAccessLog/index.ts
... ... @@ -9,5 +9,5 @@ export const getApiAccessLogPageApi = (params) => {
9 9  
10 10 // 导出API 访问日志
11 11 export const exportApiAccessLogApi = (params) => {
12   - return request.get({ url: '/infra/api-access-log/export-excel', params, responseType: 'blob' })
  12 + return request.download({ url: '/infra/api-access-log/export-excel', params })
13 13 }
... ...
yudao-ui-admin-vue3/src/api/infra/apiErrorLog/index.ts
... ... @@ -16,5 +16,8 @@ export const updateApiErrorLogPageApi = (id: number, processStatus: number) => {
16 16  
17 17 // 导出API 访问日志
18 18 export const exportApiErrorLogApi = (params) => {
19   - return request.get({ url: '/infra/api-error-log/export-excel', params, responseType: 'blob' })
  19 + return request.download({
  20 + url: '/infra/api-error-log/export-excel',
  21 + params
  22 + })
20 23 }
... ...
yudao-ui-admin-vue3/src/api/infra/codegen/index.ts
... ... @@ -40,7 +40,7 @@ export const previewCodegenApi = (id: number) => {
40 40  
41 41 // 下载生成代码
42 42 export const downloadCodegenApi = (id: number) => {
43   - return request.get({ url: '/infra/codegen/download?tableId=' + id, responseType: 'blob' })
  43 + return request.download({ url: '/infra/codegen/download?tableId=' + id })
44 44 }
45 45  
46 46 // 获得表定义
... ...
yudao-ui-admin-vue3/src/api/infra/config/index.ts
... ... @@ -35,5 +35,5 @@ export const deleteConfigApi = (id: number) => {
35 35  
36 36 // 导出参数
37 37 export const exportConfigApi = (params) => {
38   - return request.get({ url: '/infra/config/export', params, responseType: 'blob' })
  38 + return request.download({ url: '/infra/config/export', params })
39 39 }
... ...
yudao-ui-admin-vue3/src/api/infra/dbDoc/index.ts
... ... @@ -4,15 +4,15 @@ const request = useAxios()
4 4  
5 5 // 导出Html
6 6 export const exportHtmlApi = () => {
7   - return request.get({ url: '/infra/db-doc/export-html', responseType: 'blob' })
  7 + return request.download({ url: '/infra/db-doc/export-html' })
8 8 }
9 9  
10 10 // 导出Word
11 11 export const exportWordApi = () => {
12   - return request.get({ url: '/infra/db-doc/export-word', responseType: 'blob' })
  12 + return request.download({ url: '/infra/db-doc/export-word' })
13 13 }
14 14  
15 15 // 导出Markdown
16 16 export const exportMarkdownApi = () => {
17   - return request.get({ url: '/infra/db-doc/export-markdown', responseType: 'blob' })
  17 + return request.download({ url: '/infra/db-doc/export-markdown' })
18 18 }
... ...
yudao-ui-admin-vue3/src/api/infra/job/index.ts
... ... @@ -30,7 +30,7 @@ export const deleteJobApi = (id: number) => {
30 30  
31 31 // 导出定时任务调度
32 32 export const exportJobApi = (params) => {
33   - return request.get({ url: '/infra/job/export-excel', params, responseType: 'blob' })
  33 + return request.download({ url: '/infra/job/export-excel', params })
34 34 }
35 35  
36 36 // 任务状态修改
... ...
yudao-ui-admin-vue3/src/api/infra/jobLog/index.ts
... ... @@ -14,9 +14,8 @@ export const getJobLogApi = (id: number) => {
14 14  
15 15 // 导出定时任务日志
16 16 export const exportJobLogApi = (params) => {
17   - return request.get({
  17 + return request.download({
18 18 url: '/infra/job-log/export-excel',
19   - params,
20   - responseType: 'blob'
  19 + params
21 20 })
22 21 }
... ...
yudao-ui-admin-vue3/src/api/pay/app/index.ts
... ... @@ -39,7 +39,7 @@ export const deleteAppApi = (id: number) => {
39 39  
40 40 // 导出支付应用
41 41 export const exportAppApi = (params) => {
42   - return request.get({ url: '/pay/app/export-excel', params, responseType: 'blob' })
  42 + return request.download({ url: '/pay/app/export-excel', params })
43 43 }
44 44  
45 45 // 根据商ID称搜索应用列表
... ...
yudao-ui-admin-vue3/src/api/pay/channel/index.ts
... ... @@ -35,5 +35,5 @@ export const deleteChannelApi = (id: number) => {
35 35  
36 36 // 导出支付渠道
37 37 export const exportChannelApi = (params) => {
38   - return request.get({ url: '/pay/channel/export-excel', params, responseType: 'blob' })
  38 + return request.download({ url: '/pay/channel/export-excel', params })
39 39 }
... ...
yudao-ui-admin-vue3/src/api/pay/merchant/index.ts
... ... @@ -40,7 +40,7 @@ export const deleteMerchantApi = (id: number) => {
40 40  
41 41 // 导出支付商户
42 42 export const exportMerchantApi = (params) => {
43   - return request.get({ url: '/pay/merchant/export-excel', params, responseType: 'blob' })
  43 + return request.download({ url: '/pay/merchant/export-excel', params })
44 44 }
45 45 // 支付商户状态修改
46 46 export const changeMerchantStatusApi = (id: number, status: number) => {
... ...
yudao-ui-admin-vue3/src/api/pay/order/index.ts
... ... @@ -30,5 +30,5 @@ export const deleteOrderApi = async (id: number) => {
30 30  
31 31 // 导出支付订单
32 32 export const exportOrderApi = async (params) => {
33   - return await request.get({ url: '/pay/order/export-excel', params, responseType: 'blob' })
  33 + return await request.download({ url: '/pay/order/export-excel', params })
34 34 }
... ...
yudao-ui-admin-vue3/src/api/pay/refund/index.ts
... ... @@ -30,5 +30,5 @@ export const deleteRefundApi = (id: number) => {
30 30  
31 31 // 导出退款订单
32 32 export const exportRefundApi = (params) => {
33   - return request.get({ url: '/pay/refund/export-excel', params, responseType: 'blob' })
  33 + return request.download({ url: '/pay/refund/export-excel', params })
34 34 }
... ...
yudao-ui-admin-vue3/src/api/system/errorCode/index.ts
... ... @@ -29,5 +29,5 @@ export const deleteErrorCodeApi = (id: number) => {
29 29 }
30 30 // 导出错误码
31 31 export const excelErrorCodeApi = (params) => {
32   - return request.get({ url: '/system/error-code/export-excel', params, responseType: 'blob' })
  32 + return request.download({ url: '/system/error-code/export-excel', params })
33 33 }
... ...
yudao-ui-admin-vue3/src/api/system/loginLog/index.ts
... ... @@ -8,5 +8,5 @@ export const getLoginLogPageApi = (params) => {
8 8 }
9 9 // 导出登录日志
10 10 export const exportLoginLogApi = (params) => {
11   - return request.get({ url: '/system/login-log/export', params, responseType: 'blob' })
  11 + return request.download({ url: '/system/login-log/export', params })
12 12 }
... ...
yudao-ui-admin-vue3/src/api/system/operatelog/index.ts
... ... @@ -8,5 +8,5 @@ export const getOperateLogPageApi = (params) => {
8 8 }
9 9 // 导出操作日志
10 10 export const exportOperateLogApi = (params) => {
11   - return request.get({ url: '/system/operate-log/export', params, responseType: 'blob' })
  11 + return request.download({ url: '/system/operate-log/export', params })
12 12 }
... ...
yudao-ui-admin-vue3/src/api/system/post/index.ts
... ... @@ -34,5 +34,5 @@ export const deletePostApi = async (id: number) => {
34 34  
35 35 // 导出岗位
36 36 export const exportPostApi = async (params) => {
37   - return await request.get({ url: '/system/post/export', params, responseType: 'blob' })
  37 + return await request.download({ url: '/system/post/export', params })
38 38 }
... ...
yudao-ui-admin-vue3/src/api/system/sensitiveWord/index.ts
... ... @@ -30,7 +30,7 @@ export const deleteSensitiveWordApi = (id: number) => {
30 30  
31 31 // 导出敏感词
32 32 export const exportSensitiveWordApi = (params) => {
33   - return request.get({ url: '/system/sensitive-word/export', params, responseType: 'blob' })
  33 + return request.download({ url: '/system/sensitive-word/export-excel', params })
34 34 }
35 35  
36 36 // 获取所有敏感词的标签数组
... ...
yudao-ui-admin-vue3/src/api/system/sms/smsLog/index.ts
... ... @@ -9,5 +9,5 @@ export const getSmsLogPageApi = (params) => {
9 9  
10 10 // 导出短信日志
11 11 export const exportSmsLogApi = (params) => {
12   - return request.get({ url: '/system/sms-log/export', params, responseType: 'blob' })
  12 + return request.download({ url: '/system/sms-log/export', params })
13 13 }
... ...
yudao-ui-admin-vue3/src/api/system/sms/smsTemplate/index.ts
... ... @@ -35,5 +35,8 @@ export const sendSmsApi = (data) => {
35 35  
36 36 // 导出短信模板
37 37 export const exportPostApi = (params) => {
38   - return request.get({ url: '/system/sms-template/export-excel', params, responseType: 'blob' })
  38 + return request.download({
  39 + url: '/system/sms-template/export-excel',
  40 + params
  41 + })
39 42 }
... ...
yudao-ui-admin-vue3/src/api/system/tenant/index.ts
... ... @@ -30,5 +30,5 @@ export const deleteTenantApi = (id: number) => {
30 30  
31 31 // 导出租户
32 32 export const exportTenantApi = (params) => {
33   - return request.get({ url: '/system/tenant/export-excel', params, responseType: 'blob' })
  33 + return request.download({ url: '/system/tenant/export-excel', params })
34 34 }
... ...
yudao-ui-admin-vue3/src/api/system/user/index.ts
... ... @@ -30,12 +30,12 @@ export const deleteUserApi = (id: number) => {
30 30  
31 31 // 导出用户
32 32 export const exportUserApi = (params) => {
33   - return request.get({ url: '/system/user/export', params, responseType: 'blob' })
  33 + return request.download({ url: '/system/user/export', params })
34 34 }
35 35  
36 36 // 下载用户导入模板
37 37 export const importUserTemplateApi = () => {
38   - return request.get({ url: '/system/user/get-import-template', responseType: 'blob' })
  38 + return request.download({ url: '/system/user/get-import-template' })
39 39 }
40 40  
41 41 // 用户密码重置
... ...
yudao-ui-admin-vue3/src/config/axios/index.ts
... ... @@ -29,7 +29,8 @@ export const PATH_URL = base_url[import.meta.env.VITE_API_BASEPATH]
29 29 // 创建axios实例
30 30 const service: AxiosInstance = axios.create({
31 31 baseURL: BASE_URL + BASE_API, // api 的 base_url
32   - timeout: config.request_timeout // 请求超时时间
  32 + timeout: config.request_timeout, // 请求超时时间
  33 + withCredentials: false // 禁用 Cookie 等信息
33 34 })
34 35  
35 36 // request拦截器
... ...
yudao-ui-admin-vue3/src/hooks/web/useAxios.ts
... ... @@ -37,12 +37,17 @@ async function putFn<T = any>(option: AxiosConfig): Promise<T> {
37 37 const res = await request({ method: 'PUT', ...option })
38 38 return res.data
39 39 }
  40 +async function downloadFn<T = any>(option: AxiosConfig): Promise<T> {
  41 + const res = await request({ method: 'GET', responseType: 'blob', ...option })
  42 + return res as unknown as Promise<T>
  43 +}
40 44  
41 45 export const useAxios = () => {
42 46 return {
43 47 get: getFn,
44 48 post: postFn,
45 49 delete: deleteFn,
46   - put: putFn
  50 + put: putFn,
  51 + download: downloadFn
47 52 }
48 53 }
... ...
yudao-ui-admin-vue3/src/utils/download.ts
1   -const download0 = (data: any, fileName: string, mineType: string) => {
  1 +const download0 = (data: Blob, fileName: string, mineType: string) => {
2 2 // 创建 blob
3 3 const blob = new Blob([data], { type: mineType })
4 4 // 创建 href 超链接,点击进行下载
... ... @@ -14,23 +14,23 @@ const download0 = (data: any, fileName: string, mineType: string) =&gt; {
14 14  
15 15 const download = {
16 16 // 下载 Excel 方法
17   - excel: (data: any, fileName: string) => {
  17 + excel: (data: Blob, fileName: string) => {
18 18 download0(data, fileName, 'application/vnd.ms-excel')
19 19 },
20 20 // 下载 Word 方法
21   - word: (data: any, fileName: string) => {
  21 + word: (data: Blob, fileName: string) => {
22 22 download0(data, fileName, 'application/msword')
23 23 },
24 24 // 下载 Zip 方法
25   - zip: (data: any, fileName: string) => {
  25 + zip: (data: Blob, fileName: string) => {
26 26 download0(data, fileName, 'application/zip')
27 27 },
28 28 // 下载 Html 方法
29   - html: (data: any, fileName: string) => {
  29 + html: (data: Blob, fileName: string) => {
30 30 download0(data, fileName, 'text/html')
31 31 },
32 32 // 下载 Markdown 方法
33   - markdown: (data: any, fileName: string) => {
  33 + markdown: (data: Blob, fileName: string) => {
34 34 download0(data, fileName, 'text/markdown')
35 35 }
36 36 }
... ...
yudao-ui-admin-vue3/src/views/infra/codegen/index.vue
... ... @@ -45,8 +45,8 @@ const handleSynchDb = (row: CodegenTableVO) =&gt; {
45 45 })
46 46 }
47 47 // 生成代码操作
48   -const handleGenTable = (row: CodegenTableVO) => {
49   - const res = CodegenApi.downloadCodegenApi(row.id)
  48 +const handleGenTable = async (row: CodegenTableVO) => {
  49 + const res = await CodegenApi.downloadCodegenApi(row.id)
50 50 download.zip(res, 'codegen-' + row.className + '.zip')
51 51 }
52 52 // 删除操作
... ...
yudao-ui-admin-vue3/src/views/system/oauth2/client/index.vue
... ... @@ -113,7 +113,7 @@ getList()
113 113 @register="register"
114 114 >
115 115 <template #logo="{ row }">
116   - <el-image :src="row.logo" />
  116 + <el-image :src="row.logo" :preview-src-list="[row.logo]" />
117 117 </template>
118 118 <template #status="{ row }">
119 119 <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
... ...