|
@@ -1,5 +1,5 @@
|
|
|
-import type { App, Component } from 'vue';
|
|
|
import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router';
|
|
|
+import type { App, Component } from 'vue';
|
|
|
|
|
|
import { intersectionWith, isEqual, mergeWith, unionWith } from 'lodash-es';
|
|
|
import { unref } from 'vue';
|
|
@@ -52,6 +52,14 @@ export function deepMerge<T extends object | null | undefined, U extends object
|
|
|
target: U,
|
|
|
mergeArrays: 'union' | 'intersection' | 'concat' | 'replace' = 'replace',
|
|
|
): T & U {
|
|
|
+
|
|
|
+ return mergeWith(cloneDeep(target), source, (objValue, srcValue) => {
|
|
|
+ if (isObject(objValue) && isObject(srcValue)) {
|
|
|
+ return mergeWith(cloneDeep(objValue), srcValue, (prevValue, nextValue) => {
|
|
|
+ // 如果是数组,合并数组(去重) If it is an array, merge the array (remove duplicates)
|
|
|
+ return isArray(prevValue) ? unionWith(prevValue, nextValue, isEqual) : undefined;
|
|
|
+ });
|
|
|
+
|
|
|
if (!target) {
|
|
|
return source as T & U;
|
|
|
}
|
|
@@ -70,6 +78,7 @@ export function deepMerge<T extends object | null | undefined, U extends object
|
|
|
return source as T & U;
|
|
|
default:
|
|
|
throw new Error(`Unknown merge array strategy: ${mergeArrays}`);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
if (isObject(target) && isObject(source)) {
|