|
|
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
|
}
|