| | |
| | | downloadLoadingInstance.close();
|
| | | });
|
| | | }
|
| | |
|
| | | // 通用下载方法
|
| | | export function downloadGet(url: string, params: any, filename: string, config: any, isSaveFile = false) {
|
| | | downloadLoadingInstance = ElLoading.service({ text: "正在下载数据,请稍候", 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>;
|
| | | };
|