import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table'; import { Button, Form, Input, message, Modal, PageHeader, Select, Spin, Tree, TreeSelect } from 'antd'; import { useRef, useState } from 'react'; import { fetchAllDepartment, addOrg, deleteOrg, updateOrg, getDataById } from './service'; import React from 'react'; const Index: React.FC<{}> = () => { const [spin, spinSet] = useState(false); const actionRef = useRef(); const [form] = Form.useForm(); const [title, setTitle] = useState(''); const [open, setOpen] = useState(false); const [org, orgSet] = useState([]); const layout = { labelCol: { span: 6 }, wrapperCol: { span: 13 }, }; const columns: ProColumns[] = [ // { // title: '组织编码', // dataIndex: 'orgNum', // width: '15%', // }, { title: '组织名称', dataIndex: 'orgName', width: '45%', }, { title: '组织全称', dataIndex: 'orgFullName', width: '40%', hideInSearch: true, }, { title: '操作', width: '10%', valueType: 'option', render: (_, record) => [ , ] }, // { // title: '部门负责人', // dataIndex: 'leaderName', // width: '15%', // }, ]; const handleAdd = async () => { setOpen(true); setTitle('添加组织'); }; const handleUpdate = async (record: any) => { form.resetFields(); const org = await getDataById(record.orgId); form.setFieldsValue(org.data); setOpen(true); setTitle('修改组织'); }; // 删除操作 const handleDelete = (id: string) => { Modal.confirm({ title: '确认删除该组织?', onOk: async () => { await deleteOrg(id).then((r: any) => { if (r.code == 200) { message.success('删除成功'); } }) .finally(() => actionRef.current?.reload()); }, }); }; const handleSubmit = async () => { try { const values = await form.validateFields(); if (values.orgId) { await updateOrg(values).then((r: any) => { if (r.code == 200) { message.success('修改成功'); } }); } else { await addOrg(values).then((r: any) => { if (r.code == 200) { message.success('新增成功'); } }); } closeModal(); } catch (error) { console.error(error); } }; const closeModal = async () => { actionRef.current?.reload(); form.resetFields(); setOpen(false); }; const addModal = ( setOpen(false)}>关闭} onOk={handleSubmit} onCancel={() => closeModal()} >
); //表格请求 async function request(params: any) { console.log('org params:', params); const { data } = await fetchAllDepartment(params); console.log('org data:', data); // orgSet(data.children); orgSet(data); let result = { // data: data.children, data: data, success: true, total: data.length, }; return result; } return (
[ , ] } request={request} /> {addModal}
); } export default Index;