@a2simcode/ui 0.0.66 → 0.0.67

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.
@@ -53,6 +53,12 @@ export default {
53
53
  "description": "是否是表格单元格",
54
54
  "type": "boolean",
55
55
  "default": "false"
56
+ },
57
+ {
58
+ "name": "getTableProvide",
59
+ "description": "获取表格提供的方法",
60
+ "type": "func",
61
+ "default": "undefined"
56
62
  }
57
63
  ],
58
64
  "events": [
@@ -136,6 +136,36 @@ export default {
136
136
  "description": "编辑参数",
137
137
  "type": "EditConfigType",
138
138
  "default": "() => ({})"
139
+ },
140
+ {
141
+ "name": "emptyTipText",
142
+ "description": "空数据提示文本",
143
+ "type": "string",
144
+ "default": "'暂无数据'"
145
+ },
146
+ {
147
+ "name": "subColumns",
148
+ "description": "子表列配置",
149
+ "type": "any[]",
150
+ "default": "() => []"
151
+ },
152
+ {
153
+ "name": "isSubShowNumber",
154
+ "description": "是否显示子表序号",
155
+ "type": "boolean",
156
+ "default": "true"
157
+ },
158
+ {
159
+ "name": "subActions",
160
+ "description": "子表行内操作按钮配置",
161
+ "type": "ButtonCompType[]",
162
+ "default": "() => []"
163
+ },
164
+ {
165
+ "name": "loadChildren",
166
+ "description": "子表/树形数据懒加载函数(children 为 true 时触发)",
167
+ "type": "(record: Record<string, any>) => Promise<any[]>",
168
+ "default": "null"
139
169
  }
140
170
  ],
141
171
  "events": [
@@ -125,6 +125,40 @@
125
125
  </template>
126
126
  </Demo>
127
127
 
128
+ ## 子表
129
+
130
+ 通过 `subColumns` 属性配置子表列信息(Master-Detail)。
131
+
132
+ <Demo :source-code="tableSubTableCode">
133
+ <template #source>
134
+ <table-sub-table />
135
+ </template>
136
+ <template #description>
137
+ 传入 `subColumns` 数组配置子表列,配置格式与 `columns` 一致。
138
+ 默认情况下,插件会查找记录中的 `children` 字段作为子表数据。
139
+
140
+ 此外,还可以通过以下属性控制子表行为:
141
+ - `isSubShowNumber`: 是否显示子表序号,默认为 `true`。
142
+ - `subActions`: 配置子表行内操作按钮,格式与 `actions` 一致。
143
+ </template>
144
+ </Demo>
145
+
146
+ ## 子表异步数据加载(懒加载)
147
+
148
+ 当子表数据量较大时,可以将主表记录的 `children` 设置为 `true` 作为“需要懒加载”的标识;在用户展开该行时,组件会调用 `loadChildren(record)` 异步获取子表数据,并自动写入并展开。
149
+
150
+ - 触发条件:展开行且 `originData.children === true`
151
+ - 成功后:会把返回的数组设置为该行的子数据(下次再展开不会重复请求)
152
+
153
+ <Demo :source-code="tableSubTableLazyCode">
154
+ <template #source>
155
+ <table-sub-table-lazy />
156
+ </template>
157
+ <template #description>
158
+ 将主表行的 <code>children</code> 设置为 <code>true</code> 作为懒加载标识;展开该行时会调用 <code>loadChildren(record)</code> 获取子表数据并写入。
159
+ </template>
160
+ </Demo>
161
+
128
162
  ## 多选
129
163
 
130
164
  通过 `isMultiple` 属性开启多选。
@@ -238,6 +272,8 @@ import TableFrozenColumn from '../examples/table/frozen-column.vue'
238
272
  import TableHeightMode from '../examples/table/height-mode.vue'
239
273
  import TableTreeColumn from '../examples/table/tree-column.vue'
240
274
  import TableTreeData from '../examples/table/tree-data.vue'
275
+ import TableSubTable from '../examples/table/sub-table.vue'
276
+ import TableSubTableLazy from '../examples/table/sub-table-lazy.vue'
241
277
  import TableMultiple from '../examples/table/multiple.vue'
242
278
  import TableSingleSelection from '../examples/table/single-selection.vue'
243
279
  import TableFieldSelection from '../examples/table/field-selection.vue'
@@ -256,6 +292,8 @@ import tableFrozenColumnCode from '../examples/table/frozen-column.vue?raw'
256
292
  import tableHeightModeCode from '../examples/table/height-mode.vue?raw'
257
293
  import tableTreeColumnCode from '../examples/table/tree-column.vue?raw'
258
294
  import tableTreeDataCode from '../examples/table/tree-data.vue?raw'
295
+ import tableSubTableCode from '../examples/table/sub-table.vue?raw'
296
+ import tableSubTableLazyCode from '../examples/table/sub-table-lazy.vue?raw'
259
297
  import tableMultipleCode from '../examples/table/multiple.vue?raw'
260
298
  import tableSingleSelectionCode from '../examples/table/single-selection.vue?raw'
261
299
  import tableFieldSelectionCode from '../examples/table/field-selection.vue?raw'
@@ -340,16 +340,15 @@ const schema = [
340
340
  label: '',
341
341
  field: 'name',
342
342
  },
343
- getCompConfig: (data) => {
344
- console.log(data, 'getCompConfig')
343
+ getCompConfig: ({ row }) => {
345
344
  return {
346
- // prepend: h(
347
- // 'span',
348
- // {
349
- // style: { color: 'blue' },
350
- // },
351
- // row.type,
352
- // ),
345
+ prepend: h(
346
+ 'span',
347
+ {
348
+ style: { color: 'blue' },
349
+ },
350
+ row.type
351
+ ),
353
352
  }
354
353
  },
355
354
  },
@@ -359,6 +358,53 @@ const schema = [
359
358
  },
360
359
  ],
