/**
|
* 对比两个客户的路由,看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);
|
};
|