From 27087cf06cc50699e2b89fff1060486cf0e84379 Mon Sep 17 00:00:00 2001 From: wjt <1797368093@qq.com> Date: 星期三, 14 八月 2024 17:11:39 +0800 Subject: [PATCH] 批量下载图片 --- src/utils/request.ts | 43 ++++++------------------------------------- 1 files changed, 6 insertions(+), 37 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 932820b..b399f84 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -136,7 +136,10 @@ export function download(url: string, params: any, filename: string, config: any) { downloadLoadingInstance = ElLoading.service({ text: "姝e湪涓嬭浇鏁版嵁锛岃绋嶅��", background: "rgba(0, 0, 0, 0.7)" }); return service - .post(url, params, { + .get(url, { + params, + responseType: "blob", + }, { transformRequest: [ (params) => { return tansParams(params); @@ -147,6 +150,7 @@ ...config, }) .then(async (data) => { + // console.log(data, 'data===') const isBlob = blobValidate(data); if (isBlob) { const blob = new Blob([data]); @@ -165,42 +169,7 @@ downloadLoadingInstance.close(); }); } -// 閫氱敤涓嬭浇鏂规硶 -export function downloadGet(url: string, params: any, filename: string, config: any, isSaveFile = false) { - downloadLoadingInstance = ElLoading.service({ text: "姝e湪涓嬭浇鏁版嵁锛岃绋嶅��", background: "rgba(0, 0, 0, 0.7)" }); - return service - .get(url, { params }, { - transformRequest: [ - (params) => { - return tansParams(params); - }, - ], - headers: { "Content-Type": "application/x-www-form-urlencoded" }, - responseType: "blob", - ...config, - }) - .then(async (data) => { - const isBlob = blobValidate(data); - if (isBlob && isSaveFile) { - const blob = new Blob([data]); - saveAs(blob, filename); - } else { - if(!isSaveFile) { - } else { - const resText = await data.text(); - const rspObj = JSON.parse(resText); - const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode["default"]; - ElMessage.error(errMsg); - } - } - downloadLoadingInstance.close(); - }) - .catch((r) => { - console.error(r); - ElMessage.error("涓嬭浇鏂囦欢鍑虹幇閿欒锛岃鑱旂郴绠$悊鍛橈紒"); - downloadLoadingInstance.close(); - }); -} + const request = <T = any>(_config: AxiosRequestConfig<any>): Promise<T> => { return service(_config) as Promise<T>; }; -- Gitblit v1.9.1