From ca4e87bddf85d5259d4a63c9a90c4f9e10abf26a Mon Sep 17 00:00:00 2001 From: HouYunFei <1844025705@qq.com> Date: Sat, 23 May 2026 15:08:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(canvas):=20=E9=87=8D=E6=9E=84=E7=94=BB?= =?UTF-8?q?=E5=B8=83=E5=8A=A9=E6=89=8B=E9=9D=A2=E6=9D=BF=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 Segmented 组件并替换为自定义模式切换按钮 - 替换 ModelPicker 为 ComposerModelPill 组件 - 添加下拉菜单实现模型选择功能 - 优化 CSS 样式类和响应式布局 - 更新图标引入和工具栏组件结构 - 简化提示词库按钮样式配置 --- .../components/canvas-assistant-panel.tsx | 111 ++++++++------ .../components/canvas-prompt-library.tsx | 6 +- web/src/app/globals.css | 140 +++++++++++++++++- web/src/components/model-picker.tsx | 7 +- 4 files changed, 204 insertions(+), 60 deletions(-) diff --git a/web/src/app/(user)/canvas/components/canvas-assistant-panel.tsx b/web/src/app/(user)/canvas/components/canvas-assistant-panel.tsx index fcf62e8..7f7a6ae 100644 --- a/web/src/app/(user)/canvas/components/canvas-assistant-panel.tsx +++ b/web/src/app/(user)/canvas/components/canvas-assistant-panel.tsx @@ -1,12 +1,11 @@ "use client"; -import { useEffect, useMemo, useState, type ReactNode } from "react"; -import { ArrowUp, History, ImageIcon, LoaderCircle, MessageSquare, PanelRightClose, Plus, RotateCcw, Settings2, Sparkles, Trash2, X } from "lucide-react"; -import { Button, ConfigProvider, Modal, Segmented, Tooltip } from "antd"; +import { useEffect, useMemo, useState } from "react"; +import { ArrowUp, ChevronDown, Cpu, History, ImageIcon, LoaderCircle, MessageSquare, PanelRightClose, Plus, RotateCcw, Settings2, Sparkles, Trash2, X } from "lucide-react"; +import { Button, Dropdown, Modal, Tooltip } from "antd"; import { motion } from "motion/react"; import { ImageGenerationPending } from "@/components/image-generation-pending"; -import { ModelPicker } from "@/components/model-picker"; import { useConfigStore, useEffectiveConfig, type AiConfig } from "@/stores/use-config-store"; import { canvasThemes } from "@/lib/canvas-theme"; import { nanoid } from "nanoid"; @@ -417,41 +416,16 @@ function AssistantComposer({ placeholder={mode === "image" ? "描述你想生成或修改的图片" : "输入你想问的问题"} />
-
+
- - onModeChange(value as AssistantMode)} - options={[ - { - value: "ask", - label: ( - - - - ), - }, - { - value: "image", - label: ( - - - - ), - }, - ]} - /> - + {mode === "image" ? ( <> - onConfigChange("imageModel", model)} onMissingConfig={onMissingConfig} /> - document.body} onConfigChange={onConfigChange} onMissingConfig={onMissingConfig} /> + onConfigChange("imageModel", model)} onMissingConfig={onMissingConfig} /> + document.body} buttonClassName="canvas-composer-settings canvas-composer-icon !h-8 !min-w-8 !rounded-full !px-2" onConfigChange={onConfigChange} onMissingConfig={onMissingConfig} /> ) : ( - onConfigChange("textModel", model)} onMissingConfig={onMissingConfig} /> + onConfigChange("textModel", model)} onMissingConfig={onMissingConfig} /> )}
+ + ); +} + +function ModelMenuLabel({ model }: { model: string }) { + return ( + + + {model} + + ); +} + +function ModelIcon({ model }: { model: string }) { + const name = model.toLowerCase(); + const icon = name.includes("claude") || name.includes("anthropic") ? "/icons/claude.svg" : name.includes("gemini") || name.includes("google") ? "/icons/gemini.svg" : name.includes("gpt") || name.includes("openai") ? "/icons/openai.svg" : ""; + return icon ? : ; +} + +function AssistantModeSwitch({ mode, theme, onChange }: { mode: AssistantMode; theme: (typeof canvasThemes)[keyof typeof canvasThemes]; onChange: (mode: AssistantMode) => void }) { + return ( +
+ {[ + { value: "ask" as const, title: "对话", icon: }, + { value: "image" as const, title: "生图", icon: }, + ].map((item) => ( + + + + ))} +
); } diff --git a/web/src/app/(user)/canvas/components/canvas-prompt-library.tsx b/web/src/app/(user)/canvas/components/canvas-prompt-library.tsx index e2305e4..a29730d 100644 --- a/web/src/app/(user)/canvas/components/canvas-prompt-library.tsx +++ b/web/src/app/(user)/canvas/components/canvas-prompt-library.tsx @@ -16,9 +16,9 @@ export function CanvasPromptLibrary({ onSelect }: { onSelect: (prompt: string) = <>