utility.js 1.2 KB
const formatDate = function(date) {
    return moment(date).format("YYYY-MM-DD HH:mm:ss")
}

const getPagedList = function(list, columnNum) {
    const baseArray = list
    const len = baseArray.length
    const lineNum = len % columnNum === 0 ? len / columnNum : Math.floor((len / columnNum) + 1)
    let result = []
    for (let i = 0; i < lineNum; i++)
    {
        // slice() 方法返回一个从开始到结束(不包括结束)选择的数组的一部分浅拷贝到一个新数组对象。且原始数组不会被修改。
        const temp = baseArray.slice(i * columnNum, i * columnNum + columnNum)
        result.push(temp)
    }
    return result
}

const isEqual = (value, other) => {
    return _.isEqual(value, other)
}

const isOneOfTheseValue = function(value, expectedValueList) {
    for (let expectedValue of expectedValueList)
    {
        if (isEqual(value, expectedValue))
        {
            return true
        }
    }
    return false
}
const filterEmptyValueInObject = function(object) {
    for (let key in object)
    {
        let value = object[key]
        if (isOneOfTheseValue(value, ['', NaN, undefined, null]))
        {
            delete object[key]
        }
    }
    return object
}