From 62998de6e522bc497e0538694bc7bdcc11819f7b Mon Sep 17 00:00:00 2001 From: allen2fuc Date: Mon, 6 Jul 2026 09:48:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20AI=20=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E5=88=A0=E9=99=A4=E5=9C=A8=20App=20=E5=86=85?= =?UTF-8?q?=E6=97=A0=E5=93=8D=E5=BA=94=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WebView 不支持 window.confirm,改用 AlertDialog 显示删除确认框。 Co-authored-by: Cursor --- client/src/pages/AIPage.tsx | 83 +++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/client/src/pages/AIPage.tsx b/client/src/pages/AIPage.tsx index 9e2fc01..14cfbbf 100644 --- a/client/src/pages/AIPage.tsx +++ b/client/src/pages/AIPage.tsx @@ -8,6 +8,16 @@ ============================================================ */ import BottomNav from "@/components/BottomNav"; import ConnectionPlaceholder from "@/components/ConnectionPlaceholder"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from "@/components/ui/alert-dialog"; import { useDevice } from "@/contexts/DeviceContext"; import { AI_SPLIT_RESTORE_PATH_KEY, @@ -211,6 +221,7 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {}) const deviceName = deviceState?.device ?? "Luxsin X9"; const aiText = useMemo(() => resolveAILocale(language), [language]); + const promptText = useMemo(() => resolveLocalePack(language).prompt, [language]); const restoreDesktopSplit = useCallback(() => { const path = readAndClearAiSplitRestorePath(); @@ -223,6 +234,7 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {}) const [input, setInput] = useState(""); const [sending, setSending] = useState(false); const [historyOpen, setHistoryOpen] = useState(false); + const [pendingDeleteId, setPendingDeleteId] = useState(null); const [chats, setChats] = useState([]); // 初次加载历史会话期间,避免先闪一下欢迎页再切到消息 const [initializing, setInitializing] = useState(true); @@ -382,27 +394,22 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {}) } }, [aiText, chatId, newChat]); - // ── 历史面板里删除某条会话 ── - const deleteChatById = useCallback( - async (id: string) => { - const ok = window.confirm(aiText.history.deleteConfirm); - if (!ok) return; - try { - await clearChat(id); - setChats((prev) => prev.filter((c) => c.id !== id)); - if (chatId === id) { - setChatId(null); - setMessages([]); - } - toast.success(aiText.history.deleted); - } catch (e: any) { - toast.error( - formatText(aiText.history.deleteFailed, { message: e?.message ?? e }), - ); + // ── 历史面板里删除某条会话(确认框用 AlertDialog,WebView 不支持 window.confirm) ── + const confirmDeleteChat = useCallback(async (id: string) => { + try { + await clearChat(id); + setChats((prev) => prev.filter((c) => c.id !== id)); + if (chatId === id) { + setChatId(null); + setMessages([]); } - }, - [aiText, chatId], - ); + toast.success(aiText.history.deleted); + } catch (e: any) { + toast.error( + formatText(aiText.history.deleteFailed, { message: e?.message ?? e }), + ); + } + }, [aiText, chatId]); // ── 发送提问 ── const send = useCallback( @@ -897,10 +904,41 @@ export default function AIPage({ variant = "page", onClose }: AIPageProps = {}) onClose={() => setHistoryOpen(false)} onSelect={(id) => loadChat(id)} onNew={newChat} - onDelete={deleteChatById} + onDelete={setPendingDeleteId} /> )} + { + if (!open) setPendingDeleteId(null); + }} + > + + + + {aiText.history.delete} + + + {aiText.history.deleteConfirm} + + + + + {promptText.cancel} + + { + if (pendingDeleteId) void confirmDeleteChat(pendingDeleteId); + }} + > + {promptText.delete} + + + + + {/* ── 对比对话框 ── */} {compareMsg && ( )}