zhangwei
2025-12-22 4a5993fb232124830dcc964fc5525896fdea583e
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 
 
import $router from '../router/index'
import { ElMessageBox } from 'element-plus'
 
// const {$meth,$confirm } = getCurrentInstance().appContext.config.globalProperties
function gourl (url,obj = {}) {
    $router.push({
        path:url,
        query:obj
    })
}
// 由于json.stringify嵌套循环导致报错的解决函数,obj是要stringify的对象
function circularSafeStringify (obj){
  const cache = new Set();
  return JSON.stringify(obj, (key, value) => {
    if (typeof value === "object" && value !== null) {
      if (cache.has(value)) {
        // 当前对象已经存在于缓存中,说明存在循环引用,返回占位符或其他处理方式
        return "[Circular Reference]";
      }
      cache.add(value);
    }
    return value;
  });
}
 
function islogin(el){
    let newel=el?el:"请先登录"
    ElMessageBox.confirm(newel, "提示",{
        confirmButtonText: '确定',
        cancelButtonText:"取消",
         type: 'warning',
          callback: (action) => {
            if(action=="confirm"){
                $router.push({path:"/login"})
           
            }
           
         
 
  },
    })
}
//防抖
function debounce(func, delay) {
    let timeoutId;
    return function (...args) {
      clearTimeout(timeoutId);
      timeoutId = setTimeout(() => {
        func.apply(this, args);
      }, delay);
    };
  }
 
  // 入参 fmt-格式 date-日期
function formatDate(fmt, date) {
  let ret;
  const opt = {
      "Y+": date.getFullYear().toString(),        // 年
      "m+": (date.getMonth() + 1).toString(),     // 月
      "d+": date.getDate().toString(),            // 日
      "H+": date.getHours().toString(),           // 时
      "M+": date.getMinutes().toString(),         // 分
      "S+": date.getSeconds().toString()          // 秒
      // 有其他格式化字符需求可以继续添加,必须转化成字符串
  };
  for (let k in opt) {
      ret = new RegExp("(" + k + ")").exec(fmt);
      if (ret) {
          fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
      };
  };
  return fmt;
}
 
export {
    gourl,
    islogin,
    debounce,
    circularSafeStringify,
    formatDate
}