zhanghua
2022-11-16 cc9ddf2ecaf3ad935374f49c842227f7eb15779d
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import myrequest from './request'
// 深拷贝
export function deepClone(obj) {
    let objClone = Array.isArray(obj) ? [] : {};
    if (obj && typeof obj === 'object' && obj != null) {
        for (let key in obj) {
            if (obj.hasOwnProperty(key)) {
                if (obj[key] && typeof obj[key] === 'object') {
                    objClone[key] = deepClone(obj[key]);
                } else {
                    objClone[key] = obj[key];
                }
            }
        }
    }
    return objClone;
}
// 计算限制时间
export function computeTime(time2) {
    const t1 = new Date();
    const t2 = new Date(time2);
    return filterTime(t2.getTime() - t1.getTime());
}
// 获取字典表
export async function getTypeList(level, code) {
    let arr;
    await myrequest({
        method: 'get',
        url: `sccg/dict/query_type?level=${level}&typeCode=${code}`
    })
        .then(res => {
            arr = res.data;
        })
    return arr;
}
// 获取字典表2
export async function getCodeList(code){
    let arr;
    await myrequest({
        method: 'get',
        url: `/sccg/dict/queryByCode?code=${code}`
    })
        .then(res => {
            arr = res.data;
        })
    return arr;
}
 
// data: 文件, contentDisposition:请求头中文件的名字
// 默认不用修改,直接将返回的res传入即可
export function downloadFile(res) {
    const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
    const fileName = res.contentDisposition.split('=')[1];
    if (window.navigator && window.navigator.msSaveBlob) {
        navigator.msSaveBlob(blob, fileName);
    } else {
        const link = document.createElement('a');
        link.style.display = 'none';
        link.href = URL.createObjectURL(blob);
        link.setAttribute('download', decodeURI(fileName));
        document.body.appendChild(link);
        link.click();
        URL.revokeObjectURL(link.href);
        document.body.removeChild(link);
    }
}
 
// 获取token
export function getToken() {
    const token = sessionStorage.getItem('token');
    const tokenHead = sessionStorage.getItem('tokenHead');
    if (token && tokenHead) {
        return tokenHead + token;
    }
}
// 获取年月日时分秒
export function getNowDate(time){
    const result = new Date(time);
    let yy = result.getFullYear(),
    mm = result.getMonth()+1,
    dd = result.getDate(),
    hh = result.getHours(),
    mi = result.getMinutes(),
    ss = result.getSeconds()
    return yy+'-'+ fillTime(mm)+'-'+fillTime(dd)+" "+fillTime(hh)+':'+fillTime(mi) + ':' + fillTime(ss);
}
function filterTime(time) {
    if (time < 0) {
        return '已逾期';
    }
    let dd = Math.floor(time / 24 / 60 / 60 / 1000),
        hh = Math.floor(time / 60 / 60 / 1000 - dd * 24),
        mi = Math.floor(time / 60 / 1000 - dd * 24 * 60 - hh * 60);
    return addDay(fillTime(dd)) + addHour(fillTime(hh)) + addMin(fillTime(mi));
}
function fillTime(num) {
    if (num < 10) {
        return '0' + num;
    }
    return num;
}
function addDay(str) {
    str = parseFloat(str);
    if (str < 0) {
        return;
    }
    return str + '天'
}
function addHour(str) {
    str = parseFloat(str);
    if (str < 0) {
        return;
    }
    return str + '小时'
}
function addMin(str) {
    str = parseFloat(str);
    if (str < 0) {
        return;
    }
    return str + '分钟'
}