361
360
  },
361
+ {
362
+ type: 'j-table',
363
+ config: {
364
+ label: '规则格式',
365
+ field: 'ruleFormat',
366
+ heightMode: 'auto',
367
+ maxHeight: 300,
368
+ editConfig: { isAddBtn: true, isRemoveBtn: true },
369
+ },
370
+ children: [
371
+ {
372
+ type: 'j-select',
373
+ config: {
374
+ label: '前缀',
375
+ width: 120,
376
+ field: 'itemType',
377
+ dataType: 'options',
378
+ options: [
379
+ { value: '0', label: '自定义' },
380
+ { value: '1', label: '日期' },
381
+ { value: '2', label: '流水号' },
382
+ { value: '3', label: '公司' },
383
+ { value: '4', label: '部门' },
384
+ { value: '5', label: '用户' },
385
+ { value: '6', label: '表字段' },
386
+ ],
387
+ change: (data) => {
388
+ console.log(data)
389
+ data.row.Product = 'xxx'
390
+ },
391
+ },
392
+ },
393
+ {
394
+ id: 'Product',
395
+ config: {
396
+ label: 'Product Name',
397
+ width: 'auto',
398
+ align: 'left',
399
+ },
400
+ },
401
+ ],
402
+ // on: {
403
+ // change: (data: any) => {
404
+ // console.log(data, 'change')
405
+ // }
406
+ // }
407
+ },
362
408
  ]
363
409
 
