From 374ab1c606c3ee6b9fcf6be927de6e6d9c6d83ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=9B=E5=85=AE?= Date: Tue, 27 Oct 2026 12:11:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20H5=E9=A3=8E=E6=A0=BC=E4=B8=8E?= =?UTF-8?q?=E4=B8=96=E7=95=8C=E4=B9=A6=E4=BD=BF=E7=94=A8=E5=BA=95=E9=83=A8?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=8A=BD=E5=B1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - H5入口:设定页只显示当前风格和已选世界书,单选与多选均从底部抽屉完成 - 交互:独立草稿、确认回填、取消还原、恢复默认、清空选择和焦点返回 - 响应式:桌面保留展开式选择,主设定页和抽屉的提交按钮固定可见 - 验证:类型检查与构建通过,90项浏览器断言覆盖小屏、双主题、键盘和真实保存 --- src/components/digital-home.tsx | 460 +++++++++++++++++++++++--------- src/components/digital.css | 207 +++++++++++++- 2 files changed, 540 insertions(+), 127 deletions(-) diff --git a/src/components/digital-home.tsx b/src/components/digital-home.tsx index ad1fdd1..0c6362b 100644 --- a/src/components/digital-home.tsx +++ b/src/components/digital-home.tsx @@ -35,6 +35,7 @@ import { RefreshCw, Download, ChevronDown, + ChevronRight, } from "lucide-react"; import { digital, @@ -130,6 +131,14 @@ export function DigitalHome({ const [profileDraft, setProfileDraft] = useState( initial.profile, ); + const [selectionSheet, setSelectionSheet] = useState< + "style" | "books" | null + >(null); + const [choiceDraft, setChoiceDraft] = useState<{ + presetId?: string; + bookIds: string[]; + }>({ bookIds: [] }); + const selectionTrigger = useRef(null); const favoritePending = useRef(false); const [activeMessage, setActiveMessage] = useState(null), [showJump, setShowJump] = useState(false), @@ -258,13 +267,20 @@ export function DigitalHome({ ); const controls = () => Array.from( - dialog?.querySelectorAll( + ( + document.querySelector(".dh-selection-sheet") ?? dialog + )?.querySelectorAll( 'button:not([disabled]),input,textarea,select,[tabindex="0"]', ) ?? [], ); const frame = requestAnimationFrame(() => controls()[0]?.focus()); const onKey = (event: globalThis.KeyboardEvent) => { if (event.key === "Escape") { + event.preventDefault(); + if (document.querySelector(".dh-selection-sheet")) { + setSelectionSheet(null); + return; + } setDetail(null); setShowSettings(false); } @@ -288,6 +304,35 @@ export function DigitalHome({ previous?.focus(); }; }, [detail, showSettings]); + /** 抽屉聚焦当前选项并限制滚动;取消、确认及切回桌面后恢复入口焦点。 */ + useEffect(() => { + if (!selectionSheet) return; + const previous = selectionTrigger.current; + const media = window.matchMedia("(max-width: 600px)"); + const resize = () => { + if (!media.matches) setSelectionSheet(null); + }; + resize(); + media.addEventListener("change", resize); + const frame = requestAnimationFrame(() => { + const panel = document.querySelector(".dh-selection-sheet"); + ( + panel?.querySelector("input:checked") ?? + panel?.querySelector("input") ?? + panel?.querySelector("button") + )?.focus(); + }); + return () => { + cancelAnimationFrame(frame); + media.removeEventListener("change", resize); + if (previous?.isConnected && previous.getClientRects().length) + previous.focus(); + else + document + .querySelector(".dh-desktop-choices input:checked") + ?.focus(); + }; + }, [selectionSheet]); useEffect(() => { const id = boot?.decision.decisionId; if (!id || document.hidden) return; @@ -586,6 +631,26 @@ export function DigitalHome({ reportError(e); } } + /** 抽屉仅编辑临时值;确认后回填设定,取消不改动已有选择。 */ + function openSelection(kind: "style" | "books") { + if (!settings) return; + selectionTrigger.current = document.activeElement as HTMLElement; + setChoiceDraft({ + presetId: settings.presetId, + bookIds: [...settings.bookIds], + }); + setSelectionSheet(kind); + } + function confirmSelection() { + if (settings) + setSettings({ + ...settings, + ...(selectionSheet === "style" + ? { presetId: choiceDraft.presetId } + : { bookIds: choiceDraft.bookIds }), + }); + setSelectionSheet(null); + } async function saveSettings(event: FormEvent) { event.preventDefault(); if (!conversation || !settings) return; @@ -662,6 +727,97 @@ export function DigitalHome({ (tag === "全部" || c.tags.includes(tag)) && (!onlyFavorites || profile?.favorites.includes(c.id)), ); + const styleChoices = ( + value: string | undefined, + onChange: (value: string | undefined) => void, + inSheet = false, + ) => ( +
+ + 叙事风格 + +

为这段故事选一种氛围

+
+ {[ + { + id: "", + name: "角色默认风格", + description: "沿用角色原有的语气与叙事节奏。", + }, + ...presets, + ...(value && !presets.some((p) => p.id === value) + ? [ + { + id: value, + name: "当前会话风格", + description: + "此风格暂不在可选列表中,可以保留或选择其他风格。", + }, + ] + : []), + ].map((p) => ( + + ))} +
+
+ ); + const bookChoices = ( + value: string[], + onChange: (value: string[]) => void, + inSheet = false, + ) => ( +
+ + 加入世界书 + + {books.map((b) => ( + + ))} +
+ ); const modern = boot?.decision.variant === "B"; return (
)} {showSettings && settings && ( -
+
@@ -1406,136 +1564,188 @@ export function DigitalHome({
-