user.js
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import request from '@/utils/request'
import { getRefreshToken, getToken } from "@/utils/auth";
export function login (data) {
return request({
url: '/api/User/Login',
method: 'post',
data: {
userCode: data.username,
password: data.password
}
}).then((response) => {
return { ...response, code: 'Success' }
})
}
export function logout () {
return Promise.resolve()
}
// 权限获取
export function getLicense () {
return request({
url: '/api/System/GetLicense',
method: 'get'
// data,
})
}
// 权限导入
export function importLicense (data) {
return request({
url: '/api/System/ImportLicense?content=' + encodeURIComponent(data),
method: 'get'
// data,
})
}
// 权限导入
export function getExport (data) {
return request({
url: '/api/MTask/GetMTasks',
method: 'post',
data
})
}
function downloadFile (url, params, text) {
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + getToken(),
"x-accesstoken": getRefreshToken(),
},
body: JSON.stringify(params),
})
.then((response) => {
if (!response.ok) throw new Error("网络响应不是 OK");
return response.blob();
})
.then((blob) => {
const downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = downloadUrl;
link.setAttribute("download", text); // 指定文件名
document.body.appendChild(link);
link.click();
link.remove();
})
.catch((error) => {
console.error("下载文件出错:", error);
});
}
// 导出函数以供其他文件使用
export default downloadFile;