|
@@ -153,37 +153,25 @@ service.interceptors.response.use(res => {
|
|
|
}
|
|
|
)
|
|
|
// 通用下载方法
|
|
|
-export function download(url, params, filename, config) {
|
|
|
- downloadLoadingInstance = ElLoading.service({
|
|
|
- text: "正在下载数据,请稍候",
|
|
|
- background: "rgba(0, 0, 0, 0.7)",
|
|
|
- })
|
|
|
- return service.post(url, params, {
|
|
|
- transformRequest: [(params) => {
|
|
|
- return tansParams(params)
|
|
|
- }],
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- responseType: 'blob',
|
|
|
- ...config
|
|
|
- }).then(async (data) => {
|
|
|
- const isLogin = await blobValidate(data);
|
|
|
- if (isLogin) {
|
|
|
- const blob = new Blob([data])
|
|
|
- saveAs(blob, filename)
|
|
|
- } else {
|
|
|
- const resText = await data.text();
|
|
|
- const rspObj = JSON.parse(resText);
|
|
|
- const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
|
|
- ElMessage.error(errMsg);
|
|
|
+export function download(fileUrl, fileName) {
|
|
|
+ let xhr = new XMLHttpRequest();
|
|
|
+ //域名是华为云的
|
|
|
+ xhr.open("GET", `${fileUrl}`, true);
|
|
|
+ xhr.responseType = "blob";
|
|
|
+ xhr.send();
|
|
|
+ xhr.onreadystatechange = function () {
|
|
|
+ if (xhr.readyState === 4 && xhr.status === 200) {
|
|
|
+ let url = window.URL.createObjectURL(xhr.response);
|
|
|
+ const a = document.createElement("a");
|
|
|
+ a.href = url;
|
|
|
+ a.download = fileName; // 下载后文件名
|
|
|
+ a.style.display = "none";
|
|
|
+ document.body.appendChild(a);
|
|
|
+ a.click(); // 点击下载
|
|
|
+ window.URL.revokeObjectURL(a.href);
|
|
|
+ document.body.removeChild(a); // 下载完成移除元素
|
|
|
}
|
|
|
- downloadLoadingInstance.close();
|
|
|
- }).catch((r) => {
|
|
|
- console.error(r)
|
|
|
- ElMessage.error('下载文件出现错误,请联系管理员!')
|
|
|
- downloadLoadingInstance.close();
|
|
|
- })
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
|