diff --git a/apps/web-antd/src/adapter/vxe-table.ts b/apps/web-antd/src/adapter/vxe-table.ts index c4dcb2a86..78b0d0d08 100644 --- a/apps/web-antd/src/adapter/vxe-table.ts +++ b/apps/web-antd/src/adapter/vxe-table.ts @@ -267,6 +267,38 @@ setupVbenVxeTable({ // 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化 // vxeUI.formats.add + + vxeUI.formats.add('formatPast2', { + tableCellFormatMethod({ cellValue }) { + if (cellValue === null || cellValue === undefined) { + return ''; + } + // 定义时间单位常量,便于维护 + const SECOND = 1000; + const MINUTE = 60 * SECOND; + const HOUR = 60 * MINUTE; + const DAY = 24 * HOUR; + + // 计算各时间单位 + const day = Math.floor(cellValue / DAY); + const hour = Math.floor((cellValue % DAY) / HOUR); + const minute = Math.floor((cellValue % HOUR) / MINUTE); + const second = Math.floor((cellValue % MINUTE) / SECOND); + + // 根据时间长短返回不同格式 + if (day > 0) { + return `${day} 天${hour} 小时 ${minute} 分钟`; + } + if (hour > 0) { + return `${hour} 小时 ${minute} 分钟`; + } + if (minute > 0) { + return `${minute} 分钟`; + } + return second > 0 ? `${second} 秒` : `${0} 秒`; + }, + }); + // add by 星语:数量格式化,例如说:金额 vxeUI.formats.add('formatNumber', { tableCellFormatMethod({ cellValue }, digits = 2) { diff --git a/apps/web-antd/src/utils/formatTime.ts b/apps/web-antd/src/utils/formatTime.ts deleted file mode 100644 index 45fe64421..000000000 --- a/apps/web-antd/src/utils/formatTime.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 将毫秒,转换成时间字符串。例如说,xx 分钟 - * - * @param ms 毫秒 - * @returns {string} 字符串 - */ -// TODO @xingyu:这个要融合到哪里去 date 么? -export function formatPast2(ms: number): string { - // 定义时间单位常量,便于维护 - const SECOND = 1000; - const MINUTE = 60 * SECOND; - const HOUR = 60 * MINUTE; - const DAY = 24 * HOUR; - - // 计算各时间单位 - const day = Math.floor(ms / DAY); - const hour = Math.floor((ms % DAY) / HOUR); - const minute = Math.floor((ms % HOUR) / MINUTE); - const second = Math.floor((ms % MINUTE) / SECOND); - - // 根据时间长短返回不同格式 - if (day > 0) { - return `${day} 天${hour} 小时 ${minute} 分钟`; - } - if (hour > 0) { - return `${hour} 小时 ${minute} 分钟`; - } - if (minute > 0) { - return `${minute} 分钟`; - } - return second > 0 ? `${second} 秒` : `${0} 秒`; -} diff --git a/apps/web-antd/src/utils/index.ts b/apps/web-antd/src/utils/index.ts index b33984b78..eb173b636 100644 --- a/apps/web-antd/src/utils/index.ts +++ b/apps/web-antd/src/utils/index.ts @@ -2,7 +2,6 @@ export * from './constants'; export * from './dict'; export * from './download'; export * from './formatNumber'; -export * from './formatTime'; export * from './formCreate'; export * from './rangePickerProps'; export * from './routerHelper';