|
@@ -1,20 +1,23 @@
|
|
|
import { PageContainer } from '@ant-design/pro-components';
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
-import { Button, Card, Form, Input, Modal, Space, Table } from 'antd';
|
|
|
+import { Button, Card, Form, Input, message, Modal, Space, Table } from 'antd';
|
|
|
import Icon, { PlusCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
|
|
|
import type { ColumnsType } from 'antd/es/table';
|
|
|
import moment from 'moment/moment';
|
|
|
import Edit from '@/pages/MenuManagement/edit';
|
|
|
import IconMap from '@/components/Icon/IconMap';
|
|
|
import Check from '@/pages/MenuManagement/check';
|
|
|
+import { delMenu, queryMenu } from '@/services/menu';
|
|
|
|
|
|
interface DataType {
|
|
|
+ key: React.ReactNode;
|
|
|
name: string;
|
|
|
menu_type: number;
|
|
|
sequence: number;
|
|
|
hidden: number;
|
|
|
icon: string;
|
|
|
record_id: string;
|
|
|
+ children?: DataType[];
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -33,27 +36,28 @@ const MenuManagement: React.FC = () => {
|
|
|
const [checkVisible, setCheckVisible] = useState(false);
|
|
|
const [checkData, setCheckData] = useState<object | null>({});
|
|
|
|
|
|
+ // 获取列表数据
|
|
|
const getList = () => {
|
|
|
- const data: any = [
|
|
|
- {
|
|
|
- name: '菜单名称',
|
|
|
- menu_type: 2,
|
|
|
- sequence: 20,
|
|
|
- hidden: 1,
|
|
|
- icon: 'security-scan',
|
|
|
- tag: 'web',
|
|
|
- router: '/editionManagement',
|
|
|
- creator: 'root',
|
|
|
- created_at: '2023-01-04T14:31:23.664+08:00',
|
|
|
- record_id: '1111',
|
|
|
- parent_id: '1111',
|
|
|
- },
|
|
|
- ];
|
|
|
- setDataList(data);
|
|
|
- setPagination({ total: 0, current: 1, pageSize: 10 });
|
|
|
+ const params = {
|
|
|
+ q: 'page',
|
|
|
+ current: pagination.current,
|
|
|
+ pageSize: pagination.pageSize,
|
|
|
+ ...searchData,
|
|
|
+ };
|
|
|
+ queryMenu(params).then((res) => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ res.data.list.forEach((el: { children: any[] }) => {
|
|
|
+ el.children = [];
|
|
|
+ });
|
|
|
+ setDataList(res.data.list);
|
|
|
+ setPagination(res.data.pagination);
|
|
|
+ setLoading(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
useEffect(() => {
|
|
|
+ setLoading(true);
|
|
|
getList();
|
|
|
}, []);
|
|
|
|
|
@@ -66,8 +70,13 @@ const MenuManagement: React.FC = () => {
|
|
|
pageSize: page.pageSize,
|
|
|
...searchData,
|
|
|
};
|
|
|
- console.log(params);
|
|
|
- // 请求接口
|
|
|
+ queryMenu(params).then((res) => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ setDataList(res.data.list);
|
|
|
+ setPagination(res.data.pagination);
|
|
|
+ setLoading(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
// 搜索
|
|
@@ -102,7 +111,18 @@ const MenuManagement: React.FC = () => {
|
|
|
title: '删除',
|
|
|
content: `确认删除菜单:[${record.name}]`,
|
|
|
onOk: () => {
|
|
|
- // 请求接口
|
|
|
+ delMenu(record.record_id)
|
|
|
+ .then((res) => {
|
|
|
+ if (res.data && res.data.status === 'OK') {
|
|
|
+ message.success('删除成功');
|
|
|
+ getList();
|
|
|
+ } else {
|
|
|
+ message.error('删除失败');
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ message.error(e?.message);
|
|
|
+ });
|
|
|
},
|
|
|
});
|
|
|
};
|
|
@@ -124,6 +144,27 @@ const MenuManagement: React.FC = () => {
|
|
|
setCheckVisible(false);
|
|
|
};
|
|
|
|
|
|
+ // const getChildrenList = () =>{
|
|
|
+ // const params = {
|
|
|
+ // q:'page',
|
|
|
+ //
|
|
|
+ // };
|
|
|
+ // queryMenu(params).then(res =>{
|
|
|
+ // if(res.code === 0){
|
|
|
+ // setDataList(res.data.list);
|
|
|
+ // setPagination(res.data.pagination);
|
|
|
+ // setLoading(false);
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 异步展开树table
|
|
|
+ const areaExpandedRowsChange = (expanded: any, record: any) => {
|
|
|
+ // 做一下限制,如果已经有数据,不再重复请求数据
|
|
|
+ if (expanded && record.children && record.children.length >= 0) {
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
const columns: ColumnsType<DataType> = [
|
|
|
{
|
|
|
title: '序号',
|
|
@@ -135,32 +176,16 @@ const MenuManagement: React.FC = () => {
|
|
|
title: '菜单名称',
|
|
|
dataIndex: 'name',
|
|
|
key: 'name',
|
|
|
- width: 250,
|
|
|
},
|
|
|
{
|
|
|
- title: '类型',
|
|
|
- dataIndex: 'menu_type',
|
|
|
- width: 100,
|
|
|
- render: (val) => {
|
|
|
- switch (val) {
|
|
|
- case 1:
|
|
|
- return <span style={{ color: '#f50' }}>系统</span>;
|
|
|
- case 2:
|
|
|
- return <span style={{ color: '#87d068' }}>通用</span>;
|
|
|
- case 3:
|
|
|
- return <span style={{ color: '#3c6bbc' }}>企业</span>;
|
|
|
- case 4:
|
|
|
- return <span style={{ color: '#b28317' }}>项目</span>;
|
|
|
- default:
|
|
|
- return <span style={{ color: '#590858' }}>无</span>;
|
|
|
- }
|
|
|
- },
|
|
|
+ title: '排序值',
|
|
|
+ dataIndex: 'sequence',
|
|
|
+ key: 'sequence',
|
|
|
},
|
|
|
{
|
|
|
title: '状态',
|
|
|
dataIndex: 'hidden',
|
|
|
align: 'center',
|
|
|
- width: 100,
|
|
|
render: (val) =>
|
|
|
val === 1 ? (
|
|
|
<span style={{ color: '#f50' }}>隐藏</span>
|
|
@@ -172,7 +197,6 @@ const MenuManagement: React.FC = () => {
|
|
|
title: '图标',
|
|
|
dataIndex: 'icon',
|
|
|
align: 'center',
|
|
|
- width: 100,
|
|
|
render: (val) => {
|
|
|
return tag === 'api' ? (
|
|
|
<img src={val} alt="val" style={{ width: 32 }} />
|
|
@@ -181,30 +205,11 @@ const MenuManagement: React.FC = () => {
|
|
|
);
|
|
|
},
|
|
|
},
|
|
|
- // {
|
|
|
- // title: '动作',
|
|
|
- // dataIndex: 'actions',
|
|
|
- // align: 'center',
|
|
|
- // width: 80,
|
|
|
- // render: val =>
|
|
|
- // val ? (
|
|
|
- // <Tooltip title={val.map((item: { name: any; }) => item.name).join(' ')}>
|
|
|
- // <span style={{ color: '#87d068' }}>{val.length} 动作</span>
|
|
|
- // </Tooltip>
|
|
|
- // ) : (
|
|
|
- // <span style={{ color: '#d07c63' }}>无动作</span>
|
|
|
- // ),
|
|
|
- // },
|
|
|
{
|
|
|
title: '访问路由',
|
|
|
dataIndex: 'router',
|
|
|
key: 'router',
|
|
|
},
|
|
|
- {
|
|
|
- title: '创建者',
|
|
|
- dataIndex: 'creator',
|
|
|
- key: 'creator',
|
|
|
- },
|
|
|
{
|
|
|
title: '创建时间',
|
|
|
dataIndex: 'created_at',
|
|
@@ -282,15 +287,11 @@ const MenuManagement: React.FC = () => {
|
|
|
pagination={paginationProps}
|
|
|
loading={loading}
|
|
|
onChange={tableChange}
|
|
|
+ expandable={{
|
|
|
+ onExpand: areaExpandedRowsChange,
|
|
|
+ }}
|
|
|
/>
|
|
|
- {visible && (
|
|
|
- <Edit
|
|
|
- visible={visible}
|
|
|
- treeData={dataList}
|
|
|
- editCallback={handleEdit}
|
|
|
- params={editData}
|
|
|
- />
|
|
|
- )}
|
|
|
+ {visible && <Edit visible={visible} editCallback={handleEdit} params={editData} />}
|
|
|
{checkVisible && (
|
|
|
<Check visible={checkVisible} checkCallback={checkCallback} params={checkData} />
|
|
|
)}
|