yangyin
2024-09-07 ca56a45c58301de1e2ee852a6ba4ea71d035f098
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
/**
 * 对比两个客户的路由,看target中有哪些是在source 中没有的;看source中有哪些是在target 中没有的
 * @param {*} source
 * @param {*} target
 */
const routeContrast = (source, target) => {
    const sourceMap = new Map(source.map((item) => [item.path, item]));
 
    const targetMap = new Map(target.map((item) => [item.path, item]));
 
    let sourceExclusiveList = [];
    for (const item of target) {
        const targetPath = item.path;
        if (!sourceMap.get(targetPath)) {
            sourceExclusiveList.push(item);
        }
    }
 
    let targetExclusiveList = [];
    for (const item of source) {
        const targetPath = item.path;
        if (!targetMap.get(targetPath)) {
            targetExclusiveList.push(item);
        }
    }
    // 按 path 排序
    const newSourceExclusiveList = sourceExclusiveList
        .toSorted((a, b) => a.path > b.path)
        .map((item) => ({
            path: item.path,
            ...item,
        }));
    const newTargetExclusiveList = targetExclusiveList
        .toSorted((a, b) => a.path > b.path)
        .map((item) => ({
            path: item.path,
            ...item,
        }));
    console.log('source 不包含的 target 中的路由:', newSourceExclusiveList);
    console.log('target 不包含的 source 中的路由:', newTargetExclusiveList);
};