mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	feat: vue3 axios add download function
This commit is contained in:
		| @@ -9,5 +9,5 @@ export const getApiAccessLogPageApi = (params) => { | ||||
|  | ||||
| // 导出API 访问日志 | ||||
| export const exportApiAccessLogApi = (params) => { | ||||
|   return request.get({ url: '/infra/api-access-log/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/infra/api-access-log/export-excel', params }) | ||||
| } | ||||
|   | ||||
| @@ -16,5 +16,8 @@ export const updateApiErrorLogPageApi = (id: number, processStatus: number) => { | ||||
|  | ||||
| // 导出API 访问日志 | ||||
| export const exportApiErrorLogApi = (params) => { | ||||
|   return request.get({ url: '/infra/api-error-log/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ | ||||
|     url: '/infra/api-error-log/export-excel', | ||||
|     params | ||||
|   }) | ||||
| } | ||||
|   | ||||
| @@ -40,7 +40,7 @@ export const previewCodegenApi = (id: number) => { | ||||
|  | ||||
| // 下载生成代码 | ||||
| export const downloadCodegenApi = (id: number) => { | ||||
|   return request.get({ url: '/infra/codegen/download?tableId=' + id, responseType: 'blob' }) | ||||
|   return request.download({ url: '/infra/codegen/download?tableId=' + id }) | ||||
| } | ||||
|  | ||||
| // 获得表定义 | ||||
|   | ||||
| @@ -35,5 +35,5 @@ export const deleteConfigApi = (id: number) => { | ||||
|  | ||||
| // 导出参数 | ||||
| export const exportConfigApi = (params) => { | ||||
|   return request.get({ url: '/infra/config/export', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/infra/config/export', params }) | ||||
| } | ||||
|   | ||||
| @@ -4,15 +4,15 @@ const request = useAxios() | ||||
|  | ||||
| // 导出Html | ||||
| export const exportHtmlApi = () => { | ||||
|   return request.get({ url: '/infra/db-doc/export-html', responseType: 'blob' }) | ||||
|   return request.download({ url: '/infra/db-doc/export-html' }) | ||||
| } | ||||
|  | ||||
| // 导出Word | ||||
| export const exportWordApi = () => { | ||||
|   return request.get({ url: '/infra/db-doc/export-word', responseType: 'blob' }) | ||||
|   return request.download({ url: '/infra/db-doc/export-word' }) | ||||
| } | ||||
|  | ||||
| // 导出Markdown | ||||
| export const exportMarkdownApi = () => { | ||||
|   return request.get({ url: '/infra/db-doc/export-markdown', responseType: 'blob' }) | ||||
|   return request.download({ url: '/infra/db-doc/export-markdown' }) | ||||
| } | ||||
|   | ||||
| @@ -30,7 +30,7 @@ export const deleteJobApi = (id: number) => { | ||||
|  | ||||
| // 导出定时任务调度 | ||||
| export const exportJobApi = (params) => { | ||||
|   return request.get({ url: '/infra/job/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/infra/job/export-excel', params }) | ||||
| } | ||||
|  | ||||
| // 任务状态修改 | ||||
|   | ||||
| @@ -14,9 +14,8 @@ export const getJobLogApi = (id: number) => { | ||||
|  | ||||
| // 导出定时任务日志 | ||||
| export const exportJobLogApi = (params) => { | ||||
|   return request.get({ | ||||
|   return request.download({ | ||||
|     url: '/infra/job-log/export-excel', | ||||
|     params, | ||||
|     responseType: 'blob' | ||||
|     params | ||||
|   }) | ||||
| } | ||||
|   | ||||
| @@ -39,7 +39,7 @@ export const deleteAppApi = (id: number) => { | ||||
|  | ||||
| // 导出支付应用 | ||||
| export const exportAppApi = (params) => { | ||||
|   return request.get({ url: '/pay/app/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/pay/app/export-excel', params }) | ||||
| } | ||||
|  | ||||
| // 根据商ID称搜索应用列表 | ||||
|   | ||||
| @@ -35,5 +35,5 @@ export const deleteChannelApi = (id: number) => { | ||||
|  | ||||
| // 导出支付渠道 | ||||
| export const exportChannelApi = (params) => { | ||||
|   return request.get({ url: '/pay/channel/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/pay/channel/export-excel', params }) | ||||
| } | ||||
|   | ||||
| @@ -40,7 +40,7 @@ export const deleteMerchantApi = (id: number) => { | ||||
|  | ||||
| // 导出支付商户 | ||||
| export const exportMerchantApi = (params) => { | ||||
|   return request.get({ url: '/pay/merchant/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/pay/merchant/export-excel', params }) | ||||
| } | ||||
| // 支付商户状态修改 | ||||
| export const changeMerchantStatusApi = (id: number, status: number) => { | ||||
|   | ||||
| @@ -30,5 +30,5 @@ export const deleteOrderApi = async (id: number) => { | ||||
|  | ||||
| // 导出支付订单 | ||||
| export const exportOrderApi = async (params) => { | ||||
|   return await request.get({ url: '/pay/order/export-excel', params, responseType: 'blob' }) | ||||
|   return await request.download({ url: '/pay/order/export-excel', params }) | ||||
| } | ||||
|   | ||||
| @@ -30,5 +30,5 @@ export const deleteRefundApi = (id: number) => { | ||||
|  | ||||
| // 导出退款订单 | ||||
| export const exportRefundApi = (params) => { | ||||
|   return request.get({ url: '/pay/refund/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/pay/refund/export-excel', params }) | ||||
| } | ||||
|   | ||||
| @@ -29,5 +29,5 @@ export const deleteErrorCodeApi = (id: number) => { | ||||
| } | ||||
| // 导出错误码 | ||||
| export const excelErrorCodeApi = (params) => { | ||||
|   return request.get({ url: '/system/error-code/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/system/error-code/export-excel', params }) | ||||
| } | ||||
|   | ||||
| @@ -8,5 +8,5 @@ export const getLoginLogPageApi = (params) => { | ||||
| } | ||||
| // 导出登录日志 | ||||
| export const exportLoginLogApi = (params) => { | ||||
|   return request.get({ url: '/system/login-log/export', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/system/login-log/export', params }) | ||||
| } | ||||
|   | ||||
| @@ -8,5 +8,5 @@ export const getOperateLogPageApi = (params) => { | ||||
| } | ||||
| // 导出操作日志 | ||||
| export const exportOperateLogApi = (params) => { | ||||
|   return request.get({ url: '/system/operate-log/export', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/system/operate-log/export', params }) | ||||
| } | ||||
|   | ||||
| @@ -34,5 +34,5 @@ export const deletePostApi = async (id: number) => { | ||||
|  | ||||
| // 导出岗位 | ||||
| export const exportPostApi = async (params) => { | ||||
|   return await request.get({ url: '/system/post/export', params, responseType: 'blob' }) | ||||
|   return await request.download({ url: '/system/post/export', params }) | ||||
| } | ||||
|   | ||||
| @@ -30,7 +30,7 @@ export const deleteSensitiveWordApi = (id: number) => { | ||||
|  | ||||
| // 导出敏感词 | ||||
| export const exportSensitiveWordApi = (params) => { | ||||
|   return request.get({ url: '/system/sensitive-word/export', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/system/sensitive-word/export-excel', params }) | ||||
| } | ||||
|  | ||||
| // 获取所有敏感词的标签数组 | ||||
|   | ||||
| @@ -9,5 +9,5 @@ export const getSmsLogPageApi = (params) => { | ||||
|  | ||||
| // 导出短信日志 | ||||
| export const exportSmsLogApi = (params) => { | ||||
|   return request.get({ url: '/system/sms-log/export', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/system/sms-log/export', params }) | ||||
| } | ||||
|   | ||||
| @@ -35,5 +35,8 @@ export const sendSmsApi = (data) => { | ||||
|  | ||||
| // 导出短信模板 | ||||
| export const exportPostApi = (params) => { | ||||
|   return request.get({ url: '/system/sms-template/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ | ||||
|     url: '/system/sms-template/export-excel', | ||||
|     params | ||||
|   }) | ||||
| } | ||||
|   | ||||
| @@ -30,5 +30,5 @@ export const deleteTenantApi = (id: number) => { | ||||
|  | ||||
| // 导出租户 | ||||
| export const exportTenantApi = (params) => { | ||||
|   return request.get({ url: '/system/tenant/export-excel', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/system/tenant/export-excel', params }) | ||||
| } | ||||
|   | ||||
| @@ -30,12 +30,12 @@ export const deleteUserApi = (id: number) => { | ||||
|  | ||||
| // 导出用户 | ||||
| export const exportUserApi = (params) => { | ||||
|   return request.get({ url: '/system/user/export', params, responseType: 'blob' }) | ||||
|   return request.download({ url: '/system/user/export', params }) | ||||
| } | ||||
|  | ||||
| // 下载用户导入模板 | ||||
| export const importUserTemplateApi = () => { | ||||
|   return request.get({ url: '/system/user/get-import-template', responseType: 'blob' }) | ||||
|   return request.download({ url: '/system/user/get-import-template' }) | ||||
| } | ||||
|  | ||||
| // 用户密码重置 | ||||
|   | ||||
| @@ -29,7 +29,8 @@ export const PATH_URL = base_url[import.meta.env.VITE_API_BASEPATH] | ||||
| // 创建axios实例 | ||||
| const service: AxiosInstance = axios.create({ | ||||
|   baseURL: BASE_URL + BASE_API, // api 的 base_url | ||||
|   timeout: config.request_timeout // 请求超时时间 | ||||
|   timeout: config.request_timeout, // 请求超时时间 | ||||
|   withCredentials: false // 禁用 Cookie 等信息 | ||||
| }) | ||||
|  | ||||
| // request拦截器 | ||||
|   | ||||
| @@ -37,12 +37,17 @@ async function putFn<T = any>(option: AxiosConfig): Promise<T> { | ||||
|   const res = await request({ method: 'PUT', ...option }) | ||||
|   return res.data | ||||
| } | ||||
| async function downloadFn<T = any>(option: AxiosConfig): Promise<T> { | ||||
|   const res = await request({ method: 'GET', responseType: 'blob', ...option }) | ||||
|   return res as unknown as Promise<T> | ||||
| } | ||||
|  | ||||
| export const useAxios = () => { | ||||
|   return { | ||||
|     get: getFn, | ||||
|     post: postFn, | ||||
|     delete: deleteFn, | ||||
|     put: putFn | ||||
|     put: putFn, | ||||
|     download: downloadFn | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| const download0 = (data: any, fileName: string, mineType: string) => { | ||||
| const download0 = (data: Blob, fileName: string, mineType: string) => { | ||||
|   // 创建 blob | ||||
|   const blob = new Blob([data], { type: mineType }) | ||||
|   // 创建 href 超链接,点击进行下载 | ||||
| @@ -14,23 +14,23 @@ const download0 = (data: any, fileName: string, mineType: string) => { | ||||
|  | ||||
| const download = { | ||||
|   // 下载 Excel 方法 | ||||
|   excel: (data: any, fileName: string) => { | ||||
|   excel: (data: Blob, fileName: string) => { | ||||
|     download0(data, fileName, 'application/vnd.ms-excel') | ||||
|   }, | ||||
|   // 下载 Word 方法 | ||||
|   word: (data: any, fileName: string) => { | ||||
|   word: (data: Blob, fileName: string) => { | ||||
|     download0(data, fileName, 'application/msword') | ||||
|   }, | ||||
|   // 下载 Zip 方法 | ||||
|   zip: (data: any, fileName: string) => { | ||||
|   zip: (data: Blob, fileName: string) => { | ||||
|     download0(data, fileName, 'application/zip') | ||||
|   }, | ||||
|   // 下载 Html 方法 | ||||
|   html: (data: any, fileName: string) => { | ||||
|   html: (data: Blob, fileName: string) => { | ||||
|     download0(data, fileName, 'text/html') | ||||
|   }, | ||||
|   // 下载 Markdown 方法 | ||||
|   markdown: (data: any, fileName: string) => { | ||||
|   markdown: (data: Blob, fileName: string) => { | ||||
|     download0(data, fileName, 'text/markdown') | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -45,8 +45,8 @@ const handleSynchDb = (row: CodegenTableVO) => { | ||||
|     }) | ||||
| } | ||||
| // 生成代码操作 | ||||
| const handleGenTable = (row: CodegenTableVO) => { | ||||
|   const res = CodegenApi.downloadCodegenApi(row.id) | ||||
| const handleGenTable = async (row: CodegenTableVO) => { | ||||
|   const res = await CodegenApi.downloadCodegenApi(row.id) | ||||
|   download.zip(res, 'codegen-' + row.className + '.zip') | ||||
| } | ||||
| // 删除操作 | ||||
|   | ||||
| @@ -113,7 +113,7 @@ getList() | ||||
|       @register="register" | ||||
|     > | ||||
|       <template #logo="{ row }"> | ||||
|         <el-image :src="row.logo" /> | ||||
|         <el-image :src="row.logo" :preview-src-list="[row.logo]" /> | ||||
|       </template> | ||||
|       <template #status="{ row }"> | ||||
|         <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" /> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 xingyu
					xingyu