|
@@ -1,4 +1,13 @@
|
|
|
-import {ActionType, PageContainer, ProForm, ProFormText,ProFormRadio,ProFormDigit, ProTable,} from '@ant-design/pro-components';
|
|
|
+import {
|
|
|
+ ActionType,
|
|
|
+ PageContainer,
|
|
|
+ ProForm,
|
|
|
+ ProFormText,
|
|
|
+ ProFormRadio,
|
|
|
+ ProFormDigit,
|
|
|
+ ProFormTreeSelect,
|
|
|
+ ProTable,
|
|
|
+} from '@ant-design/pro-components';
|
|
|
import {Button, Card, Modal, TreeSelect} from 'antd';
|
|
|
import React, {useEffect, useRef, useState} from 'react';
|
|
|
import {AddOutline} from 'antd-mobile-icons';
|
|
@@ -51,9 +60,8 @@ class Service {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const Edit: React.FC<{ bundle: EditBundle; treeData: any[]; onSuccess?: () => void }> = (props) => {
|
|
|
- const {bundle, treeData} = props;
|
|
|
- console.log("treeData" + treeData)
|
|
|
+const Edit: React.FC<{ bundle: EditBundle; onSuccess?: () => void }> = (props) => {
|
|
|
+ let {bundle} = props;
|
|
|
|
|
|
const [form] = ProForm.useForm<MenuVO>();
|
|
|
const [loading, setLoading] = React.useState(false);
|
|
@@ -117,29 +125,46 @@ const Edit: React.FC<{ bundle: EditBundle; treeData: any[]; onSuccess?: () => vo
|
|
|
}}
|
|
|
>
|
|
|
|
|
|
- <ProFormRadio.Group name="type" label="类型" value='2' options={[{label: '目录', value: '1',}, {label: '菜单', value: '2'}, {label: '按钮', value: '3'}]}/>
|
|
|
- <ProFormRadio.Group name="status" label="状态" value='1' options={[{label: '正常', value: '1',}, {label: '隐藏', value: '2'}]}/>
|
|
|
- <ProFormRadio.Group name="target" label="目标" value='1' options={[{label: '页签', value: '1',}, {label: '新窗口', value: '2'}]}/>
|
|
|
- <ProFormRadio.Group name="hasRefresh" label="是否刷新" value='1' options={[{label: '不刷新', value: '0',}, {label: '刷新', value: '1'}]}/>
|
|
|
+ <ProFormRadio.Group name='type' label='类型' value='2'
|
|
|
+ options={[
|
|
|
+ {label: '目录', value: '1',},
|
|
|
+ {label: '菜单', value: '2'},
|
|
|
+ {label: '按钮', value: '3'}]}></ProFormRadio.Group>
|
|
|
+ <ProFormRadio.Group name='status' label='状态' value='1'
|
|
|
+ options={[{label: '正常', value: '1',}, {label: '隐藏', value: '2'}]}/>
|
|
|
+ <ProFormRadio.Group name='target' label='目标' value='1'
|
|
|
+ options={[{label: '页签', value: '1',}, {label: '新窗口', value: '2'}]}/>
|
|
|
+ <ProFormRadio.Group name='hasRefresh' label='是否刷新' value='1'
|
|
|
+ options={[{label: '不刷新', value: '0',}, {label: '刷新', value: '1'}]}/>
|
|
|
<ProFormText name='name' label={'菜单名称'} placeholder={'请输入菜单名称'}
|
|
|
rules={[{required: true, message: '请输入菜单名称',}, {
|
|
|
min: 3,
|
|
|
max: 30,
|
|
|
message: '菜单名称长度必须在3-30之间',
|
|
|
},]}></ProFormText>
|
|
|
- <ProForm.Item label='父菜单' name='parentId'>
|
|
|
- <TreeSelect
|
|
|
- showSearch
|
|
|
- style={{width: '100%'}}
|
|
|
- value={value}
|
|
|
- dropdownStyle={{maxHeight: 400, overflow: 'auto'}}
|
|
|
- placeholder="请选择父菜单ID"
|
|
|
- allowClear
|
|
|
- treeDefaultExpandAll
|
|
|
- onChange={onChange}
|
|
|
- treeData={treeData}
|
|
|
- />
|
|
|
- </ProForm.Item>
|
|
|
+
|
|
|
+ <ProFormTreeSelect
|
|
|
+ label='父菜单' name='parentId'
|
|
|
+ style={{width: '100%'}}
|
|
|
+ placeholder="请选择父菜单ID"
|
|
|
+ allowClear
|
|
|
+ request={async () => {
|
|
|
+ const transformToTreeData = (data: MenuVO[]): any[] =>
|
|
|
+ data.map((item) => ({
|
|
|
+ title: item.name,
|
|
|
+ value: item.id,
|
|
|
+ key: item.id,
|
|
|
+ children: item.children ? transformToTreeData(item.children) : [],
|
|
|
+ }));
|
|
|
+ const res = await Service.listTree({});
|
|
|
+ if (res.success) {
|
|
|
+ return transformToTreeData(res.data);
|
|
|
+ }
|
|
|
+ return Promise.resolve({});
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ </ProFormTreeSelect>
|
|
|
+
|
|
|
<ProFormText name='icon' label={'图标'} placeholder={'请输入图标'}></ProFormText>
|
|
|
|
|
|
<ProFormDigit name='sortNum' label={'显示顺序'} placeholder={'请输入显示顺序'}></ProFormDigit>
|
|
@@ -150,34 +175,15 @@ const Edit: React.FC<{ bundle: EditBundle; treeData: any[]; onSuccess?: () => vo
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-const transformToTreeData = (data: MenuVO[]): any[] =>
|
|
|
- data.map((item) => ({
|
|
|
- title: item.name,
|
|
|
- value: item.id,
|
|
|
- key: item.id,
|
|
|
- children: item.children ? transformToTreeData(item.children) : [],
|
|
|
- }));
|
|
|
+
|
|
|
const MenuExp: React.FC = () => {
|
|
|
const bundle = useEdit();
|
|
|
const ref = useRef<ActionType>();
|
|
|
|
|
|
- const [treeData, setTreeData] = useState<any[]>([]);
|
|
|
-
|
|
|
- const loadData = async () => {
|
|
|
- const res = await Service.listTree({});
|
|
|
- if (res.success) {
|
|
|
- setTreeData(transformToTreeData(res.data));
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- loadData();
|
|
|
- }, []);
|
|
|
-
|
|
|
return (
|
|
|
<>
|
|
|
<PageContainer content={''}>
|
|
|
- {bundle.open && <Edit bundle={bundle} treeData={treeData} onSuccess={() => ref.current?.reload()}></Edit>}
|
|
|
+ {bundle.open && <Edit bundle={bundle} onSuccess={() => ref.current?.reload()}></Edit>}
|
|
|
<Card>
|
|
|
<ProTable<MenuVO>
|
|
|
rowKey={'id'}
|
|
@@ -202,10 +208,7 @@ const MenuExp: React.FC = () => {
|
|
|
{
|
|
|
title: '类型',
|
|
|
dataIndex: 'type',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '父菜单ID',
|
|
|
- dataIndex: 'parentId',
|
|
|
+ render: (text) => (text === 1 ? '目录' : text === 2 ? '菜单' : '按钮'),
|
|
|
},
|
|
|
{
|
|
|
title: '显示顺序',
|
|
@@ -218,14 +221,17 @@ const MenuExp: React.FC = () => {
|
|
|
{
|
|
|
title: '目标',
|
|
|
dataIndex: 'target',
|
|
|
+ render: (text) => (text === 1 ? '页签' : '新窗口'),
|
|
|
},
|
|
|
{
|
|
|
title: '状态',
|
|
|
dataIndex: 'status',
|
|
|
+ render: (text) => (text === 1 ? '正常' : '隐藏'),
|
|
|
},
|
|
|
{
|
|
|
title: '是否刷新',
|
|
|
dataIndex: 'hasRefresh',
|
|
|
+ render: (text) => (text === 1 ? '刷新' : '不刷新'),
|
|
|
},
|
|
|
{
|
|
|
title: '权限标识',
|