@liujitcn/kratos-admin-core 0.0.48 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,10 +2,9 @@ import type { ColumnProps } from "../components/ProTable/interface";
|
|
|
2
2
|
/** 表格单元格支持的对齐方式。 */
|
|
3
3
|
export type TableAlign = "left" | "center" | "right";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 根据列显式配置和组件类型解析单元格对齐方式。
|
|
6
6
|
*
|
|
7
|
-
* 显式 align
|
|
8
|
-
*
|
|
9
|
-
* 数据加载后由响应式表格重新解析。
|
|
7
|
+
* 显式 align 始终优先;选择列、状态列和图片列默认居中,金额列默认右对齐,
|
|
8
|
+
* 字典与枚举列默认居中。普通字段不根据字段名或实际数据猜测,默认左对齐。
|
|
10
9
|
*/
|
|
11
|
-
export declare function resolveTableColumnAlign(column: ColumnProps
|
|
10
|
+
export declare function resolveTableColumnAlign(column: ColumnProps): TableAlign;
|
|
@@ -266,8 +266,8 @@ const processTableData = computed(() => {
|
|
|
266
266
|
);
|
|
267
267
|
});
|
|
268
268
|
|
|
269
|
-
/** 解析 ProTable
|
|
270
|
-
const resolveColumnAlign = (column: ColumnProps) => resolveTableColumnAlign(column
|
|
269
|
+
/** 解析 ProTable 列对齐方式,普通字段不根据字段名或行数据推断。 */
|
|
270
|
+
const resolveColumnAlign = (column: ColumnProps) => resolveTableColumnAlign(column);
|
|
271
271
|
|
|
272
272
|
/** 数据加载完成后按传入行 Key 恢复多选状态,用于页面重建后的选择态续接。 */
|
|
273
273
|
function restoreSelectedRows() {
|
|
@@ -3,53 +3,20 @@ import type { ColumnProps, TypeProps } from "../components/ProTable/interface";
|
|
|
3
3
|
/** 表格单元格支持的对齐方式。 */
|
|
4
4
|
export type TableAlign = "left" | "center" | "right";
|
|
5
5
|
|
|
6
|
-
/** 获取表格行的列值,支持点号分隔的多级字段。 */
|
|
7
|
-
function getTableCellValue(row: Record<string, any>, prop: string) {
|
|
8
|
-
return prop.split(".").reduce((value, key) => (value == null ? undefined : value[key]), row as any);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** 判断值是否为可用于数值对齐的 Number 类型。 */
|
|
12
|
-
function isPureNumber(value: unknown) {
|
|
13
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** 判断列字段名是否表示时间值。 */
|
|
17
|
-
function isTimeColumn(column: ColumnProps) {
|
|
18
|
-
const prop = column.prop?.toLowerCase();
|
|
19
|
-
return !!prop && /(^|[._])(created|updated|deleted|expires|scheduled|execute|start|end|login|logout|last)[._]?at?$/.test(prop);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** 判断列字段名是否表示数值。 */
|
|
23
|
-
function isNumericColumn(column: ColumnProps) {
|
|
24
|
-
const prop = column.prop?.toLowerCase();
|
|
25
|
-
return !!prop && /(^|[._])(id|sort|size|count|total|rows|priority|status_code|latency|duration|process_time|ttl|retention|attempt|qps|rate|number|num|amount|days|minutes|seconds|ms)$/.test(prop);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
6
|
/**
|
|
29
|
-
*
|
|
7
|
+
* 根据列显式配置和组件类型解析单元格对齐方式。
|
|
30
8
|
*
|
|
31
|
-
* 显式 align
|
|
32
|
-
*
|
|
33
|
-
* 数据加载后由响应式表格重新解析。
|
|
9
|
+
* 显式 align 始终优先;选择列、状态列和图片列默认居中,金额列默认右对齐,
|
|
10
|
+
* 字典与枚举列默认居中。普通字段不根据字段名或实际数据猜测,默认左对齐。
|
|
34
11
|
*/
|
|
35
|
-
export function resolveTableColumnAlign(column: ColumnProps
|
|
12
|
+
export function resolveTableColumnAlign(column: ColumnProps): TableAlign {
|
|
36
13
|
if (column.align === "left" || column.align === "center" || column.align === "right") return column.align;
|
|
37
14
|
|
|
38
15
|
const centeredTypes: TypeProps[] = ["selection", "radio", "index", "expand", "sort"];
|
|
39
16
|
if (centeredTypes.includes(column.type as TypeProps)) return "center";
|
|
40
17
|
if (column.cellType === "actions" || column.cellType === "status" || column.cellType === "image") return "center";
|
|
41
18
|
if (column.cellType === "money") return "right";
|
|
42
|
-
if (column.dictCode || column.tag) return "center";
|
|
43
|
-
if (column.enum) return "center";
|
|
44
|
-
if (isTimeColumn(column)) return "center";
|
|
45
|
-
if (isNumericColumn(column)) return "right";
|
|
46
|
-
|
|
47
|
-
if (column.prop) {
|
|
48
|
-
const values = rows
|
|
49
|
-
.map(row => getTableCellValue(row, column.prop as string))
|
|
50
|
-
.filter(value => value !== undefined && value !== null && value !== "");
|
|
51
|
-
if (values.length && values.every(isPureNumber)) return "right";
|
|
52
|
-
}
|
|
19
|
+
if (column.dictCode || column.tag || column.enum) return "center";
|
|
53
20
|
|
|
54
21
|
return "left";
|
|
55
22
|
}
|