From 4235a6fe56cd1348786a6cea54777cb0fa1fd0b3 Mon Sep 17 00:00:00 2001 From: WenC <450292408@qq.com> Date: Fri, 19 Apr 2024 21:09:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0AI=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ai/AiHelper.tsx | 97 +++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/src/components/ai/AiHelper.tsx b/src/components/ai/AiHelper.tsx index 73058fe..d5ddb30 100644 --- a/src/components/ai/AiHelper.tsx +++ b/src/components/ai/AiHelper.tsx @@ -1,7 +1,7 @@ import {useContext, useEffect, useRef, useState} from "react"; import {GlobalContext} from "../../context/GlobalContext.ts"; import {put, WebSocketBaseUrl} from "../../util/AjaxUtils.ts"; -import {Button, Divider, Empty, Space, Spin} from "antd"; +import {Button, Divider, Empty, Space, Spin, Table, TableProps} from "antd"; import {CheckOutlined, ReloadOutlined} from "@ant-design/icons"; import useMessage from "antd/es/message/useMessage"; @@ -11,6 +11,11 @@ type PropsType = { projDesc?: string; } +type ProjModType = { + name: string, + desc: string +} + export default function AiHelper(props: PropsType) { const globalContext = useContext(GlobalContext); const pingTimeout = useRef(-1); @@ -22,6 +27,9 @@ export default function AiHelper(props: PropsType) { const [projDesc, setProjDesc] = useState(props.projDesc ? props.projDesc : ''); const [newProjDesc, setNewProjDesc] = useState(''); const [isProjDescLoading, setIsProjDescLoading] = useState(false); + const [projModArray, setProjModArray] = useState([]); + const [newProjModArray, setNewProjModArray] = useState([]); + const [isProjModArrayLoading, setIsProjModArrayLoading] = useState(false); const ping = () => { clearTimeout(pingTimeout.current); @@ -45,21 +53,19 @@ export default function AiHelper(props: PropsType) { return; } const data = JSON.parse(event.data); - if (data.type == 'REFRESH_PROJ_INTRODUCTION') { - if (data.projId != props.projId) { - return; - } - setIsProjIntroductionLoading(false); - setNewProjIntroduction(data.content); + if (data.projId != props.projId) { return; } - if (data.type == 'REFRESH_PROJ_DESC') { - if (data.projId != props.projId) { - return; - } + if (data.type == 'REFRESH_PROJ_INTRODUCTION') { + setIsProjIntroductionLoading(false); + setNewProjIntroduction(data.content); + } else if (data.type == 'REFRESH_PROJ_DESC') { setIsProjDescLoading(false); setNewProjDesc(data.content); - return; + } else if (data.type == 'REFRESH_PROJ_MODS') { + setIsProjModArrayLoading(false); + const projMods = JSON.parse(data.content) as ProjModType[]; + setNewProjModArray(projMods); } } ws.current.onerror = (event) => { @@ -71,6 +77,11 @@ export default function AiHelper(props: PropsType) { } } + const projModColumnArray: TableProps['columns'] = [ + {title: '模块名称', dataIndex: 'name', key: 'name', width: 150, align: 'center'}, + {title: '模块描述', dataIndex: 'desc', key: 'desc', align: 'center'}, + ]; + const generateProjIntroduction = () => { ws.current?.send(JSON.stringify({ type: 'REFRESH_PROJ_INTRODUCTION', @@ -89,6 +100,15 @@ export default function AiHelper(props: PropsType) { setIsProjDescLoading(true); } + const generateProjModArray = () => { + ws.current?.send(JSON.stringify({ + type: 'REFRESH_PROJ_MODS', + projId: props.projId + })); + ping(); + setIsProjModArrayLoading(true); + } + /** * 保存简介 */ @@ -191,19 +211,46 @@ export default function AiHelper(props: PropsType) { }
-
- { - newProjDesc ? ( - - - - - ) : - } -
+ { + newProjDesc ? ( + + + + + ) : + } +
+ + +
项目模块
+ +
+ {newProjModArray.length > 0 ? 原模块 : <>} + + { + newProjModArray.length > 0 ? ( + <> + 新模块 +
+ + ) : <> + } + +
+ { + newProjModArray.length > 0 ? ( + + + + + ) : + }