xiaozy_0517
xiaozhiyong 2 years ago
parent e73db5d59f
commit 026958f64d
  1. 67
      src/utils/index.js

@ -1,19 +1,19 @@
export function parseTime(time) {
if (arguments.length === 0 || !time) {
return "--";
if (!time) {
return '--'
}
let date;
if (typeof time === "object") {
date = time;
let date
if (typeof time === 'object') {
date = time
} else {
if (typeof time === "string") {
if (typeof time === 'string') {
if (/^[0-9]+$/.test(time)) {
time = parseInt(time);
time = parseInt(time)
} else {
time = time.replace(new RegExp(/-/gm), "/");
time = time.replace(new RegExp(/-/gm), '/')
}
}
date = new Date(time);
date = new Date(time)
}
const formatRes = {
y: date.getFullYear(),
@ -22,42 +22,43 @@ export function parseTime(time) {
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;
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
}
// 防抖
export function debounce(fn, delay) {
let timer = null;
let timer = null
return function () {
if (timer) clearTimeout(timer);
let _this = this;
let _arguments = arguments;
if (timer) clearTimeout(timer)
let _this = this
let _arguments = arguments
timer = setTimeout(function () {
fn.apply(_this, _arguments);
}, delay);
};
fn.apply(_this, _arguments)
}, delay)
}
export function isLicensePlate(no) {
}
// 车牌校验
export function isLicensePlate(number) {
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);
'^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领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(number)
}
export function cellStyle() {
return "text-align:center";
return 'text-align:center'
}
// 类型判断
export function typeJudgment(object) {
let res = {}.__proto__.toString.call(object);
let type = /(?<= ).+(?=\])/.exec(res);
return type.length ? type[0] : "";
let res = {}.__proto__.toString.call(object)
let type = /(?<= ).+(?=\])/.exec(res)
return type.length ? type[0] : ''
}

Loading…
Cancel
Save