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

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

Loading…
Cancel
Save