xachary
2024-02-11 236ddf3471a7851ff6541f5709e9cbb6105b58f7
src/utils/index.ts
@@ -3,7 +3,7 @@
import { intersectionWith, isEqual, mergeWith, unionWith } from 'lodash-es';
import { unref } from 'vue';
import { isArray, isObject } from '/@/utils/is';
import { isArray, isObject } from '@/utils/is';
export const noop = () => {};
@@ -52,41 +52,32 @@
  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;
  }
  if (!source) {
    return target as T & U;
  }
  if (isArray(target) && isArray(source)) {
    switch (mergeArrays) {
      case 'union':
        return unionWith(target, source, isEqual) as T & U;
      case 'intersection':
        return intersectionWith(target, source, isEqual) as T & U;
      case 'concat':
        return target.concat(source) as T & U;
      case 'replace':
        return source as T & U;
      default:
        throw new Error(`Unknown merge array strategy: ${mergeArrays}`);
  return mergeWith({}, source, target, (sourceValue, targetValue) => {
    if (isArray(targetValue) && isArray(sourceValue)) {
      switch (mergeArrays) {
        case 'union':
          return unionWith(sourceValue, targetValue, isEqual);
        case 'intersection':
          return intersectionWith(sourceValue, targetValue, isEqual);
        case 'concat':
          return sourceValue.concat(targetValue);
        case 'replace':
          return targetValue;
        default:
          throw new Error(`Unknown merge array strategy: ${mergeArrays as string}`);
      }
    }
  }
  if (isObject(target) && isObject(source)) {
    return mergeWith({}, target, source, (targetValue, sourceValue) => {
      return deepMerge(targetValue, sourceValue, mergeArrays);
    }) as T & U;
  }
  return source as T & U;
    if (isObject(targetValue) && isObject(sourceValue)) {
      return deepMerge(sourceValue, targetValue, mergeArrays);
    }
    return undefined;
  });
}
export function openWindow(