diff --git a/src/components/ai/AiHelper.tsx b/src/components/ai/AiHelper.tsx index 3142ff6..27b2040 100644 --- a/src/components/ai/AiHelper.tsx +++ b/src/components/ai/AiHelper.tsx @@ -1,10 +1,12 @@ import {useContext, useEffect, useRef, useState} from "react"; import {GlobalContext} from "../../context/GlobalContext.ts"; -import {put, WebSocketBaseUrl} from "../../util/AjaxUtils.ts"; -import {Button, Col, Divider, Empty, Row, Space, Spin, Table, TableProps} from "antd"; -import {CheckOutlined, EditOutlined, ReloadOutlined} from "@ant-design/icons"; +import {get, post, put, WebSocketBaseUrl} from "../../util/AjaxUtils.ts"; +import {Col, Divider, Row, Spin} from "antd"; import useMessage from "antd/es/message/useMessage"; -import TextArea from "antd/es/input/TextArea"; +import AiHelperText from "./text/AiHelperText.tsx"; +import AiHelperMod from "./mod/AiHelperMod.tsx"; +import {IProjMod} from "../../interfaces/proj/IProj.ts"; +import {MAX_MOD_SIZE} from "../../route/proj/edit/ProjConfigModList.tsx"; type PropsType = { projId: string; @@ -14,6 +16,7 @@ type PropsType = { } type ProjModType = { + id: string, name: string, desc: string } @@ -25,20 +28,17 @@ export default function AiHelper(props: PropsType) { const [messageApi, messageApiHolder] = useMessage(); const [projIntroduction, setProjIntroduction] = useState(props.projIntroduction ? props.projIntroduction : ''); const [newProjIntroduction, setNewProjIntroduction] = useState(''); - const [isProjIntroductionEdit, setIsProjIntroductionEdit] = useState(false); - const [isNewProjIntroductionEdit, setIsNewProjIntroductionEdit] = useState(false); const [isProjIntroductionLoading, setIsProjIntroductionLoading] = useState(false); const [projDesc, setProjDesc] = useState(props.projDesc ? props.projDesc : ''); const [newProjDesc, setNewProjDesc] = useState(''); - const [isProjDescEdit, setIsProjDescEdit] = useState(false); - const [isNewProjDescEdit, setIsNewProjDescEdit] = useState(false); const [isProjDescLoading, setIsProjDescLoading] = useState(false); - const [projModArray, setProjModArray] = useState(props.projMods ? props.projMods : []); + const [projModArray, setProjModArray] = useState([]); const [newProjModArray, setNewProjModArray] = useState([]); const [isProjModArrayLoading, setIsProjModArrayLoading] = useState(false); + const ping = () => { clearTimeout(pingTimeout.current); pingTimeout.current = setTimeout(() => { @@ -74,6 +74,8 @@ export default function AiHelper(props: PropsType) { setIsProjModArrayLoading(false); const projMods = JSON.parse(data.content) as ProjModType[]; setNewProjModArray(projMods); + } else if (data.type == 'REFRESH_PROJ_MOD_FIELDS') { + listMods(); } } ws.current.onerror = (event) => { @@ -85,20 +87,21 @@ export default function AiHelper(props: PropsType) { } } - const projModColumnArray: TableProps['columns'] = [ - { - title: '序号', - dataIndex: 'index', - key: 'index', - width: 60, - align: 'center', - render: (_value, _record, index) => { - return index + 1 + const listMods = () => { + get({ + messageApi, + url: `/api/proj-mod/list/proj-id/${props.projId}`, + onBefore() { + setIsProjModArrayLoading(true); + }, + onSuccess({data}) { + setProjModArray(data); + }, + onFinally() { + setIsProjModArrayLoading(false); } - }, - {title: '模块名称', dataIndex: 'name', key: 'name', width: 200, align: 'center'}, - {title: '模块描述', dataIndex: 'desc', key: 'desc', align: 'center'}, - ]; + }) + } const generateProjIntroduction = () => { ws.current?.send(JSON.stringify({ @@ -174,239 +177,106 @@ export default function AiHelper(props: PropsType) { } }) } - /** - * 保存模块 - */ - const updateProjModArray = () => { - put({ - messageApi, - url: `/api/proj-mod/update-mods/${props.projId}`, - body: { - list: newProjModArray - }, - onBefore() { - setIsProjModArrayLoading(true); - }, - onSuccess() { - messageApi.success('保存成功').then(); - setProjModArray(newProjModArray); - setNewProjModArray([]); - }, - onFinally() { - setIsProjModArrayLoading(false) - } - }) - } useEffect(() => { if (!props.projId) { return; } + listMods(); websocket(); }, [globalContext.user.userId, props.projId]); - /** - * 项目简介按钮 - */ - const renderNewProjIntroductionBtn = () => { - if(!newProjIntroduction) { - if(!isProjIntroductionEdit) { - return ( - - - { - projIntroduction ? ( - - ) : <> - } - - ) - } - return ( - - - - ) - } - if(!isNewProjIntroductionEdit) { - return ( - - - - - - ) - } - return ( - - - - ) - } - /** - * 项目简介按钮 - */ - const renderNewProjDescBtn = () => { - if(!newProjDesc) { - if(!isProjDescEdit) { - return ( - - - { - projIntroduction ? ( - - ) : <> - } - - ) - } - return ( - - - - ) - } - if(!isNewProjDescEdit) { - return ( - - - - - - ) - } - return ( - - - - ) - } - return ( <> {messageApiHolder} -
项目简介
-
- {newProjIntroduction ? 原简介 : <>} - {projIntroduction ? ( - isProjIntroductionEdit ?