import { ModalForm, ProForm, ProFormDependency, ProFormDigit, ProFormRadio, ProFormSelect, ProFormText, ProFormTextArea, ProFormTreeSelect, } from '@ant-design/pro-components'; import { AutoComplete, Form, Input, message } from 'antd'; import React, { useState } from 'react'; import { OPTIONS } from '../../../constants'; import { RoleFields, getMenuDetailsApi, getButtonDetailsApi, addApi, updateApi, getMenuTreeListApi, getButtonTreeListApi, } from '../services'; import { SelectOptionFields } from '../../../services'; interface PreviewProps { title: string; trigger: JSX.Element; type: 'add' | 'update'; initialValues?: RoleFields; onSubmit?: () => void; menuList: SelectOptionFields[]; } interface ModalFormProps extends RoleFields { menuIds: string[]; buttonIds: string[]; } const EditForm: React.FC = ({ title, trigger, type, initialValues, onSubmit, menuList, }) => { const [form] = Form.useForm(); const [open, setOpen] = useState(false); return ( <> {React.cloneElement(trigger, { async onClick() { setOpen(true); if (type === 'update') { form.setFieldsValue({ ...initialValues }); const { roleId = '' } = initialValues || {}; const menuIds = await getMenuDetailsApi(roleId); form.setFieldValue('menuIds', menuIds); const buttonIds = await getButtonDetailsApi(roleId); form.setFieldValue('buttonIds', buttonIds); } }, })} labelCol={{ flex: '120px' }} width={1000} layout="horizontal" title={title} open={open} form={form} autoFocusFirstInput modalProps={{ destroyOnClose: true, onCancel: () => setOpen(false), }} onFinish={async (values) => { const { menuIds = [], buttonIds = [], roleType = '' } = values; const params = { ...values, menuIds, buttonIds, roleType, }; if (type === 'add') { await addApi(params); } else if (type === 'update') { await updateApi({ ...params, roleId: initialValues?.roleId, }); } message.success('提交成功'); onSubmit?.(); setOpen(false); }} > getMenuTreeListApi()} /> {({ menuIds }) => { return ( 如果需要配置分组页面,则需要添加参数,示例:/home?_groupName_=groupName&_groupTitle_=groupTitle } > { return (menuIds || []).includes(item.menuId); }) .map((item) => { return { ...item, label: `${item.label} - ${item.value}`, }; })} > ); }} getButtonTreeListApi()} /> ); }; export default EditForm;