Blame view

utils/index.ts 1.14 KB
1
2
import { useDisplay } from "vuetify";
import { MOBILE_WIDTH } from "../constant/index";
3
4

export const isMobile = () => {
5
6
7
  const { width } = useDisplay();
  return width.value <= MOBILE_WIDTH;
};
8
9
export const isEqual = (value: any, other: any) => {
10
11
12
13
14
15
16
  // 获取两个比较值的类型
  const type = Object.prototype.toString.call(value);

  // 检查类型是否相同
  if (type !== Object.prototype.toString.call(other)) return false;

  // 根据不同的数据类型进行比较
17
  if (type === "[object Object]" || type === "[object Array]") {
18
    // 比较数组或对象的长度
19
20
21
22
    const valueLen =
      type === "[object Object]" ? Object.keys(value).length : value.length;
    const otherLen =
      type === "[object Object]" ? Object.keys(other).length : other.length;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    if (valueLen !== otherLen) return false;

    // 递归比较数组或对象中的每个元素
    const compare = (item1, item2) => {
      for (const key in item1) {
        if (!isEqual(item1[key], item2[key])) return false;
      }
      return true;
    };

    return compare(value, other);
  } else {
    // 基本数据类型直接比较
    return value === other;
  }
38
};