import { ModalForm, ProForm, ProFormDependency, ProFormDigit, ProFormRadio, ProFormText, ProFormList, ProCard, } from '@ant-design/pro-components'; import { Col, Row } from 'antd'; import React, { useState, PropsWithChildren } from 'react'; import { MenuFields, SelectOptionFields, getButtonSelections, } from '../../../../services'; import { addApi } from '../../services'; import { OPTIONS } from '../../../../constants'; import UploadImage from '../../../../components/Upload/Image'; import { htmlTools } from '@cowin/tools'; import SelectButton from './SelectButton'; interface AddFormProps { title: string; initialParentValues?: MenuFields; appId?: string; onOk?: () => void; } const defaultCol = { labelCol: { flex: '120px' }, }; const AddForm: React.FC> = ({ title, initialParentValues, appId, onOk, children, }) => { const [form] = ProForm.useForm(); const [open, setOpen] = useState(false); return ( <> setOpen(false), }} submitTimeout={2000} onFinish={async (values) => { const { menuList } = values || {}; const { menuId: parentId = '' } = initialParentValues || {}; const menuApis = (menuList || []).map((item: any) => { const { icon: _icon, ...values } = item; const icon = htmlTools.encode(_icon || ''); return addApi({ ...values, appId, parentId, icon, }); }); await Promise.all(menuApis); onOk?.(); return true; }} onOpenChange={async (open) => { if (!open) return; }} > { return (
{listDom} {action}
); }} > {() => { return ( {({ menuType }) => { return ( ); }} ); }}
); }; interface AddButtonFormProps { title: string; initialParentValues?: MenuFields; appId?: string; onOk?: () => void; initialButtonList?: string[]; } export const AddButtonForm: React.FC> = ({ title, initialParentValues, appId, onOk, children, initialButtonList, }) => { const [form] = ProForm.useForm(); const [open, setOpen] = useState(false); const [buttonList, setButtonList] = useState([]); const { menuName, path: menuPath } = initialParentValues || {}; return ( <> setOpen(false), }} submitTimeout={2000} onFinish={async (values) => { const { menuList } = values || {}; const { menuId: parentId = '' } = initialParentValues || {}; const menuApis = (menuList || []).map((value: any) => { const { label: menuName, value: perms } = buttonList.find((item) => item.value === value) || {}; return addApi({ parentId, appId, status: '1', menuType: 'F', menuName, orderNum: 0, perms, }); }); await Promise.all(menuApis); onOk?.(); return true; }} onOpenChange={async (open) => { if (!open) return; const buttonList = await getButtonSelections({ menuPath, }); setButtonList(buttonList); }} > { return !initialButtonList?.includes(item.value); })} menuName={menuName || ''} menuPath={menuPath || ''} onAddButtonOk={async () => { const buttonList = await getButtonSelections({ menuPath, }); setButtonList(buttonList); }} /> ); }; export default AddForm;