2024-05-23 14:57:22 +08:00
|
|
|
import { Button, Divider, Dropdown, Space, Table, TableProps, Modal } from "antd";
|
|
|
|
import { CheckOutlined, LoadingOutlined, ReloadOutlined, RedoOutlined } from "@ant-design/icons";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { IProjMod } from "../../../interfaces/proj/IProj.ts";
|
|
|
|
import EditModal from '../../EditModal/EditModal.tsx'
|
2024-05-23 16:20:14 +08:00
|
|
|
import ConfigModModal from '../../ConfigModModal/ConfigModModal.tsx'
|
2024-05-23 14:57:22 +08:00
|
|
|
import { get } from "../../../util/AjaxUtils.ts";
|
|
|
|
import { useParams } from "react-router-dom";
|
2024-05-23 16:20:14 +08:00
|
|
|
import { SearchOutlined } from '@ant-design/icons';
|
2024-05-23 14:57:22 +08:00
|
|
|
import {
|
|
|
|
message
|
|
|
|
} from "antd";
|
2024-04-24 18:03:44 +08:00
|
|
|
type PropsType = {
|
|
|
|
mods: IProjMod[];
|
|
|
|
newMods: ProjModType[],
|
|
|
|
handleGenerate: () => void;
|
|
|
|
handleSave: (index: number, mod: ProjModType) => void;
|
|
|
|
handleResaveField: (index: number, projModId: string) => void;
|
2024-04-25 15:37:50 +08:00
|
|
|
handleRemove: (index: number, projModId: string, item: IProjMod) => void;
|
|
|
|
handleEdit: (index: number, projModId: string, item: IProjMod) => void;
|
2024-04-24 18:03:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProjModType = {
|
|
|
|
name: string,
|
|
|
|
desc: string,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function AiHelperMod(props: PropsType) {
|
2024-05-23 14:57:22 +08:00
|
|
|
// 菜单状态是否可以编辑
|
2024-05-23 16:57:36 +08:00
|
|
|
const [messageApi] = message.useMessage();
|
2024-04-24 18:03:44 +08:00
|
|
|
const [modArray, setModArray] = useState<IProjMod[]>([]);
|
|
|
|
const [newModArray, setNewModArray] = useState<ProjModType[]>([]);
|
2024-05-23 14:57:22 +08:00
|
|
|
const [id, setId] = useState('')
|
2024-05-23 16:20:14 +08:00
|
|
|
|
|
|
|
const[configModal,setConfigModal] = useState(false)
|
2024-05-23 14:57:22 +08:00
|
|
|
const [editModal, setEditModal] = useState(false)
|
|
|
|
const [updata, setUpdata] = useState<any[]>([])
|
|
|
|
const [status, setStatus] = useState('')
|
|
|
|
// const [items, setItems] = useState<any[]>([])
|
|
|
|
const pathParams = useParams();
|
2024-04-24 18:03:44 +08:00
|
|
|
useEffect(() => {
|
2024-05-23 14:57:22 +08:00
|
|
|
console.log('mods', props.mods);
|
|
|
|
|
2024-04-24 18:03:44 +08:00
|
|
|
setModArray(props.mods);
|
|
|
|
setNewModArray(props.newMods);
|
|
|
|
}, [props.mods, props.newMods]);
|
2024-05-23 14:57:22 +08:00
|
|
|
useEffect(() => {
|
|
|
|
if (updata.length != 0) {
|
|
|
|
console.log('更新数据', updata);
|
|
|
|
setModArray(updata)
|
|
|
|
}
|
|
|
|
|
|
|
|
}, [updata])
|
|
|
|
useEffect(() => {
|
|
|
|
get<any>({
|
|
|
|
messageApi,
|
|
|
|
url: `/api/proj/get/${pathParams.projId}`,
|
|
|
|
onSuccess({ data }) {
|
2024-05-23 16:20:14 +08:00
|
|
|
// console.log('其他页面状态判断', data);
|
2024-05-23 14:57:22 +08:00
|
|
|
setStatus(data.generate.generateStatus)
|
|
|
|
}
|
|
|
|
})
|
2024-04-24 18:03:44 +08:00
|
|
|
|
2024-05-23 14:57:22 +08:00
|
|
|
}, [])
|
2024-04-24 18:03:44 +08:00
|
|
|
const modColumnArray: TableProps<IProjMod>['columns'] = [
|
|
|
|
{
|
|
|
|
title: '序号',
|
|
|
|
dataIndex: 'index',
|
|
|
|
key: 'index',
|
|
|
|
width: 60,
|
|
|
|
align: 'center',
|
|
|
|
render: (_value, _record, index) => {
|
|
|
|
return index + 1
|
|
|
|
}
|
|
|
|
},
|
2024-05-23 14:57:22 +08:00
|
|
|
{ title: '模块名称', dataIndex: 'modName', key: 'name', width: 200, align: 'center' },
|
|
|
|
{ title: '模块描述', dataIndex: 'modDesc', key: 'desc', align: 'center' },
|
2024-04-24 18:03:44 +08:00
|
|
|
{
|
|
|
|
title: 'AI状态',
|
|
|
|
dataIndex: 'aiFieldStatus',
|
|
|
|
key: 'desc',
|
|
|
|
width: 100,
|
|
|
|
align: 'center',
|
|
|
|
render: (value) => {
|
2024-05-23 14:57:22 +08:00
|
|
|
if (value == 'GENERATING') {
|
2024-04-24 18:03:44 +08:00
|
|
|
return '处理中'
|
|
|
|
}
|
2024-05-23 14:57:22 +08:00
|
|
|
if (value == 'FAILED') {
|
2024-04-24 18:03:44 +08:00
|
|
|
return '失败'
|
|
|
|
}
|
2024-05-23 14:57:22 +08:00
|
|
|
if (value == 'SUCCESS') {
|
2024-04-24 18:03:44 +08:00
|
|
|
return '成功'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '操作',
|
|
|
|
dataIndex: 'option',
|
|
|
|
key: 'option',
|
|
|
|
width: 80,
|
|
|
|
align: 'center',
|
|
|
|
render: (_value, record, index) => {
|
2024-05-23 16:20:14 +08:00
|
|
|
if (status == 'SUCCESS') {
|
|
|
|
return (
|
|
|
|
<Button icon={<SearchOutlined />} onClick={() => {
|
|
|
|
setId(record.projModId)
|
|
|
|
setConfigModal(true)
|
|
|
|
}}></Button>
|
2024-05-23 14:57:22 +08:00
|
|
|
)
|
2024-05-23 16:20:14 +08:00
|
|
|
} else if (status == 'GENERATING') {
|
|
|
|
return (
|
2024-05-23 14:57:22 +08:00
|
|
|
<LoadingOutlined />
|
|
|
|
)
|
2024-04-24 18:03:44 +08:00
|
|
|
}
|
2024-05-23 16:20:14 +08:00
|
|
|
|
|
|
|
else {
|
2024-05-23 14:57:22 +08:00
|
|
|
if (record.aiFieldStatus == 'GENERATING') {
|
|
|
|
return <LoadingOutlined />
|
|
|
|
}
|
|
|
|
if (record.aiFieldStatus == 'FAILED') {
|
|
|
|
return <Button onClick={() => {
|
|
|
|
props.handleResaveField(index, record.projModId);
|
|
|
|
}}><RedoOutlined /></Button>
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Dropdown menu={{
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
key: 'edit',
|
|
|
|
label: '编辑',
|
|
|
|
onClick: () => {
|
|
|
|
// props.handleEdit(index, record.projModId, record);
|
|
|
|
setId(record.projModId)
|
|
|
|
setEditModal(true)
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
key: 'remove',
|
|
|
|
label: '删除',
|
|
|
|
onClick: () => {
|
|
|
|
props.handleRemove(index, record.projModId, record);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}} placement="bottom" arrow>
|
|
|
|
<Button>…</Button>
|
|
|
|
</Dropdown>
|
|
|
|
)
|
2024-04-24 18:03:44 +08:00
|
|
|
}
|
2024-05-23 14:57:22 +08:00
|
|
|
// if (record.aiFieldStatus == 'GENERATING') {
|
|
|
|
// return <LoadingOutlined />
|
|
|
|
// }
|
|
|
|
// if (record.aiFieldStatus == 'FAILED') {
|
|
|
|
// return <Button onClick={() => {
|
|
|
|
// props.handleResaveField(index, record.projModId);
|
|
|
|
// }}><RedoOutlined /></Button>
|
|
|
|
// }
|
|
|
|
// return (
|
|
|
|
// <Dropdown menu={{
|
|
|
|
// items: [
|
|
|
|
// {
|
|
|
|
// key: 'edit',
|
|
|
|
// label: '编辑',
|
|
|
|
// onClick: () => {
|
|
|
|
// // props.handleEdit(index, record.projModId, record);
|
|
|
|
// setId(record.projModId)
|
|
|
|
// setEditModal(true)
|
|
|
|
// }
|
|
|
|
// }, {
|
|
|
|
// key: 'remove',
|
|
|
|
// label: '删除',
|
|
|
|
// onClick: () => {
|
|
|
|
// props.handleRemove(index, record.projModId, record);
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// ]
|
|
|
|
// }} placement="bottom" arrow>
|
|
|
|
// <Button>…</Button>
|
|
|
|
// </Dropdown>
|
|
|
|
// )
|
|
|
|
// if (record.aiFieldStatus == 'SUCCESS' || status == 'GENERATING') {
|
|
|
|
// return (
|
|
|
|
// <Dropdown menu={{
|
|
|
|
// items: [
|
2024-05-23 16:20:14 +08:00
|
|
|
|
2024-05-23 14:57:22 +08:00
|
|
|
// ]
|
|
|
|
// }} placement="bottom" arrow>
|
|
|
|
// <Button>…</Button>
|
|
|
|
// </Dropdown>
|
|
|
|
// )
|
|
|
|
// }else{
|
|
|
|
// return(
|
|
|
|
// <Dropdown menu={{
|
|
|
|
// items: [
|
|
|
|
// {
|
|
|
|
// key: 'edit',
|
|
|
|
// label: '编辑',
|
|
|
|
// onClick: () => {
|
|
|
|
// // props.handleEdit(index, record.projModId, record);
|
|
|
|
// setId(record.projModId)
|
|
|
|
// setEditModal(true)
|
|
|
|
// }
|
|
|
|
// }, {
|
|
|
|
// key: 'remove',
|
|
|
|
// label: '删除',
|
|
|
|
// onClick: () => {
|
|
|
|
// props.handleRemove(index, record.projModId, record);
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// ]
|
|
|
|
// }} placement="bottom" arrow>
|
|
|
|
// <Button>…</Button>
|
|
|
|
// </Dropdown>
|
|
|
|
// )
|
|
|
|
// }
|
2024-04-24 18:03:44 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const newModColumnArray: TableProps<ProjModType>['columns'] = [
|
|
|
|
{
|
|
|
|
title: '序号',
|
|
|
|
dataIndex: 'index',
|
|
|
|
key: 'index',
|
|
|
|
width: 60,
|
|
|
|
align: 'center',
|
|
|
|
render: (_value, _record, index) => {
|
|
|
|
return index + 1
|
|
|
|
}
|
|
|
|
},
|
2024-05-23 14:57:22 +08:00
|
|
|
{ title: '模块名称', dataIndex: 'name', key: 'name', width: 200, align: 'center' },
|
|
|
|
{ title: '模块描述', dataIndex: 'desc', key: 'desc', align: 'center' },
|
2024-04-24 18:03:44 +08:00
|
|
|
{
|
|
|
|
title: '确认',
|
|
|
|
dataIndex: 'option',
|
|
|
|
key: 'option',
|
|
|
|
width: 80,
|
|
|
|
align: 'center',
|
|
|
|
render: (_value, record, index) => {
|
|
|
|
return (
|
|
|
|
<Button onClick={() => {
|
|
|
|
props.handleSave(index, record);
|
|
|
|
}}>
|
|
|
|
<CheckOutlined />
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-05-23 14:57:22 +08:00
|
|
|
<div style={{ padding: '5px 0 0 0', fontWeight: 'bold' }}>模块管理</div>
|
|
|
|
<div style={{ padding: '5px 0 0 0' }}>
|
2024-04-24 18:03:44 +08:00
|
|
|
{newModArray.length > 0 ? <Divider orientation="right" plain>原模块</Divider> : <></>}
|
2024-05-23 14:57:22 +08:00
|
|
|
<Table columns={modColumnArray} dataSource={modArray} size="small" bordered={true} scroll={{ y: 240 }}
|
|
|
|
pagination={false} rowKey="projModId" />
|
2024-04-24 18:03:44 +08:00
|
|
|
{
|
|
|
|
newModArray.length > 0 ? (
|
|
|
|
<>
|
|
|
|
<Divider orientation="right" plain>新模块</Divider>
|
2024-04-25 15:37:50 +08:00
|
|
|
<Table columns={newModColumnArray} dataSource={newModArray} size="small" bordered={true}
|
2024-05-23 14:57:22 +08:00
|
|
|
scroll={{ y: 240 }} pagination={false} rowKey="id" />
|
2024-04-24 18:03:44 +08:00
|
|
|
</>
|
|
|
|
) : <></>
|
|
|
|
}
|
|
|
|
</div>
|
2024-05-23 14:57:22 +08:00
|
|
|
<div style={{ padding: '5px 0 0 0', textAlign: 'center' }}>
|
2024-04-24 18:03:44 +08:00
|
|
|
{
|
|
|
|
newModArray.length > 0 ? (
|
|
|
|
<Space>
|
2024-05-23 14:57:22 +08:00
|
|
|
<Button type="link" style={{ cursor: 'pointer' }}
|
2024-04-24 18:03:44 +08:00
|
|
|
onClick={() => {
|
|
|
|
props.handleGenerate();
|
2024-05-23 14:57:22 +08:00
|
|
|
}}><ReloadOutlined /> 重新生成</Button>
|
|
|
|
</Space>
|
2024-05-23 16:20:14 +08:00
|
|
|
) : <Button type="link" disabled={status == 'SUCCESS' || status == 'GENERATING' ? true : false} style={{ cursor: 'pointer' }}
|
2024-05-23 14:57:22 +08:00
|
|
|
onClick={() => {
|
|
|
|
props.handleGenerate();
|
|
|
|
}}>AI生成</Button>
|
2024-04-24 18:03:44 +08:00
|
|
|
}
|
|
|
|
</div>
|
2024-05-23 14:57:22 +08:00
|
|
|
<Modal title="编辑" open={editModal} footer={null} onCancel={() => { setEditModal(false) }} width={1200} >
|
|
|
|
< EditModal id={id} onConfirm={() => setEditModal(false)} setUpdata={setUpdata} />
|
2024-05-23 16:20:14 +08:00
|
|
|
</Modal>
|
|
|
|
<Modal title="查看" open={configModal} footer={null} onCancel={() => { setConfigModal(false) }} width={1200} >
|
|
|
|
<ConfigModModal id={id} onConfirm={() => setConfigModal(false)} ></ConfigModModal>
|
2024-05-23 14:57:22 +08:00
|
|
|
</Modal>
|
2024-04-24 18:03:44 +08:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|