@a2simcode/ui 0.0.282 → 0.0.284
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/dist/components/table-panel/index.d.ts +3 -0
- package/dist/components/table-panel/src/table-panel.vue.d.ts +1 -0
- package/dist/simcode-ui.es.js +4782 -4762
- package/dist/simcode-ui.umd.js +2 -2
- package/dist/stats.html +1 -1
- package/docs/components/table-panel.md +15 -0
- package/docs/examples/table-panel/pagination-select-state-key.vue +176 -0
- package/package.json +1 -1
|
@@ -175,6 +175,19 @@
|
|
|
175
175
|
| 仅显示选中模式 | 支持 | 支持 |
|
|
176
176
|
| 适用场景 | 需要获取选中数据,但操作在外部处理 | 需要批量操作功能 |
|
|
177
177
|
|
|
178
|
+
## 跨页选中
|
|
179
|
+
|
|
180
|
+
分页场景下,后端每次只返回当前页数据,需要在外部维护跨页选中状态。通过 `select-state-key` 指定选中状态字段,在 `loadData` 返回数据时根据外部维护的 ID 集合标记该字段,表格会自动根据此字段初始化每页的选中状态,无需手动调用选中 API。
|
|
181
|
+
|
|
182
|
+
<Demo :source-code="tablePanelPaginationSelectStateKeyCode">
|
|
183
|
+
<template #source>
|
|
184
|
+
<table-panel-pagination-select-state-key />
|
|
185
|
+
</template>
|
|
186
|
+
<template #description>
|
|
187
|
+
设置 <code>select-state-key="selected"</code>,在 <code>loadData</code> 中根据外部维护的 ID 集合为每条记录标记 <code>selected</code> 字段;通过 <code>@select</code> 事件携带的 <code>keys</code>(跨页选中的完整 ID 列表)整体同步回 ID 集合。程序化设置选中时可调用 <code>setSelectionById(ids)</code>,选中计数立即生效。
|
|
188
|
+
</template>
|
|
189
|
+
</Demo>
|
|
190
|
+
|
|
178
191
|
## 批量操作
|
|
179
192
|
|
|
180
193
|
批量操作是多选功能的一种扩展使用方式,详见上面的"多选功能"章节中的"带批处理按钮的多选"部分。
|
|
@@ -289,6 +302,7 @@ import TablePanelMultipleSelection from '../examples/table-panel/multiple-select
|
|
|
289
302
|
import TablePanelBatchOperations from '../examples/table-panel/batch-operations.vue'
|
|
290
303
|
import TablePanelSubTableLazy from '../examples/table-panel/sub-table-lazy.vue'
|
|
291
304
|
import TablePanelGetSelection from '../examples/table-panel/get-selection.vue'
|
|
305
|
+
import TablePanelPaginationSelectStateKey from '../examples/table-panel/pagination-select-state-key.vue'
|
|
292
306
|
import TablePanelButtonVisibility from '../examples/table-panel/button-visibility.vue'
|
|
293
307
|
import TablePanelModelValue from '../examples/table-panel/model-value.vue'
|
|
294
308
|
import TablePanelCard from '../examples/table-panel/card.vue'
|
|
@@ -305,6 +319,7 @@ import tablePanelMultipleSelectionCode from '../examples/table-panel/multiple-se
|
|
|
305
319
|
import tablePanelBatchOperationsCode from '../examples/table-panel/batch-operations.vue?raw'
|
|
306
320
|
import tablePanelSubTableLazyCode from '../examples/table-panel/sub-table-lazy.vue?raw'
|
|
307
321
|
import tablePanelGetSelectionCode from '../examples/table-panel/get-selection.vue?raw'
|
|
322
|
+
import tablePanelPaginationSelectStateKeyCode from '../examples/table-panel/pagination-select-state-key.vue?raw'
|
|
308
323
|
import tablePanelButtonVisibilityCode from '../examples/table-panel/button-visibility.vue?raw'
|
|
309
324
|
import tablePanelModelValueCode from '../examples/table-panel/model-value.vue?raw'
|
|
310
325
|
import tablePanelCardCode from '../examples/table-panel/card.vue?raw'
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div style="margin-bottom: 10px; display: flex; gap: 8px; align-items: center">
|
|
3
|
+
<j-button type="primary" label="获取跨页选中" @click="getAllSelected" />
|
|
4
|
+
<j-button type="primary" label="设置跨页选中" @click="setAllSelected" />
|
|
5
|
+
</div>
|
|
6
|
+
<div style="position: relative; width: 100%; height: 500px">
|
|
7
|
+
<j-table-panel
|
|
8
|
+
ref="tablePanelRef"
|
|
9
|
+
row-key="orderId"
|
|
10
|
+
is-multiple
|
|
11
|
+
select-state-key="selected"
|
|
12
|
+
:columns="columns"
|
|
13
|
+
:load-data="loadData"
|
|
14
|
+
:is-page="true"
|
|
15
|
+
:page-size="10"
|
|
16
|
+
@select="handleSelect"
|
|
17
|
+
/>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import { ref } from 'vue'
|
|
23
|
+
import { ElMessageBox } from 'element-plus'
|
|
24
|
+
|
|
25
|
+
const tablePanelRef = ref()
|
|
26
|
+
// 外部维护选中的 ID 集合
|
|
27
|
+
const selectedIds = ref(new Set<string>())
|
|
28
|
+
|
|
29
|
+
// 选中变化时用事件携带的 keys(跨页选中的完整 ID 列表)整体同步,清空选中时 keys 为空数组
|
|
30
|
+
const handleSelect = ({ keys }: { keys: string[] }) => {
|
|
31
|
+
selectedIds.value = new Set(keys)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 获取所有页选中的数据
|
|
35
|
+
const getAllSelected = () => {
|
|
36
|
+
const ids = Array.from(selectedIds.value)
|
|
37
|
+
console.log('跨页选中的 ID:', ids)
|
|
38
|
+
ElMessageBox.alert(`跨页共选中 ${ids.length} 条,ID 列表详情请看控制台`, '提示', {
|
|
39
|
+
confirmButtonText: '知道了',
|
|
40
|
+
type: 'info',
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 程序化设置跨页选中
|
|
45
|
+
const ids = ['ORD-000001', 'ORD-000030']
|
|
46
|
+
const setAllSelected = () => {
|
|
47
|
+
selectedIds.value = new Set(ids)
|
|
48
|
+
// 按 ID 设置跨页选中,选中计数立即生效(无需等待对应页数据加载)
|
|
49
|
+
tablePanelRef.value?.setSelectionById?.(ids)
|
|
50
|
+
// 刷新表格,loadData 会根据 selectedIds 标记 selected 字段
|
|
51
|
+
tablePanelRef.value?.refreshData?.()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const columns = ref([
|
|
55
|
+
{
|
|
56
|
+
id: 'orderId',
|
|
57
|
+
type: '',
|
|
58
|
+
config: {
|
|
59
|
+
label: '订单号',
|
|
60
|
+
width: 150,
|
|
61
|
+
filter: {
|
|
62
|
+
isSearchKeyword: true,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'customerId',
|
|
68
|
+
type: '',
|
|
69
|
+
config: {
|
|
70
|
+
label: '客户编号',
|
|
71
|
+
width: 120,
|
|
72
|
+
filter: {
|
|
73
|
+
isSearchKeyword: true,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'productName',
|
|
79
|
+
type: '',
|
|
80
|
+
config: {
|
|
81
|
+
label: '产品名称',
|
|
82
|
+
filter: {
|
|
83
|
+
isSearchKeyword: true,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: 'category',
|
|
89
|
+
type: '',
|
|
90
|
+
config: {
|
|
91
|
+
label: '类别',
|
|
92
|
+
width: 120,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'region',
|
|
97
|
+
type: '',
|
|
98
|
+
config: {
|
|
99
|
+
label: '区域',
|
|
100
|
+
width: 100,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: 'sales',
|
|
105
|
+
type: '',
|
|
106
|
+
config: {
|
|
107
|
+
label: '销售额',
|
|
108
|
+
width: 100,
|
|
109
|
+
align: 'right',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
])
|
|
113
|
+
|
|
114
|
+
// 生成模拟数据
|
|
115
|
+
const generateMockData = (count: number): Record<string, any>[] => {
|
|
116
|
+
const categories = ['办公用品', '科技产品', '家具']
|
|
117
|
+
const regions = ['华东', '华南', '华北', '华中', '西南', '西北']
|
|
118
|
+
const data: Record<string, any>[] = []
|
|
119
|
+
|
|
120
|
+
for (let i = 1; i <= count; i++) {
|
|
121
|
+
data.push({
|
|
122
|
+
orderId: `ORD-${String(i).padStart(6, '0')}`,
|
|
123
|
+
customerId: `CUS-${String(Math.floor(Math.random() * 10000)).padStart(5, '0')}`,
|
|
124
|
+
productName: `产品名称 ${i}`,
|
|
125
|
+
category: categories[Math.floor(Math.random() * categories.length)],
|
|
126
|
+
region: regions[Math.floor(Math.random() * regions.length)],
|
|
127
|
+
sales: (Math.random() * 10000).toFixed(2),
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return data
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const allData = generateMockData(100)
|
|
135
|
+
|
|
136
|
+
// 模拟后端分页接口
|
|
137
|
+
// 使用 select-state-key 时,需要在数据加载时标记 selected 字段
|
|
138
|
+
const loadData = async (params: Record<string, any>) => {
|
|
139
|
+
const hasKeyword = params.keyword?.value
|
|
140
|
+
const hasFilter = params.filter?.cond?.length > 0
|
|
141
|
+
|
|
142
|
+
if (hasKeyword || hasFilter) {
|
|
143
|
+
ElMessageBox.alert(
|
|
144
|
+
'查询过滤功能需要后端支持。在实际使用中,请将查询参数(keyword 和 filter)传递给后端接口进行数据过滤。',
|
|
145
|
+
'提示',
|
|
146
|
+
{
|
|
147
|
+
confirmButtonText: '知道了',
|
|
148
|
+
type: 'info',
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return new Promise((resolve) => {
|
|
154
|
+
setTimeout(() => {
|
|
155
|
+
const { pagination } = params
|
|
156
|
+
const { rows, page } = pagination || { rows: 10, page: 1 }
|
|
157
|
+
const start = (page - 1) * rows
|
|
158
|
+
const end = start + rows
|
|
159
|
+
|
|
160
|
+
// 获取当前页数据
|
|
161
|
+
const pageData = allData.slice(start, end)
|
|
162
|
+
|
|
163
|
+
// 根据 selectedIds 标记 selected 字段
|
|
164
|
+
// select-state-key="selected" 会让表格自动根据此字段初始化选中状态
|
|
165
|
+
pageData.forEach((item) => {
|
|
166
|
+
item.selected = selectedIds.value.has(item.orderId)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
resolve({
|
|
170
|
+
rows: pageData,
|
|
171
|
+
records: allData.length,
|
|
172
|
+
})
|
|
173
|
+
}, 300)
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
</script>
|