@a2simcode/ui 0.0.226 → 0.0.228

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.
@@ -1,5 +1,11 @@
1
1
  export default {
2
2
  "props": [
3
+ {
4
+ "name": "modelValue",
5
+ "description": "输入值【作为表单的编辑表格使用】",
6
+ "type": "Record<string, any>[]",
7
+ "default": "() => []"
8
+ },
3
9
  {
4
10
  "name": "columns",
5
11
  "description": "表格列配置",
@@ -179,6 +179,19 @@
179
179
  </template>
180
180
  </Demo>
181
181
 
182
+ ## v-model 外部数据驱动
183
+
184
+ 通过 `v-model` 绑定外部数据,当绑定的数据发生变化时,表格会自动刷新。适用于将表格作为表单编辑组件使用、或需要外部控制表格数据的场景。
185
+
186
+ <Demo :source-code="tablePanelModelValueCode">
187
+ <template #source>
188
+ <table-panel-model-value />
189
+ </template>
190
+ <template #description>
191
+ 使用 `v-model` 绑定数据源,外部修改绑定值后表格自动重新加载。示例中通过按钮操作(刷新、新增、清空)演示 `modelValue` 变化驱动表格更新的效果。
192
+ </template>
193
+ </Demo>
194
+
182
195
  ## 自定义渲染(掩码示例)
183
196
 
184
197
  通过 `render-v-node` 可以跳过内置表格渲染,使用 VNode 自定义每条记录的展示方式。下面示例用卡片布局展示行数据,并支持一键切换手机号/邮箱的掩码显示。
@@ -250,6 +263,7 @@ import TablePanelBatchOperations from '../examples/table-panel/batch-operations.
250
263
  import TablePanelSubTableLazy from '../examples/table-panel/sub-table-lazy.vue'
251
264
  import TablePanelGetSelection from '../examples/table-panel/get-selection.vue'
252
265
  import TablePanelButtonVisibility from '../examples/table-panel/button-visibility.vue'
266
+ import TablePanelModelValue from '../examples/table-panel/model-value.vue'
253
267
  import TablePanelMask from '../examples/table-panel/mask.vue'
254
268
  import tablePanelApi from './meta/table-panel'
255
269
 
@@ -263,5 +277,6 @@ import tablePanelBatchOperationsCode from '../examples/table-panel/batch-operati
263
277
  import tablePanelSubTableLazyCode from '../examples/table-panel/sub-table-lazy.vue?raw'
264
278
  import tablePanelGetSelectionCode from '../examples/table-panel/get-selection.vue?raw'
265
279
  import tablePanelButtonVisibilityCode from '../examples/table-panel/button-visibility.vue?raw'
280
+ import tablePanelModelValueCode from '../examples/table-panel/model-value.vue?raw'
266
281
  import tablePanelMaskCode from '../examples/table-panel/mask.vue?raw'
267
282
  </script>
@@ -0,0 +1,87 @@
1
+ <template>
2
+ <div>
3
+ <div style="margin-bottom: 12px">
4
+ <el-button type="primary" @click="refreshData">刷新数据</el-button>
5
+ <el-button @click="addRecord">新增一条记录</el-button>
6
+ <el-button @click="clearData">清空数据</el-button>
7
+ <span style="margin-left: 12px; color: #999">当前数据条数: {{ tableData.length }}</span>
8
+ </div>
9
+ <div style="position: relative; width: 100%; height: 400px">
10
+ <j-table-panel v-model="tableData" row-key="id" :columns="columns" />
11
+ </div>
12
+ </div>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import { ref } from 'vue'
17
+
18
+ const columns = ref([
19
+ {
20
+ id: 'id',
21
+ type: '',
22
+ config: {
23
+ label: 'ID',
24
+ width: 80,
25
+ },
26
+ },
27
+ {
28
+ id: 'name',
29
+ type: '',
30
+ config: {
31
+ label: '姓名',
32
+ width: 120,
33
+ },
34
+ },
35
+ {
36
+ id: 'department',
37
+ type: '',
38
+ config: {
39
+ label: '部门',
40
+ width: 120,
41
+ },
42
+ },
43
+ {
44
+ id: 'position',
45
+ type: '',
46
+ config: {
47
+ label: '职位',
48
+ },
49
+ },
50
+ ])
51
+
52
+ let nextId = 6
53
+
54
+ const initialData = [
55
+ { id: 1, name: '张三', department: '技术部', position: '前端工程师' },
56
+ { id: 2, name: '李四', department: '产品部', position: '产品经理' },
57
+ { id: 3, name: '王五', department: '设计部', position: 'UI设计师' },
58
+ { id: 4, name: '赵六', department: '技术部', position: '后端工程师' },
59
+ { id: 5, name: '孙七', department: '运营部', position: '运营专员' },
60
+ ]
61
+
62
+ const tableData = ref<Record<string, any>[]>([...initialData])
63
+
64
+ const refreshData = () => {
65
+ // 重新赋值触发 modelValue 变化 -> 自动刷新表格
66
+ tableData.value = [...initialData]
67
+ nextId = 6
68
+ }
69
+
70
+ const addRecord = () => {
71
+ const departments = ['技术部', '产品部', '设计部', '运营部']
72
+ const positions = ['工程师', '经理', '专员', '实习生']
73
+ tableData.value = [
74
+ ...tableData.value,
75
+ {
76
+ id: nextId++,
77
+ name: `员工${nextId - 1}`,
78
+ department: departments[Math.floor(Math.random() * departments.length)],
79
+ position: positions[Math.floor(Math.random() * positions.length)],
80
+ },
81
+ ]
82
+ }
83
+
84
+ const clearData = () => {
85
+ tableData.value = []
86
+ }
87
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2simcode/ui",
3
- "version": "0.0.226",
3
+ "version": "0.0.228",
4
4
  "description": "A Vue 3 UI Component Library",
5
5
  "type": "module",
6
6
  "main": "./dist/simcode-ui.umd.js",