Files
refinery-admin/src/utils/index.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-02-09 15:51:21 +08:00
export function parseTime(time) {
if (arguments.length === 0 || !time) {
return "--";
}
let date;
if (typeof time === "object") {
date = time;
} else {
if (typeof time === "string") {
if (/^[0-9]+$/.test(time)) {
time = parseInt(time);
} else {
time = time.replace(new RegExp(/-/gm), "/");
}
}
date = new Date(time);
}
const formatRes = {
y: date.getFullYear(),
M: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
m: date.getMinutes(),
s: date.getSeconds(),
week: ["日", "一", "二", "三", "四", "五", "六"][date.getDay()],
};
formatRes.M < 10 && (formatRes.M = "0" + formatRes.M);
formatRes.d < 10 && (formatRes.d = "0" + formatRes.d);
formatRes.h < 10 && (formatRes.h = "0" + formatRes.h);
formatRes.m < 10 && (formatRes.m = "0" + formatRes.m);
formatRes.s < 10 && (formatRes.s = "0" + formatRes.s);
return formatRes;
}
2023-02-24 17:12:47 +08:00
// 防抖
2023-02-09 15:51:21 +08:00
export function debounce(fn, delay) {
let timer = null;
return function () {
if (timer) clearTimeout(timer);
let _this = this;
let _arguments = arguments;
timer = setTimeout(function () {
fn.apply(_this, _arguments);
}, delay);
};
}
export function isLicensePlate(no) {
let instance = new RegExp(
"^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[a-zA-Z](([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})$"
);
return instance.test(no);
}
2023-02-14 13:35:22 +08:00
export function cellStyle() {
return "text-align:center";
}
2023-02-24 17:12:47 +08:00
// 类型判断
2023-02-22 17:21:31 +08:00
export function typeJudgment(object) {
let res = {}.__proto__.toString.call(object);
2023-02-24 17:12:47 +08:00
return res || "";
2023-02-22 17:21:31 +08:00
}