|
@@ -0,0 +1,133 @@
|
|
|
+/**
|
|
|
+ * @description 判断是否是数组
|
|
|
+ * @param arg
|
|
|
+ */
|
|
|
+export function isArray(arg) {
|
|
|
+ if (typeof Array.isArray === 'undefined') {
|
|
|
+ return Object.prototype.toString.call(arg) === '[object Array]'
|
|
|
+ }
|
|
|
+ return Array.isArray(arg)
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @description 判断是否是小写字母
|
|
|
+ * @param value
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+export function isLowerCase(value) {
|
|
|
+ const reg = /^[a-z]+$/
|
|
|
+ return reg.test(value)
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @description 判断是否是大写字母
|
|
|
+ * @param value
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+export function isUpperCase(value) {
|
|
|
+ const reg = /^[A-Z]+$/
|
|
|
+ return reg.test(value)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description 判断是否是大写字母开头
|
|
|
+ * @param value
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+export function isAlphabets(value) {
|
|
|
+ const reg = /^[A-Za-z]+$/
|
|
|
+ return reg.test(value)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description 判断是否是字符串
|
|
|
+ * @param value
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+export function isString(value) {
|
|
|
+ return typeof value === 'string' || value instanceof String
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @description 判断是否是端口号
|
|
|
+ * @param value
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+export function isPort(value) {
|
|
|
+ const reg = /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/
|
|
|
+ return reg.test(value)
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @description 判断是否中文
|
|
|
+ * @param value
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+export function isChina(value) {
|
|
|
+ const reg = /^[\u4E00-\u9FA5]{2,4}$/
|
|
|
+ return reg.test(value)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description 判断是否为空
|
|
|
+ * @param value
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+export function isBlank(value) {
|
|
|
+ return value === null || false || value === '' || value.trim() === '' || value.toLocaleLowerCase().trim() === 'null'
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @description 判断是否是手机号
|
|
|
+ * @param value
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+
|
|
|
+export const isPhone = (reule, value, cb) => {
|
|
|
+ if (!value) {
|
|
|
+ cb()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 手机的正则表达式
|
|
|
+ const regPhone = /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/
|
|
|
+ if (regPhone.test(value)) {
|
|
|
+ // 合法手机号
|
|
|
+ return cb()
|
|
|
+ } else {
|
|
|
+ cb(new Error('请输入合法的手机号'))
|
|
|
+ }
|
|
|
+}
|
|
|
+// 只能输入0-9数字型
|
|
|
+export const isNumber = (reule, value, cb) => {
|
|
|
+ const regNumber = /^[+-]?\d+(\.\d+)?$/
|
|
|
+
|
|
|
+ if (regNumber.test(value)) {
|
|
|
+ return cb()
|
|
|
+ }
|
|
|
+ cb(new Error('只能输入数字型'))
|
|
|
+}
|
|
|
+//由数字、26个英文字母或者下划线组成的
|
|
|
+export const isRuletype = (reule, value, cb) => {
|
|
|
+ const reg = /^[0-9a-zA-Z_-]{1,}$/
|
|
|
+ if (reg.test(value)) {
|
|
|
+ return cb()
|
|
|
+ }
|
|
|
+ cb(new Error('只允许输入字母或字母或者下划线_中划线-'))
|
|
|
+}
|
|
|
+// 年月日
|
|
|
+export const formatDate1 = (cellValue) => {
|
|
|
+ if (cellValue == null || cellValue == '') return ''
|
|
|
+ var date = new Date(cellValue)
|
|
|
+ var year = date.getFullYear()
|
|
|
+ var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
|
|
+ var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
|
|
+ return year + '-' + month + '-' + day
|
|
|
+}
|
|
|
+
|
|
|
+// 年月日时分秒
|
|
|
+export const formatDate = (cellValue) => {
|
|
|
+ if (cellValue == null || cellValue == '') return ''
|
|
|
+ var date = new Date(cellValue)
|
|
|
+ var year = date.getFullYear()
|
|
|
+ var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
|
|
+ var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
|
|
+ var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
|
|
+ var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
|
|
+ var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
|
|
|
+ return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
|
|
|
+}
|