@a2simcode/ui 0.0.285 → 0.0.287

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.
@@ -188,6 +188,19 @@
188
188
  </template>
189
189
  </Demo>
190
190
 
191
+ ## 选中数据远程拉取
192
+
193
+ 跨页选中时,未加载页的选中记录只有 ID、没有完整数据。开启 `remote-selection` 后,点击「仅选中」会按选中 ID 调用 `loadData`(参数携带 `ids` 逗号拼接的 ID 列表与 `field` rowKey 字段名)从接口拉取完整选中数据,保证未加载页的选中记录也能完整展示。需同时配置 `row-key`、`is-page` 和 `load-data`。
194
+
195
+ <Demo :source-code="tablePanelRemoteSelectionCode">
196
+ <template #source>
197
+ <table-panel-remote-selection />
198
+ </template>
199
+ <template #description>
200
+ 点击「设置跨页选中」选中第 1 页和第 3 页的各一条记录,再点击右上角「仅选中」:开启 <code>remote-selection</code> 后会携带 <code>ids</code> 与 <code>field</code> 调用 <code>loadData</code> 拉取完整选中数据,两条记录都能展示(未开启时只能展示已加载页的选中记录)。
201
+ </template>
202
+ </Demo>
203
+
191
204
  ## 批量操作
192
205
 
193
206
  批量操作是多选功能的一种扩展使用方式,详见上面的"多选功能"章节中的"带批处理按钮的多选"部分。
@@ -303,6 +316,7 @@ import TablePanelBatchOperations from '../examples/table-panel/batch-operations.
303
316
  import TablePanelSubTableLazy from '../examples/table-panel/sub-table-lazy.vue'
304
317
  import TablePanelGetSelection from '../examples/table-panel/get-selection.vue'
305
318
  import TablePanelPaginationSelectStateKey from '../examples/table-panel/pagination-select-state-key.vue'
319
+ import TablePanelRemoteSelection from '../examples/table-panel/remote-selection.vue'
306
320
  import TablePanelButtonVisibility from '../examples/table-panel/button-visibility.vue'
307
321
  import TablePanelModelValue from '../examples/table-panel/model-value.vue'
308
322
  import TablePanelCard from '../examples/table-panel/card.vue'
@@ -320,6 +334,7 @@ import tablePanelBatchOperationsCode from '../examples/table-panel/batch-operati
320
334
  import tablePanelSubTableLazyCode from '../examples/table-panel/sub-table-lazy.vue?raw'
321
335
  import tablePanelGetSelectionCode from '../examples/table-panel/get-selection.vue?raw'
322
336
  import tablePanelPaginationSelectStateKeyCode from '../examples/table-panel/pagination-select-state-key.vue?raw'
337
+ import tablePanelRemoteSelectionCode from '../examples/table-panel/remote-selection.vue?raw'
323
338
  import tablePanelButtonVisibilityCode from '../examples/table-panel/button-visibility.vue?raw'
324
339
  import tablePanelModelValueCode from '../examples/table-panel/model-value.vue?raw'
325
340
  import tablePanelCardCode from '../examples/table-panel/card.vue?raw'
