system-copyright-react/src/components/ai/mod/AiHelperMod.tsx

587 lines
23 KiB
TypeScript
Raw Normal View History

2024-06-14 15:50:34 +08:00
import './ai-helper-mod.css'
2024-12-03 11:58:34 +08:00
import {
Button,
2024-06-14 15:50:34 +08:00
// Divider, Dropdown, Space,
2025-01-17 16:50:18 +08:00
Table, TableProps, Modal,
// notification
2024-12-03 11:58:34 +08:00
} from "antd";
2025-01-17 16:50:18 +08:00
// const close = () => {
// console.log(
// 'Notification was closed. Either the close button was clicked or duration time elapsed.',
// );
// };
2024-06-14 15:50:34 +08:00
import {
// CheckOutlined,
2024-12-03 11:58:34 +08:00
LoadingOutlined,
2024-06-14 15:50:34 +08:00
// ReloadOutlined,
2024-12-03 11:58:34 +08:00
RedoOutlined
} from "@ant-design/icons";
2024-05-23 14:57:22 +08:00
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-06-14 15:50:34 +08:00
import noTextImg from '../../../static/noText.png'
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;
2025-01-17 16:50:18 +08:00
setActiveTab: (key: string) => void;
xixi: any;
projIntroduction: string;
isFast: boolean;
2025-01-21 11:32:53 +08:00
setisFast: any;
setIsProjModArrayLoading: any;
2025-01-21 11:50:09 +08:00
chargeType: string;
2025-03-11 17:20:30 +08:00
isDisabled?: boolean;
2024-04-24 18:03:44 +08:00
}
type ProjModType = {
name: string,
desc: string,
}
export default function AiHelperMod(props: PropsType) {
2024-06-14 15:50:34 +08:00
const height = window.innerHeight - 265;
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
2024-06-14 15:50:34 +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('')
2024-12-23 11:42:46 +08:00
2024-05-23 14:57:22 +08:00
// const [items, setItems] = useState<any[]>([])
const pathParams = useParams();
2025-01-17 16:50:18 +08:00
// useEffect(() => {
// // console.log('mods', props.mods);
// if( newModArray.length > 0){
// alert('请先保存')
// }
// }, [modArray, newModArray]);
// const key = `open${Date.now()}`;
2024-04-24 18:03:44 +08:00
useEffect(() => {
2025-01-21 11:32:53 +08:00
2024-05-23 14:57:22 +08:00
2024-04-24 18:03:44 +08:00
setModArray(props.mods);
setNewModArray(props.newMods);
2025-01-20 18:53:41 +08:00
get<any>({
messageApi,
url: `/api/proj/get/${pathParams.projId}`,
onSuccess({ data }) {
// console.log('其他页面状态判断', data);
// setStatus(data.generate.generateStatus)
2025-01-21 11:32:53 +08:00
if (data.aiSetting.modsStatus == 'GENERATING') {
2025-01-20 18:53:41 +08:00
// console.log('嘻嘻');
props.setIsProjModArrayLoading()
2025-01-21 11:32:53 +08:00
2025-01-20 18:53:41 +08:00
}
}
})
2025-01-21 11:32:53 +08:00
2024-04-24 18:03:44 +08:00
}, [props.mods, props.newMods]);
2025-01-17 16:50:18 +08:00
// useEffect(() => {
// // console.log('mods', props.mods);
// if (newModArray.length > 0 && newModArray != props.newMods) {
// notification.open({
// message: '提示',
// description:
// `功能列表已生成完毕,是否前去查看?`,
// btn: (
// <div>
// <Button size="small" type="primary" onClick={() => {
// notification.destroy(key)
// props.setActiveTab('模块')
// }}>
// 确定
// </Button>
// </div>
// ),
// key,
// onClose: close,
// duration: null,
// placement: 'bottomRight', // 设置通知框显示在右下角
// style: {
// width: 300, // 设置通知框的宽度
// height: 150, // 设置通知框的高度
// },
// });
// }
// }, [newModArray]);
2024-05-23 14:57:22 +08:00
useEffect(() => {
if (updata.length != 0) {
2024-07-31 16:00:30 +08:00
// console.log('更新数据', updata);
2024-05-23 14:57:22 +08:00
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-12-23 11:42:46 +08:00
const returnValue = (value: string) => {
2024-12-03 11:58:34 +08:00
// 如果value包含. / \ ` ! @ # $ % ^ & * ( ) 等特殊符号 去掉
// return value.replace(/[\\/:*?"<>|]/g, '');
return value.replace(/[./\\`!@#$%^&*()]/g, '');
}
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-12-23 11:42:46 +08:00
{
title: '模块名称', dataIndex: 'modName', key: 'name', width: 200, align: 'center',
2024-12-03 11:58:34 +08:00
render: (value) => {
return (
<div>
{returnValue(value)}
</div>
)
}
2024-12-23 11:42:46 +08:00
},
2024-05-23 14:57:22 +08:00
{ 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-06-14 15:50:34 +08:00
return (
<span style={{ color: '#FF4040 ' }}></span>
)
2024-04-24 18:03:44 +08:00
}
2024-05-23 14:57:22 +08:00
if (value == 'SUCCESS') {
2024-06-14 15:50:34 +08:00
return <span style={{ color: '#00A351' }}></span>
2024-04-24 18:03:44 +08:00
}
}
},
{
title: '操作',
dataIndex: 'option',
key: 'option',
2025-01-17 16:50:18 +08:00
width: 100,
2024-04-24 18:03:44 +08:00
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 (
<div style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
// 禁止换行
whiteSpace: 'nowrap',
}}>
<div
style={{
cursor: 'pointer',
// background: 'pink',
2025-01-17 16:50:18 +08:00
width: 40,
}}
onClick={() => {
props.handleResaveField(index, record.projModId);
}}><RedoOutlined /></div>
<div
style={{
cursor: 'pointer',
2025-01-19 10:19:11 +08:00
marginLeft: 5,
color: '#FF4040',
2025-01-17 16:50:18 +08:00
width: 40,
}}
onClick={() => {
props.handleRemove(index, record.projModId, record);
}}
></div>
</div>
)
2024-05-23 14:57:22 +08:00
}
return (
2024-12-24 15:41:20 +08:00
<div
2025-01-17 16:50:18 +08:00
style={{
whiteSpace: 'nowrap', display: 'flex',
alignItems: 'center',
justifyContent: 'center',
2025-01-17 16:50:18 +08:00
}}
>
<div
2024-06-14 15:50:34 +08:00
style={{
cursor: 'pointer',
2025-01-17 16:50:18 +08:00
width: 40,
2024-06-14 15:50:34 +08:00
}}
onClick={() => {
setId(record.projModId)
setEditModal(true)
}}
></div>
<div
2024-06-14 15:50:34 +08:00
style={{
cursor: 'pointer',
2025-01-17 16:50:18 +08:00
marginLeft: 5,
color: '#FF4040',
2025-01-17 16:50:18 +08:00
width: 40,
2024-06-14 15:50:34 +08:00
}}
onClick={() => {
props.handleRemove(index, record.projModId, record);
}}
></div>
2024-06-14 15:50:34 +08:00
</div>
2025-01-21 11:32:53 +08:00
2024-05-23 14:57:22 +08:00
)
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
}
},
];
2024-12-23 11:42:46 +08:00
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-12-03 11:58:34 +08:00
{
title: '模块名称', dataIndex: 'name', key: 'name', width: 200, align: 'center',
render: (value) => {
return (
<div>
{returnValue(value)}
</div>
)
}
},
2024-05-23 14:57:22 +08:00
{ title: '模块描述', dataIndex: 'desc', key: 'desc', align: 'center' },
2024-04-24 18:03:44 +08:00
{
2024-06-14 15:50:34 +08:00
title: '操作',
2024-04-24 18:03:44 +08:00
dataIndex: 'option',
key: 'option',
width: 80,
align: 'center',
render: (_value, record, index) => {
return (
2024-06-14 15:50:34 +08:00
// <Button onClick={() => {
// props.handleSave(index, record);
// }}>
// 添加
// </Button>
<span style={{ cursor: 'pointer' }}
onClick={() => {
2025-03-11 17:20:30 +08:00
if (props.isDisabled) {
return
}else{
props.handleSave(index, record);
}
// props.handleSave(index, record);
2024-06-14 15:50:34 +08:00
}}
>
</span>
2024-04-24 18:03:44 +08:00
)
}
},
];
return (
2024-06-14 15:50:34 +08:00
// <>
// <div style={{ padding: '5px 0 0 0', fontWeight: 'bold' }}>模块管理</div>
// <div style={{ padding: '5px 0 0 0' }}>
// {newModArray.length > 0 ? <Divider orientation="right" plain>原模块</Divider> : <></>}
// <Table columns={modColumnArray} dataSource={modArray} size="small" bordered={true} scroll={{ y: 240 }}
// pagination={false} rowKey="projModId" />
// {
// newModArray.length > 0 ? (
// <>
// <Divider orientation="right" plain>新模块</Divider>
// <Table columns={newModColumnArray} dataSource={newModArray} size="small" bordered={true}
// scroll={{ y: 240 }} pagination={false} rowKey="id" />
// </>
// ) : <></>
// }
// </div>
// <div style={{ padding: '5px 0 0 0', textAlign: 'center' }}>
// {
// newModArray.length > 0 ? (
// <Space>
// <Button type="link" style={{ cursor: 'pointer' }}
// onClick={() => {
// props.handleGenerate();
// }}><ReloadOutlined /> 重新生成</Button>
// </Space>
// ) : <Button type="link" disabled={status == 'SUCCESS' || status == 'GENERATING' ? true : false} style={{ cursor: 'pointer' }}
// onClick={() => {
// props.handleGenerate();
// }}>AI生成</Button>
// }
// </div>
// <Modal title="编辑"
// destroyOnClose={true}
// open={editModal} footer={null} onCancel={() => { setEditModal(false) }} width={1200} >
// < EditModal id={id} onConfirm={() => setEditModal(false)} setUpdata={setUpdata} />
// </Modal>
// <Modal title="查看"
// destroyOnClose={true}
// open={configModal} footer={null} onCancel={() => { setConfigModal(false) }} width={1200} >
// <ConfigModModal id={id} onConfirm={() => setConfigModal(false)} ></ConfigModModal>
// </Modal>
// </>
2024-12-03 11:58:34 +08:00
<div style={{ height: `${height}px`, border: '1px solid #D5D5D5', overflow: 'auto' }}>
2024-06-14 15:50:34 +08:00
<div className="aiMod-top">
{modArray.length > 0 ?
<>
<div className='aiMod-top-table' >
<Table columns={modColumnArray} dataSource={modArray} size="small" bordered={true}
pagination={false}
rowKey="projModId"
/>
</div>
{/* <div className="aiMod-top-btn">
<Button type="primary"
style={{
marginLeft: 15
}}
></Button>
</div> */}
</>
:
<div style={{
display: 'flex',
2024-06-14 15:50:34 +08:00
alignItems: 'center',
justifyContent: 'center',
fontSize: '14px',
2024-06-14 15:50:34 +08:00
}}
>
<div style={{
width: 300, height: 300, marginTop: 10, position: 'relative',
2024-12-23 11:42:46 +08:00
// backgroundColor:'pink'
}}>
2024-06-14 15:50:34 +08:00
<img src={noTextImg} alt="" width={'100%'} />
2024-12-23 11:42:46 +08:00
<div style={{ position: 'absolute', left: 90, bottom: 100, color: '#99A5B7' }}>
<div>
,
<span style={{ color: '#FF9D00', cursor: 'pointer' }}
onClick={() => {
2025-01-20 08:50:05 +08:00
props.setisFast()
2025-01-17 16:50:18 +08:00
if (props.isFast) {
return
} else {
if (props.projIntroduction) {
props.handleGenerate()
} else {
props.xixi()
}
}
2024-12-23 11:42:46 +08:00
}}
></span>
2024-12-23 11:42:46 +08:00
</div>
2024-06-14 15:50:34 +08:00
</div>
<div style={{ color: 'red', position: 'absolute', bottom: 70, textAlign: 'center', width: 600, left: -140 }}></div>
2024-12-23 11:42:46 +08:00
2024-06-14 15:50:34 +08:00
</div>
2024-12-23 11:42:46 +08:00
2024-06-14 15:50:34 +08:00
</div>
2024-04-24 18:03:44 +08:00
}
2024-06-14 15:50:34 +08:00
2024-04-24 18:03:44 +08:00
</div>
2024-06-14 15:50:34 +08:00
<div className="aiMod-center">
2025-01-21 11:32:53 +08:00
<div style={{
height: 42, background: " #EFEFEF",
display: 'flex', justifyContent: 'center', alignItems: 'center',
}}>
<div style={{
color: 'red',
fontSize: 14,
}}>
2025-01-21 11:50:09 +08:00
{props.chargeType =='FREE'?'*功能列表数量为3~5个如数量不满足请继续用AI生成':'*功能列表数量为10~15个如数量不满足请继续用AI生成'}
{/* *功能列表数量为10~15个如数量不满足请继续用AI生成 */}
2025-01-21 11:32:53 +08:00
</div>
</div>
2024-06-14 15:50:34 +08:00
</div>
<div className="aiMod-bot">
<div className='aiMod-bot-table'>
{newModArray.length > 0 ?
<div style={{
border: '1px solid #f0f0f0',
borderRadius: '10px'
}}>
<Table columns={newModColumnArray} dataSource={newModArray} size="small" bordered={true}
pagination={false} rowKey="id" />
</div>
:
<>
<span style={{
color: '#ABABAB',
2024-12-03 11:58:34 +08:00
fontSize: 16
2024-12-26 09:52:48 +08:00
}}> AI自动生成后可自动生成功能列表...</span>
2024-06-14 15:50:34 +08:00
</>}
</div>
<div className="aiMod-bot-btn">
<Button type="primary"
style={{
marginLeft: 15,
width: 109,
}}
2025-01-17 16:50:18 +08:00
disabled={status == 'SUCCESS' || status == 'GENERATING' || props.isFast ? true : false}
2024-05-23 14:57:22 +08:00
onClick={() => {
2025-01-20 08:50:05 +08:00
props.setisFast()
2025-01-21 11:32:53 +08:00
if (props.projIntroduction) {
2025-01-19 10:19:11 +08:00
props.handleGenerate()
2025-01-21 11:32:53 +08:00
} else {
2025-01-19 10:19:11 +08:00
props.xixi()
}
// props.handleGenerate()
2024-06-14 15:50:34 +08:00
}}
>AI生成</Button>
</div>
2025-01-17 16:50:18 +08:00
2024-04-24 18:03:44 +08:00
</div>
2024-06-14 15:50:34 +08:00
<Modal title="编辑"
destroyOnClose={true}
open={editModal} footer={null} onCancel={() => { setEditModal(false) }} width={1200} >
2024-05-23 14:57:22 +08:00
< EditModal id={id} onConfirm={() => setEditModal(false)} setUpdata={setUpdata} />
2024-05-23 16:20:14 +08:00
</Modal>
2024-06-14 15:50:34 +08:00
<Modal title="查看"
destroyOnClose={true}
open={configModal} footer={null} onCancel={() => { setConfigModal(false) }} width={1200} >
2024-05-23 16:20:14 +08:00
<ConfigModModal id={id} onConfirm={() => setConfigModal(false)} ></ConfigModModal>
2024-05-23 14:57:22 +08:00
</Modal>
2024-06-14 15:50:34 +08:00
</div>
2024-04-24 18:03:44 +08:00
)
}