Commit 4c0f2038af62f25dae74a075ee4b8774828bac8f

Authored by Wit〆苗大
Committed by GitHub
1 parent d25dfcc7

perf(vxetable): 封装方法中加入可编辑表格和表单验证相关方法名,并在demo中增加新增和删除方法调用实现 (#2532)

* perf(vxetable): 封装方法中加入可编辑表格相关方法名,并在demo中增加新增和删除方法调用实现

* perf(vxetable): 封装方法中加入表单验证方法名

---------

Co-authored-by: 苗大 <caoshengmiao@hypergryph.com>
src/components/VxeTable/src/VxeBasicTable.tsx
... ... @@ -5,7 +5,14 @@ import { basicProps } from &#39;./props&#39;;
5 5 import { ignorePropKeys } from './const';
6 6 import { basicEmits } from './emits';
7 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 16 import { Grid as VxeGrid } from 'vxe-table';
10 17  
11 18 import { extendSlots } from '/@/utils/helper/tsxHelper';
... ... @@ -35,7 +42,9 @@ export default defineComponent({
35 42 };
36 43  
37 44 const gridExtendTableMethods = extendTableMethods(gridComponentMethodKeys) as GridMethods &
38   - TableMethods;
  45 + TableMethods &
  46 + TableEditMethods &
  47 + TableValidatorMethods;
39 48  
40 49 basicEmits.forEach((name) => {
41 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 9 // vxe-grid 部分
5 10 'dispatchEvent',
6 11 'commitProxy',
... ... @@ -126,6 +131,30 @@ export const gridComponentMethodKeys: (keyof GridMethods | keyof TableMethods)[]
126 131 'blur',
127 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 159 // xxx
131 160 ];
... ...
src/views/demo/table/VxeTable.vue
... ... @@ -14,11 +14,11 @@
14 14 </template>
15 15 <script lang="ts" setup>
16 16 import { reactive, ref } from 'vue';
17   - import { TableAction, ActionItem } from '/@/components/Table';
  17 + import { ActionItem, TableAction } from '/@/components/Table';
18 18 import { PageWrapper } from '/@/components/Page';
19 19 import { useMessage } from '/@/hooks/web/useMessage';
20 20 import { vxeTableColumns, vxeTableFormSchema } from './tableData';
21   - import { VxeBasicTable, BasicTableProps, VxeGridInstance } from '/@/components/VxeTable';
  21 + import { BasicTableProps, VxeBasicTable, VxeGridInstance } from '/@/components/VxeTable';
22 22 import { demoListApi } from '/@/api/demo/table';
23 23  
24 24 const { createMessage } = useMessage();
... ... @@ -32,7 +32,7 @@
32 32 toolbarConfig: {
33 33 buttons: [
34 34 {
35   - content: '自定义按钮',
  35 + content: '在第一行新增',
36 36 buttonRender: {
37 37 name: 'AButton',
38 38 props: {
... ... @@ -40,7 +40,22 @@
40 40 },
41 41 events: {
42 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 77 });
63 78 },
64 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 101 color: 'error',
88 102 popConfirm: {
89 103 title: '是否确认删除',
90   - confirm: () => {},
  104 + confirm: () => {
  105 + tableRef.value?.remove(record);
  106 + },
91 107 },
92 108 },
93 109 ];
... ...