@amaoaaaaa/search-table 0.1.0-beta.1

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.
@@ -0,0 +1,157 @@
1
+ import { MaybeRefOrGetter } from 'vue';
2
+ import { TableColumnProps } from 'element-plus/es/components/table/src/table-column/defaults';
3
+ import { DefaultRow } from 'element-plus/es/components/table/src/table/defaults.mjs';
4
+ export type TableRow = DefaultRow;
5
+ export type FilterOption = {
6
+ label: string;
7
+ value: string | number | boolean;
8
+ };
9
+ /**
10
+ * 操作按钮显示状态
11
+ *
12
+ * - true: 正常显示
13
+ * - false: 不渲染
14
+ * - 'hidden': 不显示但占位
15
+ */
16
+ export type ActionButtonVisibility = boolean | 'hidden';
17
+ /**
18
+ * 表格操作按钮
19
+ */
20
+ export interface ProTableAction<T extends TableRow = TableRow> {
21
+ text: string;
22
+ /**
23
+ * 按钮类型
24
+ *
25
+ * @default 'primary'
26
+ */
27
+ type?: '' | 'primary' | 'danger' | 'text' | 'default' | 'success' | 'warning' | 'info';
28
+ /**
29
+ * 是否显示
30
+ *
31
+ * - true: 正常显示
32
+ * - false: 不渲染
33
+ * - 'hidden': 不显示但占位
34
+ *
35
+ * @default true
36
+ */
37
+ visibility?: ActionButtonVisibility | ((row: T) => ActionButtonVisibility);
38
+ /**
39
+ * 是否禁用
40
+ *
41
+ * @default false
42
+ */
43
+ disabled?: boolean | ((row: T) => boolean);
44
+ handler: (row: T) => void;
45
+ /**
46
+ * 二次确认提示内容
47
+ *
48
+ * @description
49
+ * - 传入 `true` 表示使用默认提示内容:`是否确认${action.text}?`
50
+ * - 传入 `false` 表示不使用二次确认
51
+ * - 传入字符串表示使用自定义提示内容
52
+ * - 函数表示使用自定义提示内容
53
+ */
54
+ confirmText?: boolean | string | ((row: T) => string);
55
+ }
56
+ export type FilterType = 'radio' | 'checkbox' | 'datetimerange';
57
+ /**
58
+ * 表格列配置
59
+ */
60
+ export type ProTableColumn<T extends TableRow = TableRow> = Partial<Omit<TableColumnProps<T>, 'filters'>> & {
61
+ prop?: keyof T;
62
+ align?: 'left' | 'center' | 'right';
63
+ /**
64
+ * 是否可编辑
65
+ * @default false
66
+ */
67
+ editable?: boolean | ((row: T) => boolean);
68
+ /**
69
+ * 内容溢出自动截断,鼠标移入显示完整内容
70
+ *
71
+ * @default true
72
+ */
73
+ truncate?: boolean;
74
+ /**
75
+ * 是否可筛选
76
+ *
77
+ * @description 优先级高于 `filterOptions`
78
+ */
79
+ filterable?: boolean;
80
+ /**
81
+ * 数据过滤字段名,默认为当前列 `prop` 属性的值
82
+ */
83
+ filterFieldName?: string;
84
+ /**
85
+ * 时间范围筛选字段名
86
+ */
87
+ datetimerangeFilterFieldNames?: string[];
88
+ /**
89
+ * 数据过滤类型
90
+ * - radio: 单选(默认)
91
+ * - checkbox: 多选
92
+ * - datetimerange: 时间范围选择器
93
+ */
94
+ filterType?: FilterType;
95
+ /**
96
+ * 数据过滤选项
97
+ */
98
+ filterOptions?: MaybeRefOrGetter<FilterOption[] | undefined>;
99
+ /**
100
+ * 筛选弹窗宽度
101
+ */
102
+ filterPopoverWidth?: number;
103
+ /**
104
+ * 操作按钮
105
+ */
106
+ actions?: ProTableAction<T>[] | ((row: T) => ProTableAction<T>[]);
107
+ };
108
+ /**
109
+ * 表格配置
110
+ */
111
+ export type ProTableProps<T extends TableRow = any> = {
112
+ data: T[];
113
+ columns: ProTableColumn<T>[];
114
+ /**
115
+ * 行数据的 Key,属性值必须唯一
116
+ *
117
+ * @default 'id'
118
+ */
119
+ rowKey?: string;
120
+ /**
121
+ * 是否可选择
122
+ * - 传入 true 表示所有行都可选择
123
+ * - 传入函数表示自定义选择逻辑
124
+ *
125
+ * @default undefined
126
+ */
127
+ selectable?: boolean | ((row: any, index: number) => boolean);
128
+ showIndex?: boolean;
129
+ indexWidth?: TableColumnProps['width'];
130
+ indexOffset?: number;
131
+ loading?: boolean;
132
+ };
133
+ export type ApplyFilterPayload = {
134
+ prop: string;
135
+ type: FilterType;
136
+ value: any;
137
+ filterData: Record<string, any>;
138
+ col: ProTableColumn;
139
+ };
140
+ /**
141
+ * 单元格退出编辑状态时触发回调的参数
142
+ * @template T 行数据类型
143
+ */
144
+ export type CellEditPayload<T = any> = {
145
+ /** 编辑后的值 */
146
+ newValue: any;
147
+ /** 编辑前的值 */
148
+ oldValue: any;
149
+ /** 行索引 */
150
+ rowIndex: number;
151
+ /** 列索引 */
152
+ colIndex: number;
153
+ /** 当前行完整数据 */
154
+ row: T;
155
+ /** 当前列对应的字段名 */
156
+ prop: keyof T;
157
+ };
@@ -0,0 +1,45 @@
1
+ type RowKey = string;
2
+ /**
3
+ * 表格跨页选择状态管理器
4
+ */
5
+ export declare class SelectionStore<T extends Record<string, any>> {
6
+ /** 存储选中的行 */
7
+ private map;
8
+ /** 行数据的 Key */
9
+ private rowKey;
10
+ /**
11
+ * 实例化 SelectionStore
12
+ *
13
+ * @param rowKey 作为 id 的字段名,默认为 `'id'`
14
+ */
15
+ constructor(rowKey?: string);
16
+ /** 获取所有选中行 */
17
+ get values(): T[];
18
+ /** 获取选中 id */
19
+ get ids(): RowKey[];
20
+ /** 是否选中 */
21
+ has(id: RowKey): boolean;
22
+ /** 选中一行 */
23
+ select(row: T): void;
24
+ /** 取消选中 */
25
+ unselect(id: RowKey): void;
26
+ /** 批量选中 */
27
+ selectMany(rows: T[]): void;
28
+ /** 批量取消 */
29
+ unselectMany(ids: RowKey[]): void;
30
+ /** 清空 */
31
+ clear(): void;
32
+ /**
33
+ * 同步当前页 selection-change
34
+ * @param pageRows 当前页数据
35
+ * @param selected 当前页勾选行
36
+ */
37
+ syncPage(pageRows: T[], selected: T[]): void;
38
+ /**
39
+ * 同步表格 UI 勾选状态
40
+ * @param pageRows 当前页数据
41
+ * @param toggleFn el-table toggleRowSelection
42
+ */
43
+ restorePageSelection(pageRows: T[], toggleFn: (row: T, selected: boolean) => void): void;
44
+ }
45
+ export {};