system-copyright-react/src/route/proj/edit/ProjConfigModList.tsx

188 lines
6.7 KiB
TypeScript
Raw Normal View History

2024-03-22 21:22:12 +08:00
import './proj-config-list-mod.css';
import {
Alert,
Breadcrumb, Button,
message,
Table, TableProps,
} from "antd";
import {Link, useNavigate, useParams} from "react-router-dom";
import {useEffect, useState} from "react";
2024-03-24 12:15:40 +08:00
import {EditOutlined, PlusOutlined, DeleteOutlined, SearchOutlined} from "@ant-design/icons";
import {del, get} from "../../../util/AjaxUtils.ts";
2024-04-12 18:18:14 +08:00
export const MAX_MOD_SIZE = 18;
export const MIN_MOD_SIZE = 10
export const MAX_MOD_SIZE_FREE = 3
export const MIN_MOD_SIZE_FREE = 1
2024-03-22 21:22:12 +08:00
interface DataType {
projModId: string;
projId: string;
modContext: string;
modName: string;
modUrl: string;
modDesc: string;
modIcon: string;
}
2024-04-12 18:18:14 +08:00
type PropType = {
isFree?: boolean;
}
export default function ProjConfigModList(props: PropType) {
2024-03-22 21:22:12 +08:00
const nav = useNavigate();
const pathParams = useParams();
const [messageApi, contextHolder] = message.useMessage();
const [dataArray, setDataArray] = useState<DataType[]>();
2024-03-24 12:15:40 +08:00
const [modSize, setModSize] = useState(0);
2024-04-12 18:18:14 +08:00
const minSize = props.isFree ? MIN_MOD_SIZE_FREE : MIN_MOD_SIZE;
const maxSize = props.isFree ? MAX_MOD_SIZE_FREE : MAX_MOD_SIZE;
2024-03-24 12:15:40 +08:00
const height = window.innerHeight - 165;
2024-03-22 21:22:12 +08:00
const renderData = () => {
2024-04-01 20:39:22 +08:00
get<DataType[]>({
2024-03-22 21:22:12 +08:00
messageApi,
url: '/api/proj-mod/list',
config: {
params: {
projId: pathParams.projId
}
},
onSuccess({data}) {
2024-03-24 12:15:40 +08:00
setDataArray([...data]);
setModSize(data.length);
2024-03-22 21:22:12 +08:00
}
})
}
const columns: TableProps<DataType>['columns'] = [
{
title: '菜单标题',
dataIndex: 'modName',
align: 'center',
width: 180
},
{
title: '菜单说明',
dataIndex: 'modDesc',
align: 'center',
},
{
title: '图标',
dataIndex: 'modIcon',
align: 'center',
width: 80,
render: (_text) => {
return <i className={_text}> </i>
}
},
{
title: '菜单地址',
dataIndex: 'menuUrl',
align: 'center',
},
{
title: '创建时间',
dataIndex: 'gmtCreate',
align: 'center',
width: 180
},
{
title: '操作',
dataIndex: 'option',
align: 'center',
width: 100,
2024-03-24 12:15:40 +08:00
render: (_text, record) => {
return (
<>
2024-03-24 12:15:40 +08:00
{
2024-04-12 18:18:14 +08:00
modSize < maxSize ? (
2024-03-24 12:15:40 +08:00
<Button type="primary" size="small"
style={{marginRight: '5px'}}
onClick={() => {
2024-04-12 18:18:14 +08:00
if(props.isFree) {
nav(`/proj-edit/config-mod-fedit/${pathParams.projId}/${record.projModId}`)
} else {
nav(`/proj-edit/config-mod-edit/${pathParams.projId}/${record.projModId}`)
}
2024-03-24 12:15:40 +08:00
}}>
<EditOutlined/>
</Button>
) : (
<Button type="default" size="small"
style={{marginRight: '5px'}}
onClick={() => {
2024-04-12 18:18:14 +08:00
if(props.isFree) {
nav(`/proj-edit/config-mod-fshow/${pathParams.projId}/${record.projModId}`)
} else {
nav(`/proj-edit/config-mod-show/${pathParams.projId}/${record.projModId}`)
}
2024-03-24 12:15:40 +08:00
}}>
<SearchOutlined/>
</Button>
)
}
<Button value="large" type="primary" size="small" danger
onClick={() => {
2024-03-24 12:15:40 +08:00
del({
messageApi,
url: `/api/proj-mod/remove/proj-id/${pathParams.projId}/${record.projModId}`,
onSuccess() {
messageApi.success('删除成功');
renderData();
}
})
}}
><DeleteOutlined/></Button>
</>
)
}
},
];
useEffect(() => {
renderData();
2024-03-22 21:22:12 +08:00
}, [])
return (
<>
{contextHolder}
<Breadcrumb
items={[
{title: <Link to={'/'}></Link>},
{title: <Link to={'/proj-create'}></Link>},
2024-04-12 18:18:14 +08:00
{
title: <a onClick={() => {
nav(-1)
}}></a>
},
2024-03-22 21:22:12 +08:00
{title: '系统菜单管理'},
]}
/>
<div className="mod-list-container" style={{height: `${height}px`}}>
2024-04-12 18:18:14 +08:00
<Alert message={`菜单指的是系统的功能,最少${minSize}个菜单,最多${maxSize}个菜单`} type="info"/>
2024-03-22 21:22:12 +08:00
<div className="mod-list">
<div className="table-btn-group">
2024-03-24 12:15:40 +08:00
{
2024-04-12 18:18:14 +08:00
modSize < maxSize ? (
2024-03-24 12:15:40 +08:00
<Button value="small" onClick={() => {
2024-04-12 18:18:14 +08:00
if(props.isFree) {
nav(`/proj-edit/config-mod-fsave/${pathParams.projId}`)
} else {
nav(`/proj-edit/config-mod-save/${pathParams.projId}`)
}
2024-03-24 12:15:40 +08:00
}}><PlusOutlined/> </Button>
) : <></>
}
2024-03-22 21:22:12 +08:00
</div>
<Table columns={columns} dataSource={dataArray} pagination={{pageSize: 20}}
scroll={{y: height - 210}} size="middle" bordered key="dataTable" rowKey="projModId"/>
2024-03-22 21:22:12 +08:00
</div>
</div>
</>
)
}