Blame view

HHECS.Web/src/api/user.js 2.06 KB
胡菁 authored
1
import request from '@/utils/request'
陈嘉新 authored
2
import { getRefreshToken, getToken } from "@/utils/auth";
胡菁 authored
3
陈嘉新 authored
4
5
6
7
8
9
10
11
12
13
14
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' }
    })
胡菁 authored
15
16
}
陈嘉新 authored
17
18
export function logout () {
    return Promise.resolve()
胡菁 authored
19
20
21
}

// 权限获取
陈嘉新 authored
22
23
24
25
26
27
export function getLicense () {
    return request({
        url: '/api/System/GetLicense',
        method: 'get'
        // data,
    })
胡菁 authored
28
29
30
}

// 权限导入
陈嘉新 authored
31
32
33
34
35
36
export function importLicense (data) {
    return request({
        url: '/api/System/ImportLicense?content=' + encodeURIComponent(data),
        method: 'get'
        // data,
    })
胡菁 authored
37
}
陈嘉新 authored
38
39
40
41
42
43
44
45
46
// 权限导入
export function getExport (data) {
    return request({
        url: '/api/MTask/GetMTasks',
        method: 'post',
        data
    })
}
王硕 authored
47
陈嘉新 authored
48
function downloadFile (url, params, text) {
王硕 authored
49
50
51
52
    const fullUrl = process.env.NODE_ENV === "development"
        ? window.appConfig.baseUrlOffLine + url
        : window.appConfig.baseUrlOnLine + url;
    fetch(fullUrl, {
陈嘉新 authored
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
78
79
80
81
        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;