| | |
| | | ProForm, |
| | | ProFormDigit, |
| | | } from '@ant-design/pro-components'; |
| | | import { Col, Form, Modal, Row, Checkbox, Skeleton, Tree } from 'antd'; |
| | | import { Col, Form, Modal, Row, Checkbox, Skeleton, Tree, Drawer, Space, Button, Card } from 'antd'; |
| | | import Http from '@/utils/http'; |
| | | import { transformTreeData, getTreeAllKeys } from '@/utils/tree-util' |
| | | |
| | | const Scope = (props) => { |
| | | const [form] = Form.useForm(); |
| | | const { originMenuIds } = props; |
| | | const { originMenuIds, values: { name } } = props; |
| | | const [menuTreeLoading, setMenuTreeLoading] = useState(false); |
| | | const [menuTreeData, setMenuTreeData] = useState([]); |
| | | const [menuExpandedKeys, setMenuExpandedKeys] = useState([]); |
| | |
| | | setMenuTreeData(treeData); |
| | | const treeAllKeys = getTreeAllKeys(treeData); |
| | | setMenuTreeAllKeys(treeAllKeys); |
| | | setMenuExpandedKeys(treeAllKeys); |
| | | }).catch((err) => { |
| | | console.error(err); |
| | | setMenuTreeLoading(false); |
| | |
| | | |
| | | return ( |
| | | <> |
| | | <Modal |
| | | title="Scope" |
| | | <Drawer |
| | | title={`${name}`} |
| | | width={640} |
| | | forceRender |
| | | destroyOnClose |
| | | open={props.open} |
| | | onCancel={handleCancel} |
| | | onOk={handleOk} |
| | | onClose={handleCancel} |
| | | styles={{ |
| | | body: { |
| | | paddingBottom: 80, |
| | | }, |
| | | }} |
| | | extra={ |
| | | <Space> |
| | | <Button onClick={handleCancel}>Cancel</Button> |
| | | <Button onClick={handleOk} type="primary"> |
| | | Submit |
| | | </Button> |
| | | </Space> |
| | | } |
| | | > |
| | | <ProForm |
| | | form={form} |
| | | submitter={false} |
| | | onFinish={handleFinish} |
| | | layout="horizontal" |
| | | grid={true} |
| | | > |
| | | <ProFormDigit |
| | | name="id" |
| | | disabled |
| | | hidden={true} |
| | | /> |
| | | |
| | | <ProForm.Item |
| | | name="deptIds" |
| | | label="菜单权限" |
| | | colProps={{ md: 24, xl: 24 }} |
| | | <Card> |
| | | <ProForm |
| | | form={form} |
| | | submitter={false} |
| | | onFinish={handleFinish} |
| | | layout="horizontal" |
| | | grid={true} |
| | | > |
| | | <ProFormDigit |
| | | name="id" |
| | | disabled |
| | | hidden={true} |
| | | /> |
| | | |
| | | <Row gutter={[16, 16]}> |
| | | <Col md={24}> |
| | | <Checkbox.Group |
| | | options={[ |
| | | { label: '展开/折叠', value: 'expandAll' }, |
| | | { label: '全选/全不选', value: 'checkAll' }, |
| | | ]} |
| | | onChange={(values) => { |
| | | if (values.includes('expandAll')) { |
| | | setMenuExpandedKeys(menuTreeAllKeys); |
| | | } else { |
| | | setMenuExpandedKeys([]); |
| | | } |
| | | if (values.includes('checkAll')) { |
| | | <ProForm.Item |
| | | name="deptIds" |
| | | label="菜单权限" |
| | | colProps={{ md: 24, xl: 24 }} |
| | | > |
| | | |
| | | } else { |
| | | <Row gutter={[16, 16]}> |
| | | <Col md={24}> |
| | | <Checkbox.Group |
| | | options={[ |
| | | { label: '展开/折叠', value: 'expandAll' }, |
| | | { label: '全选/全不选', value: 'checkAll' }, |
| | | ]} |
| | | defaultValue={['expandAll']} |
| | | onChange={(values) => { |
| | | if (values.includes('expandAll')) { |
| | | setMenuExpandedKeys(menuTreeAllKeys); |
| | | } else { |
| | | setMenuExpandedKeys([]); |
| | | } |
| | | if (values.includes('checkAll')) { |
| | | |
| | | } |
| | | }} /> |
| | | </Col> |
| | | <Col md={24}> |
| | | {menuTreeLoading ? ( |
| | | <Skeleton active /> |
| | | ) : ( |
| | | <Tree |
| | | checkable |
| | | treeData={menuTreeData} |
| | | expandedKeys={menuExpandedKeys} |
| | | onExpand={(expandedKeys) => { |
| | | setMenuExpandedKeys(expandedKeys) |
| | | }} |
| | | checkedKeys={menuIds} |
| | | onCheck={(checkedKeys, checkInfo) => { |
| | | return setMenuIds({ |
| | | checked: checkedKeys, |
| | | halfChecked: checkInfo.halfCheckedKeys // 父节点 |
| | | }); |
| | | }} |
| | | // defaultCheckedKeys={onSelect} |
| | | /> |
| | | )} |
| | | </Col> |
| | | </Row> |
| | | } else { |
| | | |
| | | </ProForm.Item> |
| | | </ProForm> |
| | | </Modal> |
| | | } |
| | | }} /> |
| | | </Col> |
| | | <Col md={24}> |
| | | {menuTreeLoading ? ( |
| | | <Skeleton active /> |
| | | ) : ( |
| | | <Tree |
| | | checkable |
| | | treeData={menuTreeData} |
| | | expandedKeys={menuExpandedKeys} |
| | | onExpand={(expandedKeys) => { |
| | | setMenuExpandedKeys(expandedKeys) |
| | | }} |
| | | checkedKeys={menuIds} |
| | | onCheck={(checkedKeys, checkInfo) => { |
| | | return setMenuIds({ |
| | | checked: checkedKeys, |
| | | halfChecked: checkInfo.halfCheckedKeys // 父节点 |
| | | }); |
| | | }} |
| | | // defaultCheckedKeys={onSelect} |
| | | /> |
| | | )} |
| | | </Col> |
| | | </Row> |
| | | |
| | | </ProForm.Item> |
| | | </ProForm> |
| | | </Card> |
| | | </Drawer> |
| | | </> |
| | | ) |
| | | } |