// utils/tool.js
import Day from './dayjs'

/**
 * 数据展示
 * null => ''
 */
export const showData = (data, result = '') => {
    if (typeof data === 'undefined' || data === null) {
        return result
    }
    if (typeof data === 'string' && data.trim() === '') {
        return result
    }
    if (data === '-1' || data === -1) {
        return result
    }
    if (Array.isArray(data) && data.length === 0) {
        return result
    }
    if (typeof data === 'object' && Object.keys(data).length === 0) {
        return result
    }
    return data
}

/**
 * 时间戳格式化
 * 1715072168340 => 2024-05-07 16:56:08
 */
export const timeStampFormat = (timeStamp, opt) => {
    if (!timeStamp || timeStamp == -1 || timeStamp == '-1') {
        return ''
    }
    timeStamp = parseInt(String(timeStamp))
    const format = opt?.format || 'YYYY-MM-DD HH:mm:ss'
    return Day(timeStamp).format(format)
}
