Files
ReelShortWeb/src/utils/format.js
T

26 lines
910 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Author: fruit.com.cn
/** 播放量等大数值的展示格式:12345 → 1.2万,3100000 → 310.0万 */
export function formatCount(value) {
const num = Number(value || 0)
if (!Number.isFinite(num)) return '0'
if (num >= 100000000) return `${(num / 100000000).toFixed(2)}亿`
if (num >= 10000) return `${(num / 10000).toFixed(1)}万`
return String(num)
}
/**
* 时间展示:直接返回实体的接口给的是 ISO 时间(2026-10-15T13:22:03),
* 和后台其它页面「yyyy-MM-dd HH:mm:ss」的观感不一致,这里统一成后者。
*/
export function formatDateTime(value) {
if (!value) return '-'
const text = String(value).replace('T', ' ')
return text.length > 19 ? text.slice(0, 19) : text
}
/** el-table-column 的 formatter 适配(签名是 row, column, cellValue) */
export function dateCell(_row, _column, cellValue) {
return formatDateTime(cellValue)
}