From 56222183d1a0fb775101c452ec04694a07323045 Mon Sep 17 00:00:00 2001 From: xiongxiao Date: Wed, 18 Mar 2026 00:03:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87=20URL=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BC=A0=E9=80=92=20filepath=20=E5=92=8C=20projectPath?= =?UTF-8?q?=EF=BC=9B=E8=B0=83=E6=95=B4=20ProjectPanel=20=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat-dev/components/OpencodeChat.tsx | 110 +++++++++++++++--- src/pages/chat-dev/store/index.ts | 35 +++++- .../code-graph/components/ProjectPanel.tsx | 4 +- 3 files changed, 128 insertions(+), 21 deletions(-) diff --git a/src/pages/chat-dev/components/OpencodeChat.tsx b/src/pages/chat-dev/components/OpencodeChat.tsx index d9b971d..69d1081 100644 --- a/src/pages/chat-dev/components/OpencodeChat.tsx +++ b/src/pages/chat-dev/components/OpencodeChat.tsx @@ -1,6 +1,6 @@ -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { useShallow } from 'zustand/react/shallow'; -import { FileIcon, FolderIcon, RefreshCwIcon, TrashIcon } from 'lucide-react'; +import { FileIcon, FolderIcon, RefreshCwIcon, TrashIcon, PencilIcon, CheckIcon, XIcon } from 'lucide-react'; import { useChatDevStore } from '../store'; import { useCodeGraphStore } from '@/pages/code-graph/store'; @@ -29,6 +29,36 @@ export const OpencodeChat = () => { url: s.url, }))); + // 编辑节点信息的状态 + const [isEditing, setIsEditing] = useState(false); + const [editFilepath, setEditFilepath] = useState(''); + const [editProjectPath, setEditProjectPath] = useState(''); + + const startEditing = () => { + setEditFilepath(projectInfo?.filepath || ''); + setEditProjectPath(projectInfo?.projectPath || ''); + setIsEditing(true); + }; + + const cancelEditing = () => { + setIsEditing(false); + setEditFilepath(''); + setEditProjectPath(''); + }; + + const saveEditing = () => { + setData({ + projectInfo: { + filepath: editFilepath, + projectPath: editProjectPath, + kind: projectInfo?.kind || 'file', + }, + }); + setIsEditing(false); + setEditFilepath(''); + setEditProjectPath(''); + }; + // 初始化后尝试从 sessionStorage 恢复 opencode session 并加载历史消息 useEffect(() => { if (!codeGraphStore.url) return; @@ -88,21 +118,69 @@ export const OpencodeChat = () => { {/* 内容区 */}
{/* 节点信息 */} - {relativePath && ( -
- - - {relativePath} - -
- )} - {projectInfo?.projectPath && !relativePath && ( -
- - - {projectInfo.projectPath} - + {isEditing ? ( +
+
+ + setEditProjectPath(e.target.value)} + /> +
+
+ + setEditFilepath(e.target.value)} + /> +
+
+ + +
+ ) : ( + (relativePath || projectInfo?.projectPath) && ( +
+ {relativePath ? ( + <> + + + {relativePath} + + + ) : ( + <> + + + {projectInfo?.projectPath} + + + )} + +
+ ) )} {/* 问题输入区 */} diff --git a/src/pages/chat-dev/store/index.ts b/src/pages/chat-dev/store/index.ts index 4a4199e..5079620 100644 --- a/src/pages/chat-dev/store/index.ts +++ b/src/pages/chat-dev/store/index.ts @@ -113,7 +113,6 @@ export const useChatDevStore = create()((set, get) => ({ initFromTimestamp: (timestamp: string) => { const key = SESSION_KEY_PREFIX + timestamp; - // 优先从 localStorage 读取(首次打开) const localRaw = localStorage.getItem(key); if (localRaw) { @@ -123,7 +122,22 @@ export const useChatDevStore = create()((set, get) => ({ sessionStorage.setItem(SESSION_KEY, localRaw); // 清除 localStorage localStorage.removeItem(key); - set({ question: data.question, engine: data.engine, projectInfo: data.projectInfo }); + + // filepath和projectPath可以通过URL参数传递,优先级高于存储的内容 + const urlParams = new URLSearchParams(window.location.search); + const urlFilepath = urlParams.get('filepath'); + const urlProjectPath = urlParams.get('projectPath'); + + if (urlFilepath || urlProjectPath) { + const projectInfo = { + ...data.projectInfo, + filepath: urlFilepath ? decodeURI(urlFilepath) : data.projectInfo?.filepath ?? '', + projectPath: urlProjectPath ? decodeURI(urlProjectPath) : data.projectInfo?.projectPath ?? '', + }; + set({ question: data.question, engine: data.engine, projectInfo }); + } else { + set({ question: data.question, engine: data.engine, projectInfo: data.projectInfo }); + } return; } catch { localStorage.removeItem(key); @@ -135,7 +149,22 @@ export const useChatDevStore = create()((set, get) => ({ if (sessionRaw) { try { const data: ChatDevData = JSON.parse(sessionRaw); - set({ question: data.question, engine: data.engine, projectInfo: data.projectInfo }); + + // filepath和projectPath可以通过URL参数传递,优先级高于存储的内容 + const urlParams = new URLSearchParams(window.location.search); + const urlFilepath = urlParams.get('filepath'); + const urlProjectPath = urlParams.get('projectPath'); + + if (urlFilepath || urlProjectPath) { + const projectInfo = { + ...data.projectInfo, + filepath: urlFilepath ? decodeURI(urlFilepath) : data.projectInfo?.filepath ?? '', + projectPath: urlProjectPath ? decodeURI(urlProjectPath) : data.projectInfo?.projectPath ?? '', + }; + set({ question: data.question, engine: data.engine, projectInfo }); + } else { + set({ question: data.question, engine: data.engine, projectInfo: data.projectInfo }); + } return; } catch { sessionStorage.removeItem(SESSION_KEY); diff --git a/src/pages/code-graph/components/ProjectPanel.tsx b/src/pages/code-graph/components/ProjectPanel.tsx index f46a1eb..230eb0e 100644 --- a/src/pages/code-graph/components/ProjectPanel.tsx +++ b/src/pages/code-graph/components/ProjectPanel.tsx @@ -18,7 +18,7 @@ export function ProjectPanel({ onStopProject, }: ProjectPanelProps) { const [isDragging, setIsDragging] = useState(false); - const [position, setPosition] = useState({ x: 20, y: 80 }); + const [position, setPosition] = useState({ x: 20, y: 100 }); const dragOffset = useRef({ x: 0, y: 0 }); const panelRef = useRef(null); @@ -132,7 +132,7 @@ export function ProjectPanel({
{/* 项目列表 */} -
+
{activeProjects.map((project) => { const projectName = project.name || project.path.split('/').pop() || project.path; const nodeInfoData = {