364
410
  onMounted(() => {
@@ -0,0 +1,97 @@
1
+ <template>
2
+ <div style="position: relative; width: 100%; height: 500px">
3
+ <j-table
4
+ :columns="columns"
5
+ :records="records"
6
+ :sub-columns="subColumns"
7
+ :load-children="loadChildren"
8
+ />
9
+ </div>
10
+ </template>
11
+
12
+ <script setup lang="ts">
13
+ import { ref } from 'vue'
14
+
15
+ const columns = ref([
16
+ {
17
+ id: 'orderId',
18
+ config: {
19
+ label: 'Order ID',
20
+ width: 150,
21
+ },
22
+ },
23
+ {
24
+ id: 'customer',
25
+ config: {
26
+ label: 'Customer',
27
+ width: 'auto',
28
+ },
29
+ },
30
+ {
31
+ id: 'amount',
32
+ config: {
33
+ label: 'Amount',
34
+ width: 150,
35
+ },
36
+ },
37
+ ])
38
+
39
+ const records = ref([
40
+ {
41
+ orderId: 'ORD-001',
42
+ customer: 'John Doe',
43
+ amount: '$1,200',
44
+ children: [
45
+ { id: 'P001', product: 'Laptop', quantity: 1, price: '$1,000' },
46
+ { id: 'P002', product: 'Mouse', quantity: 2, price: '$50' },
47
+ ],
48
+ },
49
+ {
50
+ orderId: 'ORD-002',
51
+ customer: 'Jane Smith',
52
+ amount: '$800',
53
+ children: true,
54
+ },
55
+ ])
56
+
57
+ const subColumns = [
58
+ {
59
+ id: 'product',
60
+ config: {
61
+ label: 'Product',
62
+ width: 200,
63
+ },
64
+ },
65
+ {
66
+ id: 'quantity',
67
+ config: {
68
+ label: 'Quantity',
69
+ width: 100,
70
+ },
71
+ },
72
+ {
73
+ id: 'price',
74
+ config: {
75
+ label: 'Price',
76
+ width: 100,
77
+ },
78
+ },
79
+ ]
80
+
81
+ const fetchDetailFromServer = async (orderId: string) => {
82
+ await new Promise((resolve) => setTimeout(resolve, 600))
83
+
84
+ if (orderId === 'ORD-002') {
85
+ return [
86
+ { id: 'P003', product: 'Monitor', quantity: 1, price: '$300' },
87
+ { id: 'P004', product: 'Headset', quantity: 1, price: '$200' },
88
+ ]
89
+ }
90
+
91
+ return []
92
+ }
93
+
94
+ const loadChildren = async (record: any) => {
95
+ return await fetchDetailFromServer(record.orderId)
96
+ }
97
+ </script>
@@ -0,0 +1,103 @@
1
+ <template>
2
+ <div style="position: relative; width: 100%; height: 500px">
3
+ <j-table
4
+ :columns="columns"
5
+ :records="records"
6
+ :sub-columns="subColumns"
7
+ :is-sub-show-number="true"
8
+ :sub-actions="subActions"
9
+ />
10
+ </div>
11
+ </template>
12
+
13
+ <script setup lang="ts">
14
+ import { ref } from 'vue'
15
+
16
+ const columns = ref([
17
+ {
18
+ id: 'orderId',
19
+ config: {
20
+ label: 'Order ID',
21
+ width: 150,
22
+ },
23
+ },
24
+ {
25
+ id: 'customer',
26
+ config: {
27
+ label: 'Customer',
28
+ width: 'auto',
29
+ },
30
+ },
31
+ {
32
+ id: 'amount',
33
+ config: {
34
+ label: 'Amount',
35
+ width: 150,
36
+ },
37
+ },
38
+ ])
39
+
40
+ const records = ref([
41
+ {
42
+ orderId: 'ORD-001',
43
+ customer: 'John Doe',
44
+ amount: '$1,200',
45
+ children: [
46
+ { id: 'P001', product: 'Laptop', quantity: 1, price: '$1,000' },
47
+ { id: 'P002', product: 'Mouse', quantity: 2, price: '$50' },
48
+ { id: 'P003', product: 'Keyboard', quantity: 1, price: '$100' },
49
+ ],
50
+ },
51
+ {
52
+ orderId: 'ORD-002',
53
+ customer: 'Jane Smith',
54
+ amount: '$800',
55
+ children: [
56
+ { id: 'P004', product: 'Monitor', quantity: 2, price: '$300' },
57
+ { id: 'P005', product: 'Headset', quantity: 1, price: '$200' },
58
+ ],
59
+ },
60
+ {
61
+ orderId: 'ORD-003',
62
+ customer: 'Bob Johnson',
63
+ amount: '$150',
64
+ children: [
65
+ { id: 'P006', product: 'USB Hub', quantity: 3, price: '$50' },
66
+ ],
67
+ },
68
+ ])
69
+
70
+ const subColumns = [
71
+ {
72
+ id: 'product',
73
+ config: {
74
+ label: 'Product',
75
+ width: 200,
76
+ },
77
+ },
78
+ {
79
+ id: 'quantity',
80
+ config: {
81
+ label: 'Quantity',
82
+ width: 100,
83
+ },
84
+ },
85
+ {
86
+ id: 'price',
87
+ config: {
88
+ label: 'Price',
89
+ width: 100,
90
+ },
91
+ },
92
+ ]
93
+
94
+ const subActions = [
95
+ {
96
+ id: 'view',
97
+ label: '查看详情',
98
+ click: ({ data }) => {
99
+ console.log('查看详情:', data)
100
+ },
101
+ },
102
+ ]
103
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2simcode/ui",
3
- "version": "0.0.66",
3
+ "version": "0.0.67",
4
4
  "description": "A Vue 3 UI Component Library",
5
5
  "type": "module",
6
6
  "main": "./dist/simcode-ui.umd.js",
@@ -68,8 +68,9 @@
68
68
  "@codemirror/state": "^6.5.4",
69
69
  "@codemirror/view": "^6.39.13",
70
70
  "@iconify/vue": "^5.0.0",
71
- "@visactor/vtable": "^1.23.1",
72
- "@visactor/vtable-editors": "^1.23.1",
71
+ "@visactor/vtable": "^1.23.3",
72
+ "@visactor/vtable-editors": "^1.23.3",
73
+ "@visactor/vtable-plugins": "^1.23.3",
73
74
  "@vueuse/core": "^14.2.0",
74
75
  "async-validator": "^4.2.5",
75
76
  "codemirror": "^6.0.2",