Commit f43e616b authored by 前端-黄佳鑫's avatar 前端-黄佳鑫

🐞 fix(TableLayout 组件): 修改跨页多选的问题

parent e12fcc8f
...@@ -9,6 +9,7 @@ import { createFormActions, FormEffectHooks } from '@formily/antd'; ...@@ -9,6 +9,7 @@ import { createFormActions, FormEffectHooks } from '@formily/antd';
import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch'; import { useStateFilterSearchLinkageEffect } from '@/formSchema/effects/useFilterSearch';
import { useLinkageUtils } from '@/utils/formEffectUtils'; import { useLinkageUtils } from '@/utils/formEffectUtils';
import { searchSelectGetSelectCategoryOptionEffect } from '@/pages/systemManage/effect'; import { searchSelectGetSelectCategoryOptionEffect } from '@/pages/systemManage/effect';
import { useRowSelectionTable } from '@/hooks/useRowSelectionTable';
const { onFormMount$ } = FormEffectHooks const { onFormMount$ } = FormEffectHooks
interface Iprops { interface Iprops {
...@@ -51,6 +52,13 @@ const Table: React.FC<Iprops> = (props: any) => { ...@@ -51,6 +52,13 @@ const Table: React.FC<Iprops> = (props: any) => {
useStateEffects useStateEffects
} = props; } = props;
const tableRef = useRef<any>({}); const tableRef = useRef<any>({});
const [selectRow, selectRowFns] = useRowSelectionTable({
extendsSelection: {
onChange: () => {
fetchRowkeys(selectRowFns.selectedRowKeys)
},
}
});
/** 列表数据 */ /** 列表数据 */
const fetchData = (params?: any) => { const fetchData = (params?: any) => {
...@@ -63,18 +71,12 @@ const Table: React.FC<Iprops> = (props: any) => { ...@@ -63,18 +71,12 @@ const Table: React.FC<Iprops> = (props: any) => {
/**多选 */ /**多选 */
const [selectedRowKeys, setSelectedRowKeys] = useState<Array<number>>([]); const [selectedRowKeys, setSelectedRowKeys] = useState<Array<number>>([]);
const rowSelection = {
selectedRowKeys: selectedRowKeys,
onChange: (rowKeys: any) => {
console.log(rowKeys, 98)
fetchRowkeys(rowKeys)
setSelectedRowKeys(rowKeys);
},
}
useImperativeHandle(reload, () => ({ useImperativeHandle(reload, () => ({
reload: () => { reload: () => {
tableRef.current.reload(); tableRef.current.reload();
selectRowFns.setSelectRow([])
selectRowFns.setSelectedRowKeys([])
} }
})); }));
...@@ -107,7 +109,7 @@ const Table: React.FC<Iprops> = (props: any) => { ...@@ -107,7 +109,7 @@ const Table: React.FC<Iprops> = (props: any) => {
currentRef={tableRef} currentRef={tableRef}
columns={columns} columns={columns}
tableProps={{ rowKew: 'id' }} tableProps={{ rowKew: 'id' }}
rowSelection={selectedRow && rowSelection} rowSelection={selectedRow && selectRow}
fetchTableData={(params: any) => fetchData(params)} fetchTableData={(params: any) => fetchData(params)}
controlRender={ controlRender={
<NiceForm <NiceForm
......
...@@ -12,7 +12,11 @@ interface useRowSelectionTableCtl { ...@@ -12,7 +12,11 @@ interface useRowSelectionTableCtl {
interface useRowSelectionOptions { interface useRowSelectionOptions {
type?: 'checkbox' | 'radio', type?: 'checkbox' | 'radio',
customKey?: string customKey?: string,
// 可通过该参数扩展多选选项
// https://ant.design/components/table-cn/#components-table-demo-row-selection
extendsSelection?: TableRowSelection<any>
} }
/** /**
...@@ -20,7 +24,7 @@ interface useRowSelectionOptions { ...@@ -20,7 +24,7 @@ interface useRowSelectionOptions {
* @auth xjm * @auth xjm
*/ */
export const useRowSelectionTable = (options: useRowSelectionOptions = {}): [TableRowSelection<any>, useRowSelectionTableCtl] => { export const useRowSelectionTable = (options: useRowSelectionOptions = {}): [TableRowSelection<any>, useRowSelectionTableCtl] => {
const { type = 'checkbox', customKey = 'id' } = options const { type = 'checkbox', customKey = 'id', extendsSelection = {} } = options
const [selectRow, setSelectRow] = useState<any[]>([]) // 模态框选择的行数据 const [selectRow, setSelectRow] = useState<any[]>([]) // 模态框选择的行数据
const [selectedRowKeys, setSelectedRowKeys] = useState<any[]>(() => []) const [selectedRowKeys, setSelectedRowKeys] = useState<any[]>(() => [])
...@@ -59,7 +63,7 @@ export const useRowSelectionTable = (options: useRowSelectionOptions = {}): [Tab ...@@ -59,7 +63,7 @@ export const useRowSelectionTable = (options: useRowSelectionOptions = {}): [Tab
// 单选情况下 // 单选情况下
setSelectedRowKeys([record[customKey]]) setSelectedRowKeys([record[customKey]])
setSelectRow([record]) setSelectRow([record])
return ; return;
} }
const findIds = selectedRowKeys.indexOf(record[customKey]) const findIds = selectedRowKeys.indexOf(record[customKey])
if (findIds === -1) { if (findIds === -1) {
...@@ -79,8 +83,10 @@ export const useRowSelectionTable = (options: useRowSelectionOptions = {}): [Tab ...@@ -79,8 +83,10 @@ export const useRowSelectionTable = (options: useRowSelectionOptions = {}): [Tab
setSelectedRowKeys(removeRowsKeys(changeRows.map(v => v[customKey]))) setSelectedRowKeys(removeRowsKeys(changeRows.map(v => v[customKey])))
setSelectRow(removeRows(changeRows)) setSelectRow(removeRows(changeRows))
} }
} },
...extendsSelection
} }
return [rowSelection, { selectRow, setSelectRow, selectedRowKeys, setSelectedRowKeys }] return [rowSelection, { selectRow, setSelectRow, selectedRowKeys, setSelectedRowKeys }]
} }
\ No newline at end of file
...@@ -263,14 +263,14 @@ const WaitAddedMarketing = () => { ...@@ -263,14 +263,14 @@ const WaitAddedMarketing = () => {
icon={<DeleteOutlined />} icon={<DeleteOutlined />}
loading={loading} loading={loading}
onClick={() => fetchDeleteBatch()} onClick={() => fetchDeleteBatch()}
disabled={rowkeys.length === 0} disabled={rowkeys.length !== 0}
> >
批量删除 批量删除
</Button> </Button>
<Button <Button
loading={loading} loading={loading}
onClick={() => fetchSubmitBatch()} onClick={() => fetchSubmitBatch()}
disabled={rowkeys.length === 0} disabled={rowkeys.length !== 0}
> >
批量提交审核 批量提交审核
</Button> </Button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment