Commit 4c0f2038af62f25dae74a075ee4b8774828bac8f
Committed by
GitHub
1 parent
d25dfcc7
perf(vxetable): 封装方法中加入可编辑表格和表单验证相关方法名,并在demo中增加新增和删除方法调用实现 (#2532)
* perf(vxetable): 封装方法中加入可编辑表格相关方法名,并在demo中增加新增和删除方法调用实现 * perf(vxetable): 封装方法中加入表单验证方法名 --------- Co-authored-by: 苗大 <caoshengmiao@hypergryph.com>
Showing
3 changed files
with
65 additions
and
11 deletions
src/components/VxeTable/src/VxeBasicTable.tsx
@@ -5,7 +5,14 @@ import { basicProps } from './props'; | @@ -5,7 +5,14 @@ import { basicProps } from './props'; | ||
5 | import { ignorePropKeys } from './const'; | 5 | import { ignorePropKeys } from './const'; |
6 | import { basicEmits } from './emits'; | 6 | import { basicEmits } from './emits'; |
7 | import XEUtils from 'xe-utils'; | 7 | import XEUtils from 'xe-utils'; |
8 | -import type { VxeGridInstance, VxeGridEventProps, GridMethods, TableMethods } from 'vxe-table'; | 8 | +import type { |
9 | + VxeGridInstance, | ||
10 | + VxeGridEventProps, | ||
11 | + GridMethods, | ||
12 | + TableMethods, | ||
13 | + TableEditMethods, | ||
14 | + TableValidatorMethods, | ||
15 | +} from 'vxe-table'; | ||
9 | import { Grid as VxeGrid } from 'vxe-table'; | 16 | import { Grid as VxeGrid } from 'vxe-table'; |
10 | 17 | ||
11 | import { extendSlots } from '/@/utils/helper/tsxHelper'; | 18 | import { extendSlots } from '/@/utils/helper/tsxHelper'; |
@@ -35,7 +42,9 @@ export default defineComponent({ | @@ -35,7 +42,9 @@ export default defineComponent({ | ||
35 | }; | 42 | }; |
36 | 43 | ||
37 | const gridExtendTableMethods = extendTableMethods(gridComponentMethodKeys) as GridMethods & | 44 | const gridExtendTableMethods = extendTableMethods(gridComponentMethodKeys) as GridMethods & |
38 | - TableMethods; | 45 | + TableMethods & |
46 | + TableEditMethods & | ||
47 | + TableValidatorMethods; | ||
39 | 48 | ||
40 | basicEmits.forEach((name) => { | 49 | basicEmits.forEach((name) => { |
41 | const type = XEUtils.camelCase(`on-${name}`) as keyof VxeGridEventProps; | 50 | const type = XEUtils.camelCase(`on-${name}`) as keyof VxeGridEventProps; |
src/components/VxeTable/src/methods.ts
1 | -import { GridMethods, TableMethods } from 'vxe-table'; | 1 | +import { GridMethods, TableMethods, TableEditMethods, TableValidatorMethods } from 'vxe-table'; |
2 | 2 | ||
3 | -export const gridComponentMethodKeys: (keyof GridMethods | keyof TableMethods)[] = [ | 3 | +export const gridComponentMethodKeys: ( |
4 | + | keyof GridMethods | ||
5 | + | keyof TableMethods | ||
6 | + | keyof TableEditMethods | ||
7 | + | keyof TableValidatorMethods | ||
8 | +)[] = [ | ||
4 | // vxe-grid 部分 | 9 | // vxe-grid 部分 |
5 | 'dispatchEvent', | 10 | 'dispatchEvent', |
6 | 'commitProxy', | 11 | 'commitProxy', |
@@ -126,6 +131,30 @@ export const gridComponentMethodKeys: (keyof GridMethods | keyof TableMethods)[] | @@ -126,6 +131,30 @@ export const gridComponentMethodKeys: (keyof GridMethods | keyof TableMethods)[] | ||
126 | 'blur', | 131 | 'blur', |
127 | 'connect', | 132 | 'connect', |
128 | 133 | ||
134 | + // vxe-table-edit部分 | ||
135 | + 'insert', | ||
136 | + 'insertAt', | ||
137 | + 'remove', | ||
138 | + 'removeCheckboxRow', | ||
139 | + 'removeRadioRow', | ||
140 | + 'removeCurrentRow', | ||
141 | + 'getRecordset', | ||
142 | + 'getInsertRecords', | ||
143 | + 'getRemoveRecords', | ||
144 | + 'getUpdateRecords', | ||
145 | + 'getEditRecord', | ||
146 | + 'getSelectedCell', | ||
147 | + 'clearSelected', | ||
148 | + 'isEditByRow', | ||
149 | + 'setEditRow', | ||
150 | + 'setEditCell', | ||
151 | + 'setSelectCell', | ||
152 | + | ||
153 | + // vxe-table-validator | ||
154 | + 'clearValidate', | ||
155 | + 'fullValidate', | ||
156 | + 'validate', | ||
157 | + | ||
129 | //... 如有缺少在此处追加 | 158 | //... 如有缺少在此处追加 |
130 | // xxx | 159 | // xxx |
131 | ]; | 160 | ]; |
src/views/demo/table/VxeTable.vue
@@ -14,11 +14,11 @@ | @@ -14,11 +14,11 @@ | ||
14 | </template> | 14 | </template> |
15 | <script lang="ts" setup> | 15 | <script lang="ts" setup> |
16 | import { reactive, ref } from 'vue'; | 16 | import { reactive, ref } from 'vue'; |
17 | - import { TableAction, ActionItem } from '/@/components/Table'; | 17 | + import { ActionItem, TableAction } from '/@/components/Table'; |
18 | import { PageWrapper } from '/@/components/Page'; | 18 | import { PageWrapper } from '/@/components/Page'; |
19 | import { useMessage } from '/@/hooks/web/useMessage'; | 19 | import { useMessage } from '/@/hooks/web/useMessage'; |
20 | import { vxeTableColumns, vxeTableFormSchema } from './tableData'; | 20 | import { vxeTableColumns, vxeTableFormSchema } from './tableData'; |
21 | - import { VxeBasicTable, BasicTableProps, VxeGridInstance } from '/@/components/VxeTable'; | 21 | + import { BasicTableProps, VxeBasicTable, VxeGridInstance } from '/@/components/VxeTable'; |
22 | import { demoListApi } from '/@/api/demo/table'; | 22 | import { demoListApi } from '/@/api/demo/table'; |
23 | 23 | ||
24 | const { createMessage } = useMessage(); | 24 | const { createMessage } = useMessage(); |
@@ -32,7 +32,7 @@ | @@ -32,7 +32,7 @@ | ||
32 | toolbarConfig: { | 32 | toolbarConfig: { |
33 | buttons: [ | 33 | buttons: [ |
34 | { | 34 | { |
35 | - content: '自定义按钮', | 35 | + content: '在第一行新增', |
36 | buttonRender: { | 36 | buttonRender: { |
37 | name: 'AButton', | 37 | name: 'AButton', |
38 | props: { | 38 | props: { |
@@ -40,7 +40,22 @@ | @@ -40,7 +40,22 @@ | ||
40 | }, | 40 | }, |
41 | events: { | 41 | events: { |
42 | click: () => { | 42 | click: () => { |
43 | - createMessage.success('点击了自定义按钮'); | 43 | + tableRef.value?.insert({ name: '新增的' }); |
44 | + createMessage.success('新增成功'); | ||
45 | + }, | ||
46 | + }, | ||
47 | + }, | ||
48 | + }, | ||
49 | + { | ||
50 | + content: '在最后一行新增', | ||
51 | + buttonRender: { | ||
52 | + name: 'AButton', | ||
53 | + props: { | ||
54 | + type: 'warning', | ||
55 | + }, | ||
56 | + events: { | ||
57 | + click: () => { | ||
58 | + tableRef.value?.insertAt({ name: '新增的' }, -1); | ||
44 | }, | 59 | }, |
45 | }, | 60 | }, |
46 | }, | 61 | }, |
@@ -62,8 +77,7 @@ | @@ -62,8 +77,7 @@ | ||
62 | }); | 77 | }); |
63 | }, | 78 | }, |
64 | queryAll: async ({ form }) => { | 79 | queryAll: async ({ form }) => { |
65 | - const data = await demoListApi(form); | ||
66 | - return data; | 80 | + return await demoListApi(form); |
67 | }, | 81 | }, |
68 | }, | 82 | }, |
69 | }, | 83 | }, |
@@ -87,7 +101,9 @@ | @@ -87,7 +101,9 @@ | ||
87 | color: 'error', | 101 | color: 'error', |
88 | popConfirm: { | 102 | popConfirm: { |
89 | title: '是否确认删除', | 103 | title: '是否确认删除', |
90 | - confirm: () => {}, | 104 | + confirm: () => { |
105 | + tableRef.value?.remove(record); | ||
106 | + }, | ||
91 | }, | 107 | }, |
92 | }, | 108 | }, |
93 | ]; | 109 | ]; |