async groupMemberDataExportApi(data: any) {
let url = Serve + "接口地址?";
for (const k in data) {
url += `${k}=${data[k]}&`;
}
const name = "导出文件名.xlsx";
const code: number = await downLoadPromise(
url,
name,
LoginManager.getToken() || ""
);
return code;
},
private async groupMemberDataExport() {
try {
await API.groupMemberDataExportApi({
此处传参数
});
} catch (error) {
console.log(error, "on error");
this.$message.warning(error.message || "下载失败");
}
}
import { Serve } from "@/utils/serve";
export const Serve = process.env.VUE_APP_API_ROOT;
import { downLoadPromise } from "@/utils/down-load";
export function downLoadPromise(url: string, name: string, token?: string) {
const promise = new Promise<number>(function(resolve, reject) {
const x = new XMLHttpRequest();
x.open("GET", url, true);
if (token) {
x.setRequestHeader("Auth-Token", token);
}
x.responseType = "blob";
x.send();
x.onload = function() {
if (x.status === 200) {
const urlResponse = window.URL.createObjectURL(x.response);
const a = document.createElement("a");
a.href = urlResponse;
a.download = name;
a.click();
resolve(x.status);
} else {
reject(x.status);
}
};
});
return promise;
}
class LoginManager {
static MOCK_ACCOUNT = "yuruizhi@vchangyi.com";
static PASS_WORD = "hOJYZv";
static getLoginData: () => IUserInfo = function() {
try {
return JSON.parse(localStorage.getItem("USERINFO") || "");
} catch (error) {
return null;
}
};
static getToken: () => string | null = function() {
try {
return JSON.parse(localStorage.getItem("TOKEN") || "");
} catch (error) {
return null;
}
};