@@ -0,0 +1,159 @@
1
+ <template>
2
+ <div style="margin-bottom: 10px; display: flex; gap: 8px; align-items: center">
3
+ <j-button type="primary" label="设置跨页选中" @click="setAllSelected" />
4
+ <span style="color: #606266; font-size: 13px"
5
+ >设置跨页选中后,点击表格右上角「仅选中」按钮,将按选中 ID 从接口拉取完整选中数据</span
6
+ >
7
+ </div>
8
+ <div style="position: relative; width: 100%; height: 500px">
9
+ <j-table-panel
10
+ ref="tablePanelRef"
11
+ row-key="orderId"
12
+ is-multiple
13
+ select-state-key="selected"
14
+ remote-selection
15
+ :columns="columns"
16
+ :load-data="loadData"
17
+ :is-page="true"
18
+ :page-size="10"
19
+ @select="handleSelect"
20
+ />
21
+ </div>
22
+ </template>
23
+
24
+ <script setup lang="ts">
25
+ import { ref } from 'vue'
26
+
27
+ const tablePanelRef = ref()
28
+ // 外部维护选中的 ID 集合
29
+ const selectedIds = ref(new Set<string>())
30
+
31
+ // 选中变化时用事件携带的 keys(跨页选中的完整 ID 列表)整体同步
32
+ const handleSelect = ({ keys }: { keys: string[] }) => {
33
+ selectedIds.value = new Set(keys)
34
+ }
35
+
36
+ // 程序化设置跨页选中(ORD-000001 在第 1 页,ORD-000030 在第 3 页)
37
+ const ids = ['ORD-000001', 'ORD-000030']
38
+ const setAllSelected = () => {
39
+ selectedIds.value = new Set(ids)
40
+ // 按 ID 设置跨页选中,选中计数立即生效(无需等待对应页数据加载)
41
+ tablePanelRef.value?.setSelectionById?.(ids)
42
+ // 刷新表格,loadData 会根据 selectedIds 标记 selected 字段
43
+ tablePanelRef.value?.refreshData?.()
44
+ }
45
+
46
+ const columns = ref([
47
+ {
48
+ id: 'orderId',
49
+ type: '',
50
+ config: {
51
+ label: '订单号',
52
+ width: 150,
53
+ },
54
+ },
55
+ {
56
+ id: 'customerId',
57
+ type: '',
58
+ config: {
59
+ label: '客户编号',
60
+ width: 120,
61
+ },
62
+ },
63
+ {
64
+ id: 'productName',
65
+ type: '',
66
+ config: {
67
+ label: '产品名称',
68
+ },
69
+ },
70
+ {
71
+ id: 'category',
72
+ type: '',
73
+ config: {
74
+ label: '类别',
75
+ width: 120,
76
+ },
77
+ },
78
+ {
79
+ id: 'region',
80
+ type: '',
81
+ config: {
82
+ label: '区域',
83
+ width: 100,
84
+ },
85
+ },
86
+ {
87
+ id: 'sales',
88
+ type: '',
89
+ config: {
90
+ label: '销售额',
91
+ width: 100,
92
+ align: 'right',
93
+ },
94
+ },
95
+ ])
96
+
97
+ // 生成模拟数据
98
+ const generateMockData = (count: number): Record<string, any>[] => {
99
+ const categories = ['办公用品', '科技产品', '家具']
100
+ const regions = ['华东', '华南', '华北', '华中', '西南', '西北']
101
+ const data: Record<string, any>[] = []
102
+
103
+ for (let i = 1; i <= count; i++) {
104
+ data.push({
105
+ orderId: `ORD-${String(i).padStart(6, '0')}`,
106
+ customerId: `CUS-${String(Math.floor(Math.random() * 10000)).padStart(5, '0')}`,
107
+ productName: `产品名称 ${i}`,
108
+ category: categories[Math.floor(Math.random() * categories.length)],
109
+ region: regions[Math.floor(Math.random() * regions.length)],
110
+ sales: (Math.random() * 10000).toFixed(2),
111
+ })
112
+ }
113
+
114
+ return data
115
+ }
116
+
117
+ const allData = generateMockData(100)
118
+
119
+ // 模拟后端分页接口
120
+ // 开启 remote-selection 时,点击「仅选中」会携带 ids(选中 ID 逗号拼接)与 field(rowKey 字段名)调用本方法,按 ID 返回完整选中数据
121
+ const loadData = async (params: Record<string, any>) => {
122
+ return new Promise((resolve) => {
123
+ setTimeout(() => {
124
+ // 仅选中(remote-selection):按 ids 返回完整选中数据,实际使用中由后端按 ID 列表查询
125
+ if (params.ids) {
126
+ const idSet = new Set(String(params.ids).split(','))
127
+ const selectedData = allData.filter((item) => idSet.has(item[params.field]))
128
+ selectedData.forEach((item) => {
129
+ item.selected = true
130
+ })
131
+ resolve({
132
+ rows: selectedData,
133
+ records: selectedData.length,
134
+ })
135
+ return
136
+ }
137
+
138
+ const { pagination } = params
139
+ const { rows, page } = pagination || { rows: 10, page: 1 }
140
+ const start = (page - 1) * rows
141
+ const end = start + rows
142
+
143
+ // 获取当前页数据
144
+ const pageData = allData.slice(start, end)
145
+
146
+ // 根据 selectedIds 标记 selected 字段
147
+ // select-state-key="selected" 会让表格自动根据此字段初始化选中状态
148
+ pageData.forEach((item) => {
149
+ item.selected = selectedIds.value.has(item.orderId)
150
+ })
151
+
152
+ resolve({
153
+ rows: pageData,
154
+ records: allData.length,
155
+ })
156
+ }, 300)
157
+ })
158
+ }
159
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2simcode/ui",
3
- "version": "0.0.285",
3
+ "version": "0.0.287",
4
4
  "description": "A Vue 3 UI Component Library",
5
5
  "type": "module",
6
6
  "main": "./dist/simcode-ui.umd.js",