From 026958f64deb27a6f97ce74ae60996c7db689aa6 Mon Sep 17 00:00:00 2001 From: xiaozhiyong Date: Fri, 28 Apr 2023 13:30:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.js | 67 +++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index ce47b84..bf91135 100644 --- a/src/utils/index.js +++ b/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] : '' }