diff --git a/src/components/ai/AiHelper.tsx b/src/components/ai/AiHelper.tsx index 957eace..3142ff6 100644 --- a/src/components/ai/AiHelper.tsx +++ b/src/components/ai/AiHelper.tsx @@ -2,13 +2,15 @@ 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, ReloadOutlined} from "@ant-design/icons"; +import {CheckOutlined, EditOutlined, ReloadOutlined} from "@ant-design/icons"; import useMessage from "antd/es/message/useMessage"; +import TextArea from "antd/es/input/TextArea"; type PropsType = { projId: string; projIntroduction?: string; projDesc?: string; + projMods?: ProjModType[]; } type ProjModType = { @@ -23,11 +25,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([]); + + const [projModArray, setProjModArray] = useState(props.projMods ? props.projMods : []); const [newProjModArray, setNewProjModArray] = useState([]); const [isProjModArrayLoading, setIsProjModArrayLoading] = useState(false); @@ -78,7 +86,16 @@ 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}}, + { + title: '序号', + dataIndex: 'index', + key: 'index', + width: 60, + align: 'center', + render: (_value, _record, index) => { + return index + 1 + } + }, {title: '模块名称', dataIndex: 'name', key: 'name', width: 200, align: 'center'}, {title: '模块描述', dataIndex: 'desc', key: 'desc', align: 'center'}, ]; @@ -113,19 +130,19 @@ export default function AiHelper(props: PropsType) { /** * 保存简介 */ - const updateProjIntroduction = () => { + const updateProjIntroduction = (content: string) => { put({ messageApi, url: `/api/proj/update-introduction/${props.projId}`, body: { - content: newProjIntroduction + content: content }, onBefore() { setIsProjIntroductionLoading(true); }, onSuccess() { messageApi.success('保存成功'); - setProjIntroduction(newProjIntroduction); + setProjIntroduction(content); setNewProjIntroduction(''); }, onFinally() { @@ -137,19 +154,19 @@ export default function AiHelper(props: PropsType) { /** * 保存详情 */ - const updateProjDesc = () => { + const updateProjDesc = (content: string) => { put({ messageApi, url: `/api/proj/update-desc/${props.projId}`, body: { - content: newProjDesc + content: content }, onBefore() { setIsProjDescLoading(true); }, onSuccess() { messageApi.success('保存成功').then(); - setProjDesc(newProjDesc); + setProjDesc(content); setNewProjDesc(''); }, onFinally() { @@ -157,6 +174,29 @@ 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) { @@ -165,6 +205,105 @@ export default function AiHelper(props: PropsType) { 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} @@ -174,28 +313,29 @@ export default function AiHelper(props: PropsType) {
{newProjIntroduction ? 原简介 : <>} - {projIntroduction ?
{projIntroduction}
: } + {projIntroduction ? ( + isProjIntroductionEdit ?