|
|
|
|
@ -1,9 +1,14 @@ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 通用工具类 |
|
|
|
|
*/ |
|
|
|
|
export default class func { |
|
|
|
|
/** |
|
|
|
|
* 不为空 |
|
|
|
|
* @param val |
|
|
|
|
* @returns {boolean} |
|
|
|
|
*/ |
|
|
|
|
export function notEmpty(val) { |
|
|
|
|
static notEmpty(val) { |
|
|
|
|
return !this.isEmpty(val); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -12,7 +17,7 @@ export function notEmpty(val) { |
|
|
|
|
* @param val |
|
|
|
|
* @returns {boolean} |
|
|
|
|
*/ |
|
|
|
|
export function isEmpty(val) { |
|
|
|
|
static isEmpty(val) { |
|
|
|
|
if ( |
|
|
|
|
val === null || |
|
|
|
|
typeof val === 'undefined' || |
|
|
|
|
@ -29,7 +34,7 @@ export function isEmpty(val) { |
|
|
|
|
* @param defaultValue |
|
|
|
|
* @returns {number} |
|
|
|
|
*/ |
|
|
|
|
export function toInt(val, defaultValue) { |
|
|
|
|
static toInt(val, defaultValue) { |
|
|
|
|
if (this.isEmpty(val)) { |
|
|
|
|
return defaultValue === undefined ? -1 : defaultValue; |
|
|
|
|
} |
|
|
|
|
@ -42,7 +47,7 @@ export function toInt(val, defaultValue) { |
|
|
|
|
* @param obj |
|
|
|
|
* @returns {FormData} |
|
|
|
|
*/ |
|
|
|
|
export function toFormData(obj) { |
|
|
|
|
static toFormData(obj) { |
|
|
|
|
const data = new FormData(); |
|
|
|
|
Object.keys(obj).forEach(key => { |
|
|
|
|
data.append(key, Array.isArray(obj[key]) ? obj[key].join(',') : obj[key]); |
|
|
|
|
@ -56,7 +61,7 @@ export function toFormData(obj) { |
|
|
|
|
* @param format |
|
|
|
|
* @returns {null} |
|
|
|
|
*/ |
|
|
|
|
export function format(date, format = 'YYYY-MM-DD HH:mm:ss') { |
|
|
|
|
static format(date, format = 'YYYY-MM-DD HH:mm:ss') { |
|
|
|
|
return date ? date.format(format) : null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -65,7 +70,7 @@ export function format(date, format = 'YYYY-MM-DD HH:mm:ss') { |
|
|
|
|
* @param arr |
|
|
|
|
* @returns {string} |
|
|
|
|
*/ |
|
|
|
|
export function join(arr) { |
|
|
|
|
static join(arr) { |
|
|
|
|
return arr ? arr.join(',') : ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -74,7 +79,7 @@ export function join(arr) { |
|
|
|
|
* @param str |
|
|
|
|
* @returns {string} |
|
|
|
|
*/ |
|
|
|
|
export function split(str) { |
|
|
|
|
static split(str) { |
|
|
|
|
return str ? String(str).split(',') : ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|