|
|
@@ -126,7 +126,88 @@ let error = error => {
|
|
|
|
|
|
// 响应拦截器
|
|
|
service.interceptors.response.use(success,error)
|
|
|
+export function exportFile(
|
|
|
+ url,
|
|
|
+ request,
|
|
|
+ method,
|
|
|
+ onDownloadProgressCallBack,
|
|
|
+ exceptionCallBack
|
|
|
+) {
|
|
|
+ const headers = {
|
|
|
+ //"content-type": "application/vnd.ms-excel",
|
|
|
+ };
|
|
|
|
|
|
+ service
|
|
|
+ .request({
|
|
|
+ url,
|
|
|
+ method,
|
|
|
+ data: request,
|
|
|
+ responseType: "blob",
|
|
|
+ headers,
|
|
|
+ onDownloadProgress: onDownloadProgressCallBack,
|
|
|
+ })
|
|
|
+ .then((response) => {
|
|
|
+ if (loading) loading.close();
|
|
|
+ const data = response.data;
|
|
|
+
|
|
|
+ /* if (!data) {
|
|
|
+ Message.warning("文件下载失败");
|
|
|
+ exceptionCallBack("文件下载失败");
|
|
|
+ return;
|
|
|
+ } else if (data.type === "application/json") {
|
|
|
+ data.text().then((t) => {
|
|
|
+ let r = JSON.parse(t);
|
|
|
+ if (r.result === "000001") {
|
|
|
+ if(exceptionCallBack)
|
|
|
+ {
|
|
|
+ exceptionCallBack(r.error);
|
|
|
+ }else{
|
|
|
+ Message.warning(r.error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }*/
|
|
|
+ debugger
|
|
|
+ /* let cd = response.headers["content-disposition"];
|
|
|
+ let fileName = "未知";
|
|
|
+ if (cd) {
|
|
|
+ fileName = decodeURIComponent(
|
|
|
+ response.headers["content-disposition"].split("=")[1]
|
|
|
+ );
|
|
|
+ }*/
|
|
|
+ let fileName="1231231231.zip";
|
|
|
+ if (typeof window.navigator.msSaveBlob !== "undefined") {
|
|
|
+ window.navigator.msSaveBlob(
|
|
|
+ response,
|
|
|
+ fileName
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ const url = window.URL.createObjectURL(
|
|
|
+ response,
|
|
|
+ );
|
|
|
+ const link = document.createElement("a");
|
|
|
+ link.style.display = "none";
|
|
|
+ link.href = url;
|
|
|
+ link.setAttribute("download", fileName);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link); // 下载完成移除元素
|
|
|
+ window.URL.revokeObjectURL(url); // 释放掉blob对象
|
|
|
+ if(fileName=="未知") {
|
|
|
+ exceptionCallBack("后端接口返回异常,文件下载失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(err) {
|
|
|
+ if (loading) loading.close();
|
|
|
+ console.log("exportFile catch",err);
|
|
|
+ if(exceptionCallBack)
|
|
|
+ {
|
|
|
+ exceptionCallBack(err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
// 通用下载方法
|
|
|
export function download(url, params, filename, config) {
|
|
|
downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
|