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

251 lines
9.0 KiB
TypeScript
Raw Normal View History

2024-03-22 21:22:12 +08:00
import './proj-config-list-mod.css';
import {
Alert,
2024-05-28 18:00:42 +08:00
Button,
2024-03-22 21:22:12 +08:00
message,
2024-05-28 18:00:42 +08:00
Table, TableProps, Modal
2024-03-22 21:22:12 +08:00
} from "antd";
2024-05-28 18:00:42 +08:00
import { useParams } from "react-router-dom";
2024-05-22 16:18:38 +08:00
import { useEffect, useState } from "react";
import { EditOutlined, PlusOutlined, DeleteOutlined } from "@ant-design/icons";
import { del, get } from "../../../util/AjaxUtils.ts";
2024-05-28 18:00:42 +08:00
import ConfigModSave from '../../proj/edit/ProjConfigModSave.tsx'
import ConfigModEdit from '../../proj/edit/ProjConfigModEdit.tsx'
2024-03-24 12:15:40 +08:00
2024-04-25 15:37:50 +08:00
export const MAX_MOD_SIZE = 15;
2024-04-12 18:18:14 +08:00
export const MIN_MOD_SIZE = 10
2024-06-21 16:18:01 +08:00
export const MAX_MOD_SIZE_FREE = 5
export const MIN_MOD_SIZE_FREE = 3
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;
2024-05-28 18:00:42 +08:00
projId?: string
2024-04-12 18:18:14 +08:00
}
export default function ProjConfigModList(props: PropType) {
2024-05-28 18:00:42 +08:00
const [configModSaveOpen, setConfigModSaveOpen] = useState(false)
const [configModEditOpen, setConfigModEdit] = useState(false)
const [projModId, setprojModId] = useState('')
// const nav = useNavigate();
2024-03-22 21:22:12 +08:00
const pathParams = useParams();
2024-05-28 18:00:42 +08:00
const [projId] = useState(pathParams.projId ? pathParams.projId : props.projId)
2024-03-22 21:22:12 +08:00
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
2024-05-28 18:00:42 +08:00
const height = window.innerHeight - 210;
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: {
2024-05-28 18:00:42 +08:00
projId: projId
2024-03-22 21:22:12 +08:00
}
},
2024-05-22 16:18:38 +08:00
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>
}
},
2024-06-07 16:39:22 +08:00
// {
// 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-05-22 16:18:38 +08:00
<Button type="primary" size="small"
style={{ marginRight: '5px' }}
onClick={() => {
2024-05-28 18:00:42 +08:00
// if (props.isFree) {
// // lyp
// nav(`/proj-edit/config-mod-fedit/${pathParams.projId}/${record.projModId}`)
// } else {
// nav(`/proj-edit/config-mod-edit/${pathParams.projId}/${record.projModId}`)
// }
setprojModId(record.projModId)
// console.log(record.projModId);
setConfigModEdit(true)
2024-05-22 16:18:38 +08:00
}}>
<EditOutlined />
</Button>
{/* {
2024-04-12 18:18:14 +08:00
modSize < maxSize ? (
2024-03-24 12:15:40 +08:00
<Button type="primary" size="small"
2024-05-22 16:18:38 +08:00
style={{ marginRight: '5px' }}
onClick={() => {
if (props.isFree) {
nav(`/proj-edit/config-mod-fedit/${pathParams.projId}/${record.projModId}`)
} else {
nav(`/proj-edit/config-mod-edit/${pathParams.projId}/${record.projModId}`)
}
}}>
<EditOutlined />
2024-03-24 12:15:40 +08:00
</Button>
) : (
<Button type="default" size="small"
2024-05-22 16:18:38 +08:00
style={{ marginRight: '5px' }}
onClick={() => {
if (props.isFree) {
nav(`/proj-edit/config-mod-fshow/${pathParams.projId}/${record.projModId}`)
} else {
nav(`/proj-edit/config-mod-show/${pathParams.projId}/${record.projModId}`)
}
}}>
<EditOutlined />
2024-03-24 12:15:40 +08:00
</Button>
)
2024-05-22 16:18:38 +08:00
} */}
2024-03-24 12:15:40 +08:00
<Button value="large" type="primary" size="small" danger
2024-05-22 16:18:38 +08:00
onClick={() => {
del({
messageApi,
2024-05-28 18:00:42 +08:00
url: `/api/proj-mod/remove/proj-id/${projId}/${record.projModId}`,
2024-05-22 16:18:38 +08:00
onSuccess() {
messageApi.success('删除成功');
renderData();
}
})
}}
><DeleteOutlined /></Button>
</>
)
}
},
];
useEffect(() => {
renderData();
2024-03-22 21:22:12 +08:00
}, [])
return (
<>
{contextHolder}
2024-05-21 11:21:34 +08:00
{/* <Breadcrumb
2024-03-22 21:22:12 +08:00
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: '系统菜单管理'},
]}
2024-05-21 11:21:34 +08:00
/> */}
2024-05-28 18:00:42 +08:00
<div className="mod-list-container" style={{ height: `${height}px` }}>
2024-05-22 16:18:38 +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-05-28 18:00:42 +08:00
// if (props.isFree) {
// nav(`/proj-edit/config-mod-fsave/${pathParams.projId}`)
// } else {
// nav(`/proj-edit/config-mod-save/${pathParams.projId}`)
// }
setConfigModSaveOpen(true)
2024-05-22 16:18:38 +08:00
}}><PlusOutlined /> </Button>
2024-03-24 12:15:40 +08:00
) : <></>
}
2024-03-22 21:22:12 +08:00
</div>
2024-05-22 16:18:38 +08:00
<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>
2024-05-28 18:00:42 +08:00
<Modal open={configModSaveOpen}
title="新增"
width={1500}
2024-06-21 16:18:01 +08:00
destroyOnClose={true}
2024-05-28 18:00:42 +08:00
onCancel={() => {
setConfigModSaveOpen(false);
}}
footer={null}
>
<ConfigModSave
projId={projId}
closeModal={() => {
2024-05-29 14:43:48 +08:00
renderData()
2024-05-28 18:00:42 +08:00
setConfigModSaveOpen(false)
}}></ConfigModSave>
</Modal>
<Modal open={configModEditOpen}
title="编辑"
width={1500}
onCancel={() => {
// setprojModId('')
// console.log(projModId);
setConfigModEdit(false);
}}
footer={null}
>
<ConfigModEdit
key={projModId}
closeModal={() => {
setConfigModEdit(false)
renderData()
}} projModId={projModId} ></ConfigModEdit>
</Modal>
2024-03-22 21:22:12 +08:00
</>
)
}