u
This commit is contained in:
1 parent
c7240ea7c9
commit
189a085353
26 files changed
+2650
-201
No files matched your search
@@ -47,7 +47,6 @@ export function updateViewTableColumns(tableRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const newColumns = columns
|
||||
.filter((item) => item.type === undefined && item.params && item.params.b_id)
|
||||
.map((item, index) => ({
|
||||
@@ -119,3 +118,35 @@ export function formatValueByFormat(value, format) {
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 format 格式化值
|
||||
* @param {any} value 原始值
|
||||
* @param {string} format 格式描述,如 money(2)、percent(1)
|
||||
*/
|
||||
export function formatValueByFullFormat(value, format) {
|
||||
if (value === null || value === undefined || value === "") return "";
|
||||
|
||||
if (!format || typeof format !== "string") return value;
|
||||
|
||||
const fmt = format.trim().toLowerCase();
|
||||
|
||||
// money(n)
|
||||
if (fmt.startsWith("money")) {
|
||||
const match = fmt.match(/^money\((\d+)\)$/);
|
||||
const decimals = match ? Number(match[1]) : 2;
|
||||
|
||||
const num = Number.parseFloat(value);
|
||||
if (Number.isNaN(num)) return value;
|
||||
|
||||
return num.toFixed(decimals);
|
||||
} else if (fmt === "date") {
|
||||
return formatToDate(value);
|
||||
} else if (fmt === "datetime") {
|
||||
return formatToDateTime(value);
|
||||
} else if (fmt === "number") {
|
||||
return Number(value) || 0;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
Reference in new issue
Block a user