From 2ebbc7374ad03bbbe8c4c875aef4560a233fa294 Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Fri, 19 Jul 2024 10:12:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=8E=A5=E5=85=A5=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react-ui/package.json | 1 + react-ui/src/assets/img/robot.png | Bin 0 -> 1789 bytes react-ui/src/components/RobotFrame/index.less | 34 ++++++++++++++++ react-ui/src/components/RobotFrame/index.tsx | 30 ++++++++++++++ react-ui/src/hooks/draggable.ts | 37 ++++++++++++++++++ react-ui/src/pages/Workspace/index.less | 11 ++++++ react-ui/src/pages/Workspace/index.tsx | 20 ++++++++++ 7 files changed, 133 insertions(+) create mode 100644 react-ui/src/assets/img/robot.png create mode 100644 react-ui/src/components/RobotFrame/index.less create mode 100644 react-ui/src/components/RobotFrame/index.tsx create mode 100644 react-ui/src/hooks/draggable.ts diff --git a/react-ui/package.json b/react-ui/package.json index cab066ed..e7651dec 100644 --- a/react-ui/package.json +++ b/react-ui/package.json @@ -76,6 +76,7 @@ "react-cropper": "^2.3.3", "react-dev-inspector": "^1.8.1", "react-dom": "^18.2.0", + "react-draggable": "^4.4.6", "react-helmet-async": "^1.3.0", "react-highlight": "^0.15.0" }, diff --git a/react-ui/src/assets/img/robot.png b/react-ui/src/assets/img/robot.png new file mode 100644 index 0000000000000000000000000000000000000000..e91be9ac1d1a3b443719ca963cb959685b057580 GIT binary patch literal 1789 zcmVPx*w@E}nRCr$Poo#O1I1GlR?FHHsCAq>D3*+dtoi z?jrI_0`UCv&Th&Pvm;ms*+iMrs8&O~q1$qGR^c!(p$!cDr001Z{swG>OC~yG);op+)O4ar4 z`&aJ~{!7Ve(9UP~1ON>Btz4D6lYjpA_b()Nl#|qyCGXAvz?8=dSGEV>CkB9pWwm1t z0NC+Wt(qbN)Kb=nT>x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ame/index.less new file mode 100644 index 00000000..e3e5662e --- /dev/null +++ b/react-ui/src/components/RobotFrame/index.less @@ -0,0 +1,34 @@ +.robot-frame { + position: fixed; + top: 55px; + right: -610px; + z-index: 100; + width: 600px; + height: calc(100% - 55px); + background-color: #fff; + box-shadow: -6px 0 16px 0 rgba(0, 0, 0, 0.08), -3px 0 6px -4px rgba(0, 0, 0, 0.12), + -9px 0 28px 8px rgba(0, 0, 0, 0.05); + transition: right 0.3s ease-in-out; + + // 增加优先级 + &&--visible { + right: 0; + } + + &__header { + display: flex; + gap: 10px; + align-items: center; + justify-content: flex-end; + width: 100%; + height: 60px; + padding: 0 15px; + border-bottom: 1px solid #e8e8e8; + } + + &__iframe { + width: 100%; + height: calc(100% - 60px); + border: 0; + } +} diff --git a/react-ui/src/components/RobotFrame/index.tsx b/react-ui/src/components/RobotFrame/index.tsx new file mode 100644 index 00000000..49789aa7 --- /dev/null +++ b/react-ui/src/components/RobotFrame/index.tsx @@ -0,0 +1,30 @@ +import { CloseOutlined, ExpandOutlined } from '@ant-design/icons'; +import { Button } from 'antd'; +import classNames from 'classnames'; +import styles from './index.less'; + +type RobotFrameProps = { + onClose: () => void; + visible: boolean; +}; + +function RobotFrame({ onClose, visible }: RobotFrameProps) { + const url = 'http://172.20.32.181:30080/chat/l4S79c4rly0o1pn7'; + const openUrl = () => { + window.open(url, '_blank'); + }; + + return ( +
+
+ + +
+ +
+ ); +} + +export default RobotFrame; diff --git a/react-ui/src/hooks/draggable.ts b/react-ui/src/hooks/draggable.ts new file mode 100644 index 00000000..b093ea6f --- /dev/null +++ b/react-ui/src/hooks/draggable.ts @@ -0,0 +1,37 @@ +// 处理 react-draggable 组件拖动结束时,响应了点击事件的 +import { useState } from 'react'; + +export const useDraggable = (onClick: () => void) => { + const [isDragging, setIsDragging] = useState(false); + + const handleStart = () => { + setIsDragging(false); + }; + + const handleDrag = () => { + if (!isDragging) { + setIsDragging(true); + } + }; + + const handleStop = () => { + // 延迟设置 isDragging 为 false 是为了确保在点击事件触发之前它仍然为 true + setTimeout(() => setIsDragging(false), 0); + }; + + const handleClick = (e: React.MouseEvent) => { + if (isDragging) { + e.preventDefault(); + e.stopPropagation(); + } else { + onClick(); + } + }; + + return { + handleStart, + handleDrag, + handleStop, + handleClick, + }; +}; diff --git a/react-ui/src/pages/Workspace/index.less b/react-ui/src/pages/Workspace/index.less index f7f95a24..3c7bd42e 100644 --- a/react-ui/src/pages/Workspace/index.less +++ b/react-ui/src/pages/Workspace/index.less @@ -1,4 +1,5 @@ .workspace { + position: relative; height: 100%; padding: 20px 30px 10px; overflow-y: auto; @@ -43,4 +44,14 @@ min-width: 326px; height: 700px; } + + &__robot-img { + position: fixed; + right: 30px; + bottom: 20px; + width: 64px; + height: 64px; + background-color: white; + cursor: pointer; + } } diff --git a/react-ui/src/pages/Workspace/index.tsx b/react-ui/src/pages/Workspace/index.tsx index 55acd264..f5e6fe99 100644 --- a/react-ui/src/pages/Workspace/index.tsx +++ b/react-ui/src/pages/Workspace/index.tsx @@ -1,7 +1,10 @@ +import RobotFrame from '@/components/RobotFrame'; +import { useDraggable } from '@/hooks/draggable'; import { getWorkspaceOverviewReq } from '@/services/workspace'; import { ExperimentInstance } from '@/types'; import { to } from '@/utils/promise'; import { useEffect, useState } from 'react'; +import Draggable from 'react-draggable'; import AssetsManagement from './components/AssetsManagement'; import ExperimentChart, { type ExperimentStatistics } from './components/ExperimentChart'; import ExperitableTable from './components/ExperimentTable'; @@ -20,6 +23,10 @@ type OverviewData = { function Workspace() { const [overviewData, setOverviewData] = useState(); + const [robotFrameVisible, setRobotFrameVisible] = useState(false); + const { handleStart, handleStop, handleDrag, handleClick } = useDraggable(() => + setRobotFrameVisible((prev) => !prev), + ); const users: number[] = new Array(8).fill(0); useEffect(() => { getWorkspaceOverview(); @@ -64,6 +71,19 @@ function Workspace() { + + e.preventDefault()} + > + + + setRobotFrameVisible(false)} + > ); } From 76fd298723256edd05496f9260ba42ce35858c36 Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Fri, 19 Jul 2024 14:27:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E6=8E=A5=E5=85=A5=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react-ui/src/components/RobotFrame/index.tsx | 2 +- react-ui/src/pages/Experiment/components/LogGroup/index.tsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/react-ui/src/components/RobotFrame/index.tsx b/react-ui/src/components/RobotFrame/index.tsx index 49789aa7..7905265d 100644 --- a/react-ui/src/components/RobotFrame/index.tsx +++ b/react-ui/src/components/RobotFrame/index.tsx @@ -9,7 +9,7 @@ type RobotFrameProps = { }; function RobotFrame({ onClose, visible }: RobotFrameProps) { - const url = 'http://172.20.32.181:30080/chat/l4S79c4rly0o1pn7'; + const url = 'http://172.20.32.181:30080/chat/EruwZfxVgDkWdLYs'; const openUrl = () => { window.open(url, '_blank'); }; diff --git a/react-ui/src/pages/Experiment/components/LogGroup/index.tsx b/react-ui/src/pages/Experiment/components/LogGroup/index.tsx index a232b30f..b6d45ce0 100644 --- a/react-ui/src/pages/Experiment/components/LogGroup/index.tsx +++ b/react-ui/src/pages/Experiment/components/LogGroup/index.tsx @@ -134,7 +134,6 @@ function LogGroup({ // 建立 socket 连接 const setupSockect = () => { let { host } = location; - if (process.env.NODE_ENV === 'development') { host = '172.20.32.181:31213'; }