Commit 6844f69c2068807eb0bd876d30f7b7de447c841a

Authored by WYH
Committed by GitHub
1 parent 057b8263

fix: 修复demo中formTable几个空指针报错和selectedRowKeys丢失响应式的问题 (#2386)

Co-authored-by: 王一骅 <wangyihua@yazuishou.com>
src/components/Table/src/hooks/useCustomRow.ts
@@ -40,7 +40,7 @@ export function useCustomRow( @@ -40,7 +40,7 @@ export function useCustomRow(
40 function handleClick() { 40 function handleClick() {
41 const { rowSelection, rowKey, clickToRowSelect } = unref(propsRef); 41 const { rowSelection, rowKey, clickToRowSelect } = unref(propsRef);
42 if (!rowSelection || !clickToRowSelect) return; 42 if (!rowSelection || !clickToRowSelect) return;
43 - const keys = getSelectRowKeys(); 43 + const keys = getSelectRowKeys() || [];
44 const key = getKey(record, rowKey, unref(getAutoCreateKey)); 44 const key = getKey(record, rowKey, unref(getAutoCreateKey));
45 if (!key) return; 45 if (!key) return;
46 46
src/components/Table/src/hooks/useRowSelection.ts
@@ -66,13 +66,13 @@ export function useRowSelection( @@ -66,13 +66,13 @@ export function useRowSelection(
66 selectedRowKeysRef.value = rowKeys; 66 selectedRowKeysRef.value = rowKeys;
67 const allSelectedRows = findNodeAll( 67 const allSelectedRows = findNodeAll(
68 toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))), 68 toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))),
69 - (item) => rowKeys.includes(item[unref(getRowKey) as string]), 69 + (item) => rowKeys?.includes(item[unref(getRowKey) as string]),
70 { 70 {
71 children: propsRef.value.childrenColumnName ?? 'children', 71 children: propsRef.value.childrenColumnName ?? 'children',
72 }, 72 },
73 ); 73 );
74 const trueSelectedRows: any[] = []; 74 const trueSelectedRows: any[] = [];
75 - rowKeys.forEach((key: string) => { 75 + rowKeys?.forEach((key: string) => {
76 const found = allSelectedRows.find((item) => item[unref(getRowKey) as string] === key); 76 const found = allSelectedRows.find((item) => item[unref(getRowKey) as string] === key);
77 found && trueSelectedRows.push(found); 77 found && trueSelectedRows.push(found);
78 }); 78 });
src/views/demo/table/FormTable.vue
1 <template> 1 <template>
2 - <BasicTable  
3 - @register="registerTable"  
4 - :rowSelection="{ type: 'checkbox', selectedRowKeys: checkedKeys, onChange: onSelectChange }"  
5 - > 2 + <BasicTable @register="registerTable">
6 <template #form-custom> custom-slot </template> 3 <template #form-custom> custom-slot </template>
7 <template #headerTop> 4 <template #headerTop>
8 <a-alert type="info" show-icon> 5 <a-alert type="info" show-icon>
@@ -44,6 +41,11 @@ @@ -44,6 +41,11 @@
44 tableSetting: { fullScreen: true }, 41 tableSetting: { fullScreen: true },
45 showIndexColumn: false, 42 showIndexColumn: false,
46 rowKey: 'id', 43 rowKey: 'id',
  44 + rowSelection: {
  45 + type: 'checkbox',
  46 + selectedRowKeys: checkedKeys,
  47 + onChange: onSelectChange,
  48 + },
47 }); 49 });
48 50
49 function getFormValues() { 51 function getFormValues() {