455b9e04d8
新增 Button.tsx 支持 5 种变体(primary/secondary/danger/ghost/purple)、 3 种尺寸(sm/md/lg)、pill/rounded 形状及内置 loading 状态, 替换 8 个文件中 16 处重复的按钮样板代码。
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
"use client";
|
||
|
||
import { useEffect } from "react";
|
||
import { motion } from "framer-motion";
|
||
import { AlertTriangle, RotateCcw, Home } from "lucide-react";
|
||
import Button from "@/components/Button";
|
||
|
||
export default function Error({
|
||
error,
|
||
reset,
|
||
}: {
|
||
error: Error & { digest?: string };
|
||
reset: () => void;
|
||
}) {
|
||
useEffect(() => {
|
||
console.error("[ErrorBoundary]", error);
|
||
}, [error]);
|
||
|
||
return (
|
||
<div className="flex min-h-dvh flex-col items-center justify-center bg-background px-6">
|
||
<motion.div
|
||
className="flex flex-col items-center text-center"
|
||
initial={{ opacity: 0, y: 20 }}
|
||
animate={{ opacity: 1, y: 0 }}
|
||
>
|
||
<motion.div
|
||
className="relative flex h-20 w-20 items-center justify-center"
|
||
animate={{ y: [0, -4, 0] }}
|
||
transition={{ duration: 2.5, repeat: Infinity, ease: "easeInOut" }}
|
||
>
|
||
<div className="absolute inset-0 rounded-2xl bg-rose-500/15 blur-lg" />
|
||
<AlertTriangle size={36} className="relative text-rose-400/80" strokeWidth={1.5} />
|
||
</motion.div>
|
||
|
||
<h1 className="mt-6 text-xl font-bold text-heading">出了点问题</h1>
|
||
<p className="mt-2 max-w-xs text-sm text-muted">
|
||
页面遇到了意外错误,请重试或返回首页
|
||
</p>
|
||
|
||
<div className="mt-8 flex gap-3">
|
||
<Button onClick={reset} variant="danger" icon={<RotateCcw size={15} />}>
|
||
重试
|
||
</Button>
|
||
<Button onClick={() => window.location.href = "/"} variant="secondary" icon={<Home size={15} />}>
|
||
首页
|
||
</Button>
|
||
</div>
|
||
</motion.div>
|
||
</div>
|
||
);
|
||
}
|