|
@@ -3,7 +3,7 @@
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function isExternal(path: string): boolean {
|
|
|
- return /^(https?:|mailto:|tel:)/.test(path);
|
|
|
+ return /^(https?:|mailto:|tel:)/.test(path)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -11,8 +11,8 @@ export function isExternal(path: string): boolean {
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function validUsername(str: string): boolean {
|
|
|
- const valid_map = ["admin", "editor"];
|
|
|
- return valid_map.indexOf(str.trim()) >= 0;
|
|
|
+ const valid_map = ['admin', 'editor']
|
|
|
+ return valid_map.indexOf(str.trim()) >= 0
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -20,8 +20,8 @@ export function validUsername(str: string): boolean {
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function validURL(url: string): boolean {
|
|
|
- const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;
|
|
|
- return reg.test(url);
|
|
|
+ const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
|
|
|
+ return reg.test(url)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -29,8 +29,8 @@ export function validURL(url: string): boolean {
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function validLowerCase(str: string): boolean {
|
|
|
- const reg = /^[a-z]+$/;
|
|
|
- return reg.test(str);
|
|
|
+ const reg = /^[a-z]+$/
|
|
|
+ return reg.test(str)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -38,8 +38,8 @@ export function validLowerCase(str: string): boolean {
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function validUpperCase(str: string): boolean {
|
|
|
- const reg = /^[A-Z]+$/;
|
|
|
- return reg.test(str);
|
|
|
+ const reg = /^[A-Z]+$/
|
|
|
+ return reg.test(str)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -47,8 +47,8 @@ export function validUpperCase(str: string): boolean {
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function validAlphabets(str: string): boolean {
|
|
|
- const reg = /^[A-Za-z]+$/;
|
|
|
- return reg.test(str);
|
|
|
+ const reg = /^[A-Za-z]+$/
|
|
|
+ return reg.test(str)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -65,7 +65,7 @@ export function validAlphabets(str: string): boolean {
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function isString(str: any): boolean {
|
|
|
- return typeof str === "string" || str instanceof String;
|
|
|
+ return typeof str === 'string' || str instanceof String
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -73,10 +73,10 @@ export function isString(str: any): boolean {
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
export function isArray(arg: string) {
|
|
|
- if (typeof Array.isArray === "undefined") {
|
|
|
- return Object.prototype.toString.call(arg) === "[object Array]";
|
|
|
+ if (typeof Array.isArray === 'undefined') {
|
|
|
+ return Object.prototype.toString.call(arg) === '[object Array]'
|
|
|
}
|
|
|
- return Array.isArray(arg);
|
|
|
+ return Array.isArray(arg)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -87,28 +87,28 @@ export function isArray(arg: string) {
|
|
|
*/
|
|
|
export function parseTime(time: any, cFormat: string) {
|
|
|
if (arguments.length === 0 || !time) {
|
|
|
- return null;
|
|
|
+ return null
|
|
|
}
|
|
|
- const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
|
|
|
- let date;
|
|
|
- if (typeof time === "object") {
|
|
|
- date = time;
|
|
|
+ const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
|
|
+ let date
|
|
|
+ if (typeof time === 'object') {
|
|
|
+ date = time
|
|
|
} else {
|
|
|
- if (typeof time === "string") {
|
|
|
+ if (typeof time === 'string') {
|
|
|
if (/^[0-9]+$/.test(time)) {
|
|
|
// support "1548221490638"
|
|
|
- time = parseInt(time);
|
|
|
+ time = parseInt(time)
|
|
|
} else {
|
|
|
// support safari
|
|
|
// https://stackoverflow.com/questions/4310953/invalid-date-in-safari
|
|
|
- time = time.replace(new RegExp(/-/gm), "/");
|
|
|
+ time = time.replace(new RegExp(/-/gm), '/')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (typeof time === "number" && time.toString().length === 10) {
|
|
|
- time = time * 1000;
|
|
|
+ if (typeof time === 'number' && time.toString().length === 10) {
|
|
|
+ time = time * 1000
|
|
|
}
|
|
|
- date = new Date(time);
|
|
|
+ date = new Date(time)
|
|
|
}
|
|
|
const formatObj = {
|
|
|
y: date.getFullYear(),
|
|
@@ -118,47 +118,65 @@ export function parseTime(time: any, cFormat: string) {
|
|
|
i: date.getMinutes(),
|
|
|
s: date.getSeconds(),
|
|
|
a: date.getDay(),
|
|
|
- };
|
|
|
+ }
|
|
|
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
|
|
- const value = formatObj[key];
|
|
|
+ const value = formatObj[key]
|
|
|
// Note: getDay() returns 0 on Sunday
|
|
|
- if (key === "a") {
|
|
|
- return ["日", "一", "二", "三", "四", "五", "六"][value];
|
|
|
+ if (key === 'a') {
|
|
|
+ return ['日', '一', '二', '三', '四', '五', '六'][value]
|
|
|
}
|
|
|
- return value.toString().padStart(2, "0");
|
|
|
- });
|
|
|
- return time_str;
|
|
|
+ return value.toString().padStart(2, '0')
|
|
|
+ })
|
|
|
+ return time_str
|
|
|
}
|
|
|
|
|
|
export function translateDataToTreeAll(arr, parentKey, key) {
|
|
|
- const map = {};
|
|
|
- const result = [];
|
|
|
+ const map = {}
|
|
|
+ const result = []
|
|
|
arr.forEach((element) => {
|
|
|
- const id = element[key];
|
|
|
- const pid = element[parentKey];
|
|
|
+ const id = element[key]
|
|
|
+ const pid = element[parentKey]
|
|
|
if (map[id]) {
|
|
|
map[id] = {
|
|
|
...element,
|
|
|
children: map[id].children,
|
|
|
- };
|
|
|
+ }
|
|
|
} else {
|
|
|
map[id] = {
|
|
|
...element,
|
|
|
children: [],
|
|
|
- };
|
|
|
+ }
|
|
|
}
|
|
|
- const item = map[id];
|
|
|
+ const item = map[id]
|
|
|
if (pid <= 0) {
|
|
|
- result.push(item);
|
|
|
+ result.push(item)
|
|
|
} else {
|
|
|
if (map[pid]) {
|
|
|
- map[pid].children.push(item);
|
|
|
+ map[pid].children.push(item)
|
|
|
} else {
|
|
|
map[pid] = {
|
|
|
children: [item],
|
|
|
- };
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
- return result;
|
|
|
+ })
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+export function setTree(arr, parentKey, key) {
|
|
|
+ const result: any = []
|
|
|
+ const datas: any = []
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ for (let j = 0; j < arr.length - 1; j++) {
|
|
|
+ if (arr[i][key] == arr[j][parentKey]) {
|
|
|
+ const item = arr[i]
|
|
|
+ datas.push(arr[j])
|
|
|
+ item.children = datas
|
|
|
+ arr.splice(i, 1)
|
|
|
+ } else {
|
|
|
+ result.push(arr[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
}
|