xiangpei
2024-11-21 fa91cc6202aabdbe3805d26e89a776656790d7d1
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
function objectToFormData(obj) {
    const fd = new FormData();
    Object.keys(obj).forEach(key => {
        const value = obj[key];
        fd.set(key, value);
    });
    return fd;
}
function objectToQueryStr(obj, filterNull = false) {
    let queryStr = "";
    Object.keys(obj).forEach(key => {
        if (filterNull && !obj[key]) {
           return;
        }
        queryStr += `&${key}=${obj[key] || ''}`
    });
    console.log(queryStr);
    return queryStr.slice(1);
}
function openWindow(path) {
    const prefix = process.env.VUE_APP_TAB_URL_PREFIX;
    window.open(prefix + "" + path);
}
 
// 运行实例
function listToTree(list) {
    const nodeMap = {};
    const firstLevelList = list.filter(item => item.parentExecutionId === "0");
    firstLevelList.forEach(item => {
        const {executionId} = item;
        nodeMap[executionId] = item;
    });
    while (true) {
        list.forEach(item => {
            const {parentExecutionId, executionId} = item;
            if (nodeMap[executionId]) return;
            if (nodeMap[parentExecutionId]) {
                const parent = nodeMap[parentExecutionId];
                if (parent.children) {
                    parent.children.push(item);
                } else {
                    parent.children = [item];
                }
                nodeMap[executionId] = item;
            }
        });
        if (Object.keys(nodeMap).length === list.length) {
            return firstLevelList;
        }
    }
 
}
 
function normalizeDateTimeString(rawDatatimeStr) {
    function genNumStr(num) {
        return Number(num) < 10 ? "0" + num : ("" + num) 
    }
    if (rawDatatimeStr) {
        const dateObj = new Date(rawDatatimeStr);
 
        const yyyy = dateObj.getFullYear();
        const MM = dateObj.getMonth() + 1;
        const dd = dateObj.getDate();
 
        const HH = dateObj.getHours();
        const mm = dateObj.getMinutes();
        const ss = dateObj.getSeconds();
 
        return `${yyyy}-${genNumStr(MM)}-${genNumStr(dd)} ${genNumStr(HH)}:${genNumStr(mm)}:${genNumStr(ss)}`;
    }
}
 
export default {
    objectToFormData,
    objectToQueryStr,
    openWindow,
    listToTree,
    normalizeDateTimeString
};