项目关注列表 - Ant Design Pro Table 可编辑表格
import { ModalForm, ProFormInstance } from '@ant-design/pro-form'; import { ActionType, EditableFormInstance, EditableProTable, ProColumns, } from '@ant-design/pro-table'; import React, { useEffect, useRef, useState } from 'react'; import { getOnlyKey } from '@/utils/utils'; import { Button, Radio, RadioChangeEvent, Space, message } from 'antd'; import { PlusCircleOutlined } from '@ant-design/icons'; import { getProjectList, getSave } from '@/services/project/new/built'; import { useModel } from 'umi'; import { isArray } from 'lodash'; import { TYPE_PROJECT } from '@/constant/new'; import { getUserList } from '@/services/project/home/index';
interface Props { children: React.ReactElement; refresh: () => void; }
interface ListItem { entity: any; projectName: string; projectChip: string; projectType: string; publicTime: string; id: string; releaseTime: string; rowIndex: string; }
const ModalFocus: React.FC<React.PropsWithChildren
/**列表/ const getUser = async () => { try { const { data } = await getUserList({ oaName: initialState?.currentUser?.userName }); const newData = data.map((item: any) => { if (item.isNew) return item; const defaultProject = projectOptions.find((option) => option.id === item.projectId); return { ...item, chip: defaultProject?.projectChip, projectType: defaultProject?.projectType, }; }); setFocusData(newData); } catch (error) {} };
useEffect(() => { getProjectOptions(); getUser(); }, []);
const valueChange = (e: RadioChangeEvent) => {
setRedioValue(e.target.value);
};
const columns: ProColumns
const updatedFocusData = focusData;
updatedFocusData[currentRowIndex] = updatedRowData;
setFocusData(updatedFocusData);
editableFormRef?.current?.setRowData?.(currentRowIndex, {
chip: updatedRowData.chip,
projectId: updatedRowData.projectId,
projectType: updatedRowData.projectType,
});
setEditableRowKeys([...editableKeys, id]);
// console.log(updatedFocusData, 130);
},
};
},
},
{
title: '项目类型',
dataIndex: 'projectType',
readonly: true,
align: 'center',
width: 120,
valueEnum: TYPE_PROJECT,
},
{
title: '操作',
dataIndex: 'opeation',
width: 140,
renderFormItem: () => {
return (
<Radio.Group value={redioValue} onChange={valueChange}>
<Radio value={1}>已关注</Radio>
<Radio value={0}>已取消关注</Radio>
</Radio.Group>
);
},
},
];
const handleSave = async () => {
try {
const updatedFocusData = focusData.map((item: any) => ({...item, id: item.isNew ? undefined : item.id, deleted: redioValue}));
// console.log(updatedFocusData,161);
// return
const { code, msg } = await getSave({ userCareProjectList: updatedFocusData });
if (code !== 100000) throw new Error(msg);
message.success('保存成功');
setVisible(false);
if (refresh) refresh();
} catch (error) {}
};
return (
<>
{React.cloneElement(children, {
onClick: () => {
setVisible(true);
},
})}
<ModalForm
title="我关注的项目"
visible={visible}
submitter={{searchConfig: {submitText: '保存', resetText: '取消'}, render: (_, dom) =>
<Space>
<Button
style={{ border: '1px' }}
onClick={() => {
const data = [...focusData];
const newId = getOnlyKey();
data.push({ id: newId, isNew: true });
setFocusData(data);
setEditableRowKeys([...editableKeys, newId]);
}}
>
<PlusCircleOutlined />
</Button>
</Space>
</ModalForm>
</>
); }; export default React.memo(ModalFocus);
原文地址: https://www.cveoy.top/t/topic/oojV 著作权归作者所有。请勿转载和采集!