@yidun/antd-super-table 0.1.8 → 0.1.10
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.
- package/README.md +21 -13
- package/dist/index.js +1378 -1368
- package/dist/interface.d.ts +6 -0
- package/dist/utils/index.d.ts +1 -0
- package/example/index.vue +78 -1
- package/example/tableColumns.ts +11 -0
- package/package.json +1 -1
package/dist/interface.d.ts
CHANGED
|
@@ -144,6 +144,9 @@ export interface SuperTableColumn {
|
|
|
144
144
|
/** 表格内容解析用到的组件对应的props */
|
|
145
145
|
props?: Record<string, any> | ((row: SuperTableDataItem, index: number) => Record<string, any>)
|
|
146
146
|
|
|
147
|
+
/** 自定义单元格插槽名,命中后优先使用具名插槽渲染 */
|
|
148
|
+
slotName?: string
|
|
149
|
+
|
|
147
150
|
/** 是否可复制 */
|
|
148
151
|
copyable?: boolean
|
|
149
152
|
|
|
@@ -428,6 +431,9 @@ export interface SuperTableSlots {
|
|
|
428
431
|
tableFoot?: () => any
|
|
429
432
|
/** 展开行内容插槽 */
|
|
430
433
|
expandedRowRender?: (props: { record: any }) => any
|
|
434
|
+
|
|
435
|
+
/** 自定义单元格具名插槽 */
|
|
436
|
+
[slotName: string]: ((props?: Record<string, any>) => any) | undefined
|
|
431
437
|
}
|
|
432
438
|
|
|
433
439
|
/**
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export declare const initTableColumns: (columns: SuperTableColumn[]) => {
|
|
|
52
52
|
content?: string | ((row: import("..").SuperTableDataItem, index: number) => any);
|
|
53
53
|
tooltip?: string | boolean | ((row: import("..").SuperTableDataItem, index: number) => string);
|
|
54
54
|
props?: Record<string, any> | ((row: import("..").SuperTableDataItem, index: number) => Record<string, any>);
|
|
55
|
+
slotName?: string;
|
|
55
56
|
copyable?: boolean;
|
|
56
57
|
fixed?: import("..").SuperTableColumnFixedType;
|
|
57
58
|
sorter?: boolean | ((a: import("..").SuperTableDataItem, b: import("..").SuperTableDataItem) => number);
|
package/example/index.vue
CHANGED
|
@@ -14,6 +14,30 @@ const tableRef = ref<InstanceType<typeof SuperTable>>()
|
|
|
14
14
|
// 查询条件配置 - 改为响应式
|
|
15
15
|
const formItems = ref<any[]>(createFormItems())
|
|
16
16
|
|
|
17
|
+
function onTableChange(pagination: any, filters: any, sorter: any, extra: any) {
|
|
18
|
+
// sorter 可能是对象或数组(多列排序)
|
|
19
|
+
const sorters = Array.isArray(sorter) ? sorter : [sorter]
|
|
20
|
+
const activeSorters = sorters.filter(s => s?.order)
|
|
21
|
+
if (activeSorters.length > 0) {
|
|
22
|
+
console.log('sort-change:', {
|
|
23
|
+
sorter,
|
|
24
|
+
activeSorters,
|
|
25
|
+
pagination,
|
|
26
|
+
filters,
|
|
27
|
+
extra,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function onResizeColumn(width: number, column: any) {
|
|
33
|
+
console.log('resize-column:', {
|
|
34
|
+
width,
|
|
35
|
+
key: column?.key,
|
|
36
|
+
title: column?.title,
|
|
37
|
+
column,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
17
41
|
// 表头配置
|
|
18
42
|
const tableColumns: any = createTableColumns({
|
|
19
43
|
onDelete,
|
|
@@ -161,7 +185,7 @@ const handleClearCache = () => {
|
|
|
161
185
|
content: '确定要清空所有 localStorage 缓存吗?此操作不可恢复。',
|
|
162
186
|
onOk: () => {
|
|
163
187
|
try {
|
|
164
|
-
localStorage.clear()
|
|
188
|
+
window.localStorage.clear()
|
|
165
189
|
Modal.success({
|
|
166
190
|
title: '成功',
|
|
167
191
|
content: '缓存已清空,页面将自动刷新',
|
|
@@ -380,6 +404,8 @@ onMounted(() => {
|
|
|
380
404
|
},
|
|
381
405
|
}"
|
|
382
406
|
@form-item-change="onFormItemChange"
|
|
407
|
+
@change="onTableChange"
|
|
408
|
+
@resize-column="onResizeColumn"
|
|
383
409
|
>
|
|
384
410
|
<template
|
|
385
411
|
v-if="setting.showSceneAddonBefore"
|
|
@@ -417,6 +443,29 @@ onMounted(() => {
|
|
|
417
443
|
>
|
|
418
444
|
<div :class="$style.block">tableFoot</div>
|
|
419
445
|
</template>
|
|
446
|
+
<template #customBodyCell="{ record, index }">
|
|
447
|
+
<div :class="$style.customCellList">
|
|
448
|
+
<div :class="$style.customCellHeader">
|
|
449
|
+
<a-tag color="purple">插槽</a-tag>
|
|
450
|
+
<span :class="$style.customCellTitle">第 {{ index + 1 }} 行</span>
|
|
451
|
+
</div>
|
|
452
|
+
<div :class="$style.customCellItem">
|
|
453
|
+
<a-badge status="processing" />
|
|
454
|
+
<span :class="$style.customCellText">{{ record?.text || '-' }}</span>
|
|
455
|
+
<a-button
|
|
456
|
+
type="link"
|
|
457
|
+
size="small"
|
|
458
|
+
>
|
|
459
|
+
复制
|
|
460
|
+
</a-button>
|
|
461
|
+
</div>
|
|
462
|
+
<div :class="$style.customCellItem">
|
|
463
|
+
<a-badge status="success" />
|
|
464
|
+
<span :class="$style.customCellText">元素 B ⭐</span>
|
|
465
|
+
<a-tag color="green">生效</a-tag>
|
|
466
|
+
</div>
|
|
467
|
+
</div>
|
|
468
|
+
</template>
|
|
420
469
|
</super-table>
|
|
421
470
|
</div>
|
|
422
471
|
</template>
|
|
@@ -438,4 +487,32 @@ onMounted(() => {
|
|
|
438
487
|
.form {
|
|
439
488
|
padding: 16px;
|
|
440
489
|
}
|
|
490
|
+
|
|
491
|
+
.customCellList {
|
|
492
|
+
display: flex;
|
|
493
|
+
flex-direction: column;
|
|
494
|
+
gap: 6px;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.customCellHeader {
|
|
498
|
+
display: flex;
|
|
499
|
+
align-items: center;
|
|
500
|
+
gap: 8px;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.customCellTitle {
|
|
504
|
+
color: #595959;
|
|
505
|
+
font-size: 12px;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
.customCellItem {
|
|
509
|
+
display: flex;
|
|
510
|
+
align-items: center;
|
|
511
|
+
gap: 8px;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
.customCellText {
|
|
515
|
+
flex: 1;
|
|
516
|
+
color: #262626;
|
|
517
|
+
}
|
|
441
518
|
</style>
|
package/example/tableColumns.ts
CHANGED
|
@@ -17,6 +17,9 @@ export const createTableColumns = (options: {
|
|
|
17
17
|
content: 'id',
|
|
18
18
|
width: 80,
|
|
19
19
|
fixed: 'left',
|
|
20
|
+
// column 示例:开启 antd 排序(配合 example/index.vue 的 @change 打印 sort 日志)
|
|
21
|
+
sorter: (a: any, b: any) => Number(a?.id ?? 0) - Number(b?.id ?? 0),
|
|
22
|
+
sortDirections: ['ascend', 'descend'],
|
|
20
23
|
},
|
|
21
24
|
{
|
|
22
25
|
key: 'index',
|
|
@@ -132,6 +135,14 @@ export const createTableColumns = (options: {
|
|
|
132
135
|
},
|
|
133
136
|
},
|
|
134
137
|
},
|
|
138
|
+
{
|
|
139
|
+
key: 'customSlotCell',
|
|
140
|
+
title: '自定义插槽',
|
|
141
|
+
type: 'text',
|
|
142
|
+
content: 'text',
|
|
143
|
+
width: 180,
|
|
144
|
+
slotName: 'customBodyCell',
|
|
145
|
+
},
|
|
135
146
|
{
|
|
136
147
|
key: 'status',
|
|
137
148
|
title: '状态',
|