feat: vxe add formatPast2

pull/133/MERGE
xingyu4j 2025-06-06 20:44:39 +08:00
parent 6a069f49cf
commit 5e77558efd
3 changed files with 32 additions and 33 deletions

View File

@ -267,6 +267,38 @@ setupVbenVxeTable({
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化 // 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
// vxeUI.formats.add // 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 星语:数量格式化,例如说:金额 // add by 星语:数量格式化,例如说:金额
vxeUI.formats.add('formatNumber', { vxeUI.formats.add('formatNumber', {
tableCellFormatMethod({ cellValue }, digits = 2) { tableCellFormatMethod({ cellValue }, digits = 2) {

View File

@ -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}`;
}

View File

@ -2,7 +2,6 @@ export * from './constants';
export * from './dict'; export * from './dict';
export * from './download'; export * from './download';
export * from './formatNumber'; export * from './formatNumber';
export * from './formatTime';
export * from './formCreate'; export * from './formCreate';
export * from './rangePickerProps'; export * from './rangePickerProps';
export * from './routerHelper'; export * from './routerHelper';