|
@@ -1,48 +1,48 @@
|
|
import { devDependencies } from '../../package.json'
|
|
import { devDependencies } from '../../package.json'
|
|
if (!devDependencies['vab-config']) document.body.innerHTML = ''
|
|
if (!devDependencies['vab-config']) document.body.innerHTML = ''
|
|
-/**
|
|
|
|
- * @author chuzhixin 1204505056@qq.com
|
|
|
|
- * @description 格式化时间
|
|
|
|
- * @param time
|
|
|
|
- * @param cFormat
|
|
|
|
- * @returns {string|null}
|
|
|
|
- */
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @author chuzhixin 1204505056@qq.com
|
|
|
|
+ * @description 格式化时间
|
|
|
|
+ * @param time
|
|
|
|
+ * @param cFormat
|
|
|
|
+ * @returns {string|null}
|
|
|
|
+ */
|
|
export function parseTime(time, cFormat) {
|
|
export function parseTime(time, cFormat) {
|
|
- if (arguments.length === 0) {
|
|
|
|
- return null
|
|
|
|
- }
|
|
|
|
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
|
|
|
- let date
|
|
|
|
- if (typeof time === 'object') {
|
|
|
|
- date = time
|
|
|
|
- } else {
|
|
|
|
- if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
|
|
|
|
- time = parseInt(time)
|
|
|
|
|
|
+ if (arguments.length === 0) {
|
|
|
|
+ return null
|
|
}
|
|
}
|
|
- if (typeof time === 'number' && time.toString().length === 10) {
|
|
|
|
- time = time * 1000
|
|
|
|
- }
|
|
|
|
- date = new Date(time)
|
|
|
|
- }
|
|
|
|
- const formatObj = {
|
|
|
|
- y: date.getFullYear(),
|
|
|
|
- m: date.getMonth() + 1,
|
|
|
|
- d: date.getDate(),
|
|
|
|
- h: date.getHours(),
|
|
|
|
- i: date.getMinutes(),
|
|
|
|
- s: date.getSeconds(),
|
|
|
|
- a: date.getDay(),
|
|
|
|
- }
|
|
|
|
- return format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
|
|
|
- let value = formatObj[key]
|
|
|
|
- if (key === 'a') {
|
|
|
|
- return ['日', '一', '二', '三', '四', '五', '六'][value]
|
|
|
|
|
|
+ const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
|
|
|
+ let date
|
|
|
|
+ if (typeof time === 'object') {
|
|
|
|
+ date = time
|
|
|
|
+ } else {
|
|
|
|
+ if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
|
|
|
|
+ time = parseInt(time)
|
|
|
|
+ }
|
|
|
|
+ if (typeof time === 'number' && time.toString().length === 10) {
|
|
|
|
+ time = time * 1000
|
|
|
|
+ }
|
|
|
|
+ date = new Date(time)
|
|
}
|
|
}
|
|
- if (result.length > 0 && value < 10) {
|
|
|
|
- value = '0' + value
|
|
|
|
|
|
+ const formatObj = {
|
|
|
|
+ y: date.getFullYear(),
|
|
|
|
+ m: date.getMonth() + 1,
|
|
|
|
+ d: date.getDate(),
|
|
|
|
+ h: date.getHours(),
|
|
|
|
+ i: date.getMinutes(),
|
|
|
|
+ s: date.getSeconds(),
|
|
|
|
+ a: date.getDay(),
|
|
}
|
|
}
|
|
- return value || 0
|
|
|
|
- })
|
|
|
|
|
|
+ return format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
|
|
|
+ let value = formatObj[key]
|
|
|
|
+ if (key === 'a') {
|
|
|
|
+ return ['日', '一', '二', '三', '四', '五', '六'][value]
|
|
|
|
+ }
|
|
|
|
+ if (result.length > 0 && value < 10) {
|
|
|
|
+ value = '0' + value
|
|
|
|
+ }
|
|
|
|
+ return value || 0
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -53,41 +53,41 @@ export function parseTime(time, cFormat) {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
export function formatTime(time, option) {
|
|
export function formatTime(time, option) {
|
|
- if (('' + time).length === 10) {
|
|
|
|
- time = parseInt(time) * 1000
|
|
|
|
- } else {
|
|
|
|
- time = +time
|
|
|
|
- }
|
|
|
|
- const d = new Date(time)
|
|
|
|
- const now = Date.now()
|
|
|
|
|
|
+ if (('' + time).length === 10) {
|
|
|
|
+ time = parseInt(time) * 1000
|
|
|
|
+ } else {
|
|
|
|
+ time = +time
|
|
|
|
+ }
|
|
|
|
+ const d = new Date(time)
|
|
|
|
+ const now = Date.now()
|
|
|
|
|
|
- const diff = (now - d) / 1000
|
|
|
|
|
|
+ const diff = (now - d) / 1000
|
|
|
|
|
|
- if (diff < 30) {
|
|
|
|
- return '刚刚'
|
|
|
|
- } else if (diff < 3600) {
|
|
|
|
- // less 1 hour
|
|
|
|
- return Math.ceil(diff / 60) + '分钟前'
|
|
|
|
- } else if (diff < 3600 * 24) {
|
|
|
|
- return Math.ceil(diff / 3600) + '小时前'
|
|
|
|
- } else if (diff < 3600 * 24 * 2) {
|
|
|
|
- return '1天前'
|
|
|
|
- }
|
|
|
|
- if (option) {
|
|
|
|
- return parseTime(time, option)
|
|
|
|
- } else {
|
|
|
|
- return (
|
|
|
|
- d.getMonth() +
|
|
|
|
- 1 +
|
|
|
|
- '月' +
|
|
|
|
- d.getDate() +
|
|
|
|
- '日' +
|
|
|
|
- d.getHours() +
|
|
|
|
- '时' +
|
|
|
|
- d.getMinutes() +
|
|
|
|
- '分'
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
|
|
+ if (diff < 30) {
|
|
|
|
+ return '刚刚'
|
|
|
|
+ } else if (diff < 3600) {
|
|
|
|
+ // less 1 hour
|
|
|
|
+ return Math.ceil(diff / 60) + '分钟前'
|
|
|
|
+ } else if (diff < 3600 * 24) {
|
|
|
|
+ return Math.ceil(diff / 3600) + '小时前'
|
|
|
|
+ } else if (diff < 3600 * 24 * 2) {
|
|
|
|
+ return '1天前'
|
|
|
|
+ }
|
|
|
|
+ if (option) {
|
|
|
|
+ return parseTime(time, option)
|
|
|
|
+ } else {
|
|
|
|
+ return (
|
|
|
|
+ d.getMonth() +
|
|
|
|
+ 1 +
|
|
|
|
+ '月' +
|
|
|
|
+ d.getDate() +
|
|
|
|
+ '日' +
|
|
|
|
+ d.getHours() +
|
|
|
|
+ '时' +
|
|
|
|
+ d.getMinutes() +
|
|
|
|
+ '分'
|
|
|
|
+ )
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -97,19 +97,19 @@ export function formatTime(time, option) {
|
|
* @returns {{}|any}
|
|
* @returns {{}|any}
|
|
*/
|
|
*/
|
|
export function paramObj(url) {
|
|
export function paramObj(url) {
|
|
- const search = url.split('?')[1]
|
|
|
|
- if (!search) {
|
|
|
|
- return {}
|
|
|
|
- }
|
|
|
|
- return JSON.parse(
|
|
|
|
- '{"' +
|
|
|
|
- decodeURIComponent(search)
|
|
|
|
|
|
+ const search = url.split('?')[1]
|
|
|
|
+ if (!search) {
|
|
|
|
+ return {}
|
|
|
|
+ }
|
|
|
|
+ return JSON.parse(
|
|
|
|
+ '{"' +
|
|
|
|
+ decodeURIComponent(search)
|
|
.replace(/"/g, '\\"')
|
|
.replace(/"/g, '\\"')
|
|
.replace(/&/g, '","')
|
|
.replace(/&/g, '","')
|
|
.replace(/=/g, '":"')
|
|
.replace(/=/g, '":"')
|
|
.replace(/\+/g, ' ') +
|
|
.replace(/\+/g, ' ') +
|
|
- '"}'
|
|
|
|
- )
|
|
|
|
|
|
+ '"}'
|
|
|
|
+ )
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -119,28 +119,28 @@ export function paramObj(url) {
|
|
* @returns {*}
|
|
* @returns {*}
|
|
*/
|
|
*/
|
|
export function translateDataToTree(data) {
|
|
export function translateDataToTree(data) {
|
|
- const parent = data.filter(
|
|
|
|
- (value) => value.parentId === 'undefined' || value.parentId == null
|
|
|
|
- )
|
|
|
|
- const children = data.filter(
|
|
|
|
- (value) => value.parentId !== 'undefined' && value.parentId != null
|
|
|
|
- )
|
|
|
|
- const translator = (parent, children) => {
|
|
|
|
- parent.forEach((parent) => {
|
|
|
|
- children.forEach((current, index) => {
|
|
|
|
- if (current.parentId === parent.id) {
|
|
|
|
- const temp = JSON.parse(JSON.stringify(children))
|
|
|
|
- temp.splice(index, 1)
|
|
|
|
- translator([current], temp)
|
|
|
|
- typeof parent.children !== 'undefined'
|
|
|
|
- ? parent.children.push(current)
|
|
|
|
- : (parent.children = [current])
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- translator(parent, children)
|
|
|
|
- return parent
|
|
|
|
|
|
+ const parent = data.filter(
|
|
|
|
+ (value) => value.parentId === 'undefined' || value.parentId == null
|
|
|
|
+ )
|
|
|
|
+ const children = data.filter(
|
|
|
|
+ (value) => value.parentId !== 'undefined' && value.parentId != null
|
|
|
|
+ )
|
|
|
|
+ const translator = (parent, children) => {
|
|
|
|
+ parent.forEach((parent) => {
|
|
|
|
+ children.forEach((current, index) => {
|
|
|
|
+ if (current.parentId === parent.id) {
|
|
|
|
+ const temp = JSON.parse(JSON.stringify(children))
|
|
|
|
+ temp.splice(index, 1)
|
|
|
|
+ translator([current], temp)
|
|
|
|
+ typeof parent.children !== 'undefined' ?
|
|
|
|
+ parent.children.push(current) :
|
|
|
|
+ (parent.children = [current])
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ translator(parent, children)
|
|
|
|
+ return parent
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -150,24 +150,24 @@ export function translateDataToTree(data) {
|
|
* @returns {[]}
|
|
* @returns {[]}
|
|
*/
|
|
*/
|
|
export function translateTreeToData(data) {
|
|
export function translateTreeToData(data) {
|
|
- const result = []
|
|
|
|
- data.forEach((item) => {
|
|
|
|
- const loop = (data) => {
|
|
|
|
- result.push({
|
|
|
|
- id: data.id,
|
|
|
|
- name: data.name,
|
|
|
|
- parentId: data.parentId,
|
|
|
|
- })
|
|
|
|
- const child = data.children
|
|
|
|
- if (child) {
|
|
|
|
- for (let i = 0; i < child.length; i++) {
|
|
|
|
- loop(child[i])
|
|
|
|
|
|
+ const result = []
|
|
|
|
+ data.forEach((item) => {
|
|
|
|
+ const loop = (data) => {
|
|
|
|
+ result.push({
|
|
|
|
+ id: data.id,
|
|
|
|
+ name: data.name,
|
|
|
|
+ parentId: data.parentId,
|
|
|
|
+ })
|
|
|
|
+ const child = data.children
|
|
|
|
+ if (child) {
|
|
|
|
+ for (let i = 0; i < child.length; i++) {
|
|
|
|
+ loop(child[i])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }
|
|
|
|
- loop(item)
|
|
|
|
- })
|
|
|
|
- return result
|
|
|
|
|
|
+ loop(item)
|
|
|
|
+ })
|
|
|
|
+ return result
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -177,19 +177,19 @@ export function translateTreeToData(data) {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
export function tenBitTimestamp(time) {
|
|
export function tenBitTimestamp(time) {
|
|
- const date = new Date(time * 1000)
|
|
|
|
- const y = date.getFullYear()
|
|
|
|
- let m = date.getMonth() + 1
|
|
|
|
- m = m < 10 ? '' + m : m
|
|
|
|
- let d = date.getDate()
|
|
|
|
- d = d < 10 ? '' + d : d
|
|
|
|
- let h = date.getHours()
|
|
|
|
- h = h < 10 ? '0' + h : h
|
|
|
|
- let minute = date.getMinutes()
|
|
|
|
- let second = date.getSeconds()
|
|
|
|
- minute = minute < 10 ? '0' + minute : minute
|
|
|
|
- second = second < 10 ? '0' + second : second
|
|
|
|
- return y + '年' + m + '月' + d + '日 ' + h + ':' + minute + ':' + second //组合
|
|
|
|
|
|
+ const date = new Date(time * 1000)
|
|
|
|
+ const y = date.getFullYear()
|
|
|
|
+ let m = date.getMonth() + 1
|
|
|
|
+ m = m < 10 ? '' + m : m
|
|
|
|
+ let d = date.getDate()
|
|
|
|
+ d = d < 10 ? '' + d : d
|
|
|
|
+ let h = date.getHours()
|
|
|
|
+ h = h < 10 ? '0' + h : h
|
|
|
|
+ let minute = date.getMinutes()
|
|
|
|
+ let second = date.getSeconds()
|
|
|
|
+ minute = minute < 10 ? '0' + minute : minute
|
|
|
|
+ second = second < 10 ? '0' + second : second
|
|
|
|
+ return y + '年' + m + '月' + d + '日 ' + h + ':' + minute + ':' + second //组合
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -199,19 +199,19 @@ export function tenBitTimestamp(time) {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
export function thirteenBitTimestamp(time) {
|
|
export function thirteenBitTimestamp(time) {
|
|
- const date = new Date(time / 1)
|
|
|
|
- const y = date.getFullYear()
|
|
|
|
- let m = date.getMonth() + 1
|
|
|
|
- m = m < 10 ? '' + m : m
|
|
|
|
- let d = date.getDate()
|
|
|
|
- d = d < 10 ? '' + d : d
|
|
|
|
- let h = date.getHours()
|
|
|
|
- h = h < 10 ? '0' + h : h
|
|
|
|
- let minute = date.getMinutes()
|
|
|
|
- let second = date.getSeconds()
|
|
|
|
- minute = minute < 10 ? '0' + minute : minute
|
|
|
|
- second = second < 10 ? '0' + second : second
|
|
|
|
- return y + '年' + m + '月' + d + '日 ' + h + ':' + minute + ':' + second //组合
|
|
|
|
|
|
+ const date = new Date(time / 1)
|
|
|
|
+ const y = date.getFullYear()
|
|
|
|
+ let m = date.getMonth() + 1
|
|
|
|
+ m = m < 10 ? '' + m : m
|
|
|
|
+ let d = date.getDate()
|
|
|
|
+ d = d < 10 ? '' + d : d
|
|
|
|
+ let h = date.getHours()
|
|
|
|
+ h = h < 10 ? '0' + h : h
|
|
|
|
+ let minute = date.getMinutes()
|
|
|
|
+ let second = date.getSeconds()
|
|
|
|
+ minute = minute < 10 ? '0' + minute : minute
|
|
|
|
+ second = second < 10 ? '0' + second : second
|
|
|
|
+ return y + '年' + m + '月' + d + '日 ' + h + ':' + minute + ':' + second //组合
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -221,12 +221,12 @@ export function thirteenBitTimestamp(time) {
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
export function uuid(length = 32) {
|
|
export function uuid(length = 32) {
|
|
- const num = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
|
|
|
|
- let str = ''
|
|
|
|
- for (let i = 0; i < length; i++) {
|
|
|
|
- str += num.charAt(Math.floor(Math.random() * num.length))
|
|
|
|
- }
|
|
|
|
- return str
|
|
|
|
|
|
+ const num = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
|
|
|
|
+ let str = ''
|
|
|
|
+ for (let i = 0; i < length; i++) {
|
|
|
|
+ str += num.charAt(Math.floor(Math.random() * num.length))
|
|
|
|
+ }
|
|
|
|
+ return str
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -237,7 +237,7 @@ export function uuid(length = 32) {
|
|
* @returns {number}
|
|
* @returns {number}
|
|
*/
|
|
*/
|
|
export function random(m, n) {
|
|
export function random(m, n) {
|
|
- return Math.floor(Math.random() * (m - n) + n)
|
|
|
|
|
|
+ return Math.floor(Math.random() * (m - n) + n)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -245,12 +245,12 @@ export function random(m, n) {
|
|
* @description addEventListener
|
|
* @description addEventListener
|
|
* @type {function(...[*]=)}
|
|
* @type {function(...[*]=)}
|
|
*/
|
|
*/
|
|
-export const on = (function () {
|
|
|
|
- return function (element, event, handler, useCapture = false) {
|
|
|
|
- if (element && event && handler) {
|
|
|
|
- element.addEventListener(event, handler, useCapture)
|
|
|
|
|
|
+export const on = (function() {
|
|
|
|
+ return function(element, event, handler, useCapture = false) {
|
|
|
|
+ if (element && event && handler) {
|
|
|
|
+ element.addEventListener(event, handler, useCapture)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
})()
|
|
})()
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -258,10 +258,17 @@ export const on = (function () {
|
|
* @description removeEventListener
|
|
* @description removeEventListener
|
|
* @type {function(...[*]=)}
|
|
* @type {function(...[*]=)}
|
|
*/
|
|
*/
|
|
-export const off = (function () {
|
|
|
|
- return function (element, event, handler, useCapture = false) {
|
|
|
|
- if (element && event) {
|
|
|
|
- element.removeEventListener(event, handler, useCapture)
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 手机号校验
|
|
|
|
+ */
|
|
|
|
+export function validatorPhone(rule, value, callback) {
|
|
|
|
+ if (!/^1\d{10}$/.test(value)) {
|
|
|
|
+ callback(new Error('输入的电话号码不正确'))
|
|
|
|
+ } else {
|
|
|
|
+ callback()
|
|
}
|
|
}
|
|
- }
|
|
|
|
-})()
|
|
|
|
|
|
+}
|