feat(navigation): 为数字人前台拆分独立页面路由

- 新增对话列表、聊天、角色详情、书架详情及个人资料独立路由
- 导航使用真实链接,补齐历史返回、登录深链与会话草稿恢复
- 搜索筛选由 URL 驱动,修复浏览器返回时丢失筛选的问题
- 补齐路由校验回归、页面加载与异常入口,并同步 README
This commit is contained in:
湛兮
2026-10-28 17:07:34 +08:00
parent caa54c9b34
commit 4132b80ee0
25 changed files with 801 additions and 192 deletions
+23 -13
View File
@@ -1,6 +1,8 @@
"use client";
/** 会话列表的水平滑动操作与删除确认;纵向滑动继续交给页面滚动。 */
import { useEffect, useId, useRef, useState, type PointerEvent } from "react";
import Link from "next/link";
import { chatPath } from "@/lib/digital-routes";
import { LoaderCircle, Trash2 } from "lucide-react";
import type { Card, Summary } from "@/lib/digital";
@@ -11,7 +13,6 @@ export function ConversationRow({
revealed,
disabled,
onReveal,
onOpen,
onDelete,
}: {
summary: Summary;
@@ -19,7 +20,6 @@ export function ConversationRow({
revealed: boolean;
disabled: boolean;
onReveal: (id: string | null) => void;
onOpen: () => void;
onDelete: () => void;
}) {
const [drag, setDrag] = useState<number | null>(null);
@@ -32,8 +32,16 @@ export function ConversationRow({
} | null>(null),
suppressClick = useRef(false);
const distance = 88;
function start(e: PointerEvent<HTMLButtonElement>) {
if (disabled || e.button !== 0) return;
function start(e: PointerEvent<HTMLAnchorElement>) {
if (
disabled ||
e.button !== 0 ||
e.metaKey ||
e.ctrlKey ||
e.shiftKey ||
e.altKey
)
return;
suppressClick.current = false;
gesture.current = {
x: e.clientX,
@@ -44,7 +52,7 @@ export function ConversationRow({
};
e.currentTarget.setPointerCapture(e.pointerId);
}
function move(e: PointerEvent<HTMLButtonElement>) {
function move(e: PointerEvent<HTMLAnchorElement>) {
const g = gesture.current;
if (!g) return;
const dx = e.clientX - g.x,
@@ -57,7 +65,7 @@ export function ConversationRow({
g.offset = Math.max(-distance, Math.min(0, g.base + dx));
setDrag(g.offset);
}
function finish(e: PointerEvent<HTMLButtonElement>, cancelled = false) {
function finish(e: PointerEvent<HTMLAnchorElement>, cancelled = false) {
const g = gesture.current;
if (!g) return;
gesture.current = null;
@@ -85,12 +93,13 @@ export function ConversationRow({
<Trash2 size={18} />
<span>删除</span>
</button>
<button
<Link
href={chatPath(summary.id)}
className={`dh-conversation-open ${drag !== null ? "is-dragging" : ""}`}
style={{
transform: `translateX(${drag ?? (revealed ? -distance : 0)}px)`,
}}
disabled={disabled}
aria-disabled={disabled}
onPointerDown={start}
onPointerMove={move}
onPointerUp={(e) => finish(e)}
@@ -102,15 +111,15 @@ export function ConversationRow({
}
}}
onClick={(e) => {
if (suppressClick.current && e.detail !== 0) {
if (disabled || (suppressClick.current && e.detail !== 0)) {
e.preventDefault();
suppressClick.current = false;
return;
}
if (revealed) {
e.preventDefault();
onReveal(null);
return;
}
onOpen();
}}
>
{/* 封面地址沿用服务端目录,不在小型服务器做图片转换。 */}
@@ -126,7 +135,7 @@ export function ConversationRow({
day: "numeric",
})}
</small>
</button>
</Link>
<button
className="dh-row-delete-desktop"
aria-label={`删除对话:${summary.title}`}
@@ -177,7 +186,8 @@ export function ConversationDeleteDialog({
</span>
<h2 id={id}>删除这段对话?</h2>
<p id={`${id}-description`}>
「{title}」将从你的对话列表中移除,你将无法继续查看。后台仍保留聊天记录。
「{title}
」将从你的对话列表中移除,你将无法继续查看。后台仍保留聊天记录。
</p>
{error && (
<p className="dh-delete-error" role="alert">