测试节点版本配置 - 可编辑表格管理
import React, { useEffect, useRef, useState } from 'react';
import ContentCard from '@/components/ContentCard';
import { Button, Collapse, Select, Space } from 'antd';
import { ActionType, EditableProTable, ProColumns } from '@ant-design/pro-table';
// import ProForm, { ProFormInstance } from '@ant-design/pro-form';
import { getOnlyKey } from '@/utils/utils';
import { PlusCircleOutlined } from '@ant-design/icons';
import './index.less';
import { isArray } from 'lodash';
const { Panel } = Collapse;
const DEMAND_DICT = [
{
label: 'M1-1',
value: '1',
},
{
label: 'M1-2',
value: '2',
},
{
label: 'M1-3',
value: '3',
},
];
const REF_MAP = {};
const VersionConfiguration: React.FC = () => {
// const actionRef = useRef
const columns: ProColumns[] = [ { title: '节点版本', dataIndex: 'nodeVersion', align: 'center', }, { title: '测试项', dataIndex: 'testingItem', align: 'center', }, { title: '负责人', dataIndex: 'head', align: 'center', }, { title: '用例库名称', dataIndex: 'caseLibraryName', align: 'center', }, { title: '交付件模板', dataIndex: 'deliveryTemplate', align: 'center', }, { title: '测试周期(天)', dataIndex: 'testCycle', align: 'center', }, { title: '参考投入人力(人天)', dataIndex: 'referenceInputManpower', align: 'center', }, { title: '操作', valueType: 'option', width: 120, align: 'center', render: (text, record, _, action) => [ <a key="editable" onClick={() => { action?.startEditable?.(record.key); }} > 配置 , 删除, // <Popconfirm // title="确定删除此行?" // key="delete" // onConfirm={async () => { // try { // const { code, msg } = await deletedCategory({ // id: record.id, // }); // if ((code as unknown as string) !== 'BIZ_SUCCESS') throw new Error(msg); // message.success('删除成功!'); // staragyList(); // } catch (error) {} // }} // okText="确定" // cancelText="取消" // > // 删除 // , ], }, ]; useEffect(() => { // const data = [ // { // nodeVersion: '1', // testingItem: '全功能用例测试', // head: '张三', // caseLibraryName: '222', // }, // { // nodeVersion: '2', // testingItem: '全功能用例测试', // head: '张三', // caseLibraryName: '111', // }, // ]; // formRef.current?.setFieldsValue({ // dataSource: data.map((item: any) => ({ key: getOnlyKey(), ...item })), // }); }, []);
if (DEMAND_DICT.length > 0) {
DEMAND_DICT.forEach((item) => {
REF_MAP[item.value] = useRef
<div className="check-list-wrap">
<Collapse
ghost
activeKey={activeKeys}
onChange={(e) => setActiveKeys(isArray(e) ? e : [e])}
>
{DEMAND_DICT.map((item) => {
return (
<Panel header={item.label} key={item.value}>
{/* <ProForm formRef={formRef} submitter={false}> */} {/* <ProForm.Item name="dataSource" style={{ margin: '0' }}> */} <EditableProTable
rowKey="key"
recordCreatorProps={false}
actionRef={REF_MAP[item.value]}
columns={columns}
editable={{
type: 'single',
editableKeys: editKeys,
onChange: setEditKeys,
actionRender: (row, config, defaultDoms) => {
return [defaultDoms.save, defaultDoms.cancel];
},
}}
search={false}
pagination={false}
bordered
/> {/* </ProForm.Item> */} {/* </ProForm> */} <Space>
<Button
style={{ border: '1px' }}
onClick={() => {
REF_MAP[item.value].current?.addEditRecord?.({
key: getOnlyKey(),
});
}}
>
<PlusCircleOutlined />
</Button>
</Space>
</Panel>
);
})}
</Collapse>
</div>
</ContentCard>
); }; export default VersionConfiguration;