10b8379965
新增: - 交互式对话框生成器模块(路由、页面、样式、MorePage入口) - 电商模块取消生成功能(任务追踪/取消按钮/中止逻辑) - 视频服务图片上传支持 Blob/dataURL/远程URL 多种来源 优化: - 电商图片上传修复本地 blob 预览图缺少原始文件的问题 - 视频规划管线错误信息改进 - 生成流程中多处增加中止检查点
92 lines
2.4 KiB
TypeScript
92 lines
2.4 KiB
TypeScript
import { useEffect, useRef, useState, type ReactNode } from "react";
|
|
|
|
interface PageTransitionProps {
|
|
viewKey: string;
|
|
children: ReactNode;
|
|
}
|
|
|
|
const EXIT_DURATION_MS = 180;
|
|
|
|
const NAV_ORDER: string[] = [
|
|
"home",
|
|
"workbench",
|
|
"ecommerce",
|
|
"ecommerceTemplates",
|
|
"sizeTemplate",
|
|
"canvas",
|
|
"scriptTokens",
|
|
"tokenUsage",
|
|
"community",
|
|
"assets",
|
|
"more",
|
|
"imageWorkbench",
|
|
"resolutionUpscale",
|
|
"watermarkRemoval",
|
|
"subtitleRemoval",
|
|
"dialogGenerator",
|
|
"digitalHuman",
|
|
"avatarConsole",
|
|
"characterMix",
|
|
"agent",
|
|
"login",
|
|
"profile",
|
|
"report",
|
|
];
|
|
|
|
function getNavIndex(key: string): number {
|
|
return NAV_ORDER.indexOf(key);
|
|
}
|
|
|
|
export default function PageTransition({ viewKey, children }: PageTransitionProps) {
|
|
const [displayedChildren, setDisplayedChildren] = useState(children);
|
|
const [phase, setPhase] = useState<"idle" | "exit">("idle");
|
|
const [exitDirection, setExitDirection] = useState<"forward" | "backward" | "neutral">("neutral");
|
|
const prevKeyRef = useRef(viewKey);
|
|
const timerRef = useRef<ReturnType<typeof setTimeout>>();
|
|
|
|
useEffect(() => {
|
|
if (viewKey === prevKeyRef.current) {
|
|
setDisplayedChildren(children);
|
|
// Cancel any active exit animation — children updated but viewKey stable.
|
|
setPhase("idle");
|
|
return;
|
|
}
|
|
|
|
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
if (prefersReducedMotion) {
|
|
prevKeyRef.current = viewKey;
|
|
setDisplayedChildren(children);
|
|
setPhase("idle");
|
|
return;
|
|
}
|
|
|
|
const prevIndex = getNavIndex(prevKeyRef.current);
|
|
const nextIndex = getNavIndex(viewKey);
|
|
if (prevIndex < nextIndex) {
|
|
setExitDirection("forward");
|
|
} else if (prevIndex > nextIndex) {
|
|
setExitDirection("backward");
|
|
} else {
|
|
setExitDirection("neutral");
|
|
}
|
|
prevKeyRef.current = viewKey;
|
|
|
|
setPhase("exit");
|
|
timerRef.current = setTimeout(() => {
|
|
setDisplayedChildren(children);
|
|
setPhase("idle");
|
|
}, EXIT_DURATION_MS);
|
|
return () => clearTimeout(timerRef.current);
|
|
}, [viewKey, children]);
|
|
|
|
const dirClass = exitDirection === "forward" ? " is-forward" : exitDirection === "backward" ? " is-backward" : "";
|
|
|
|
if (!displayedChildren) return null;
|
|
|
|
return (
|
|
<div className={phase === "exit" ? `page-transition-wrap page-motion--exit${dirClass}` : "page-transition-wrap"}>
|
|
{displayedChildren}
|
|
</div>
|
|
);
|
|
}
|