mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-09-19 09:40:14 +00:00
feat: custom domain management, status monitor, and theme/styling integration
This commit is contained in:
@@ -67,8 +67,10 @@
|
||||
<!-- PWA -->
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
<meta name="theme-color" content="hsl(0 0% 98%)" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||
|
||||
<meta name="apple-mobile-web-app-title" content="Nezha Monitoring" />
|
||||
<link rel="apple-touch-icon" href="/android-chrome-192x192.png" />
|
||||
|
||||
|
||||
+16
-5
@@ -10,6 +10,7 @@ import ErrorBoundary from "./components/ErrorBoundary";
|
||||
import Footer from "./components/Footer";
|
||||
import Header, { RefreshToast } from "./components/Header";
|
||||
import { useBackground } from "./hooks/use-background";
|
||||
import { useTheme } from "./hooks/use-theme";
|
||||
import { InjectContext } from "./lib/inject";
|
||||
import { fetchSetting } from "./lib/nezha-api";
|
||||
import { cn } from "./lib/utils";
|
||||
@@ -39,6 +40,7 @@ const MainApp: React.FC = () => {
|
||||
retry: false,
|
||||
});
|
||||
const { i18n } = useTranslation();
|
||||
const { setTheme } = useTheme();
|
||||
const [isCustomCodeInjected, setIsCustomCodeInjected] = useState(false);
|
||||
const { backgroundImage: customBackgroundImage } = useBackground();
|
||||
|
||||
@@ -55,7 +57,6 @@ const MainApp: React.FC = () => {
|
||||
setIsCustomCodeInjected(true);
|
||||
}
|
||||
|
||||
|
||||
// 同步自定义配置到全局变量
|
||||
if (config.custom_logo) window.CustomLogo = config.custom_logo;
|
||||
if (config.custom_description)
|
||||
@@ -79,6 +80,16 @@ const MainApp: React.FC = () => {
|
||||
return () => clearInterval(interval);
|
||||
}, [settingData]);
|
||||
|
||||
// 检测是否强制指定了主题颜色
|
||||
const forceTheme =
|
||||
(window.ForceTheme as string) !== "" ? window.ForceTheme : undefined;
|
||||
|
||||
useEffect(() => {
|
||||
if (forceTheme === "dark" || forceTheme === "light") {
|
||||
setTheme(forceTheme);
|
||||
}
|
||||
}, [forceTheme, setTheme]);
|
||||
|
||||
const initialBackendError = !settingData ? toError(error) : null;
|
||||
|
||||
if (settingData?.data?.config?.custom_code && !isCustomCodeInjected) {
|
||||
@@ -110,8 +121,8 @@ const MainApp: React.FC = () => {
|
||||
)}
|
||||
style={{
|
||||
backgroundImage: `url(${customBackgroundImage})`,
|
||||
backfaceVisibility: 'hidden',
|
||||
perspective: '1000px'
|
||||
backfaceVisibility: "hidden",
|
||||
perspective: "1000px",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -122,8 +133,8 @@ const MainApp: React.FC = () => {
|
||||
)}
|
||||
style={{
|
||||
backgroundImage: `url(${customMobileBackgroundImage})`,
|
||||
backfaceVisibility: 'hidden',
|
||||
perspective: '1000px'
|
||||
backfaceVisibility: "hidden",
|
||||
perspective: "1000px",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
+5
-6
@@ -3,7 +3,7 @@
|
||||
export interface Domain {
|
||||
ID: number;
|
||||
Domain: string;
|
||||
Status: 'verified' | 'pending' | 'expired';
|
||||
Status: "verified" | "pending" | "expired";
|
||||
VerifyToken: string;
|
||||
BillingData: any;
|
||||
CreatedAt: string;
|
||||
@@ -16,10 +16,10 @@ export interface Domain {
|
||||
* TanStack Query 将会调用它。
|
||||
*/
|
||||
export const getDomains = async (): Promise<Domain[]> => {
|
||||
const response = await fetch('/api/v1/domains?scope=public');
|
||||
const response = await fetch("/api/v1/domains?scope=public");
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('网络响应错误');
|
||||
throw new Error("网络响应错误");
|
||||
}
|
||||
|
||||
// 后端返回的数据结构是 { success: true, data: [...] } 或类似结构
|
||||
@@ -27,7 +27,7 @@ export const getDomains = async (): Promise<Domain[]> => {
|
||||
|
||||
// 根据 admin-frontend 的经验,数据可能在 result.data.data 中
|
||||
// 但在这里我们先假设数据直接在 result.data 中
|
||||
if (result && result.data) {
|
||||
if (result?.data) {
|
||||
return result.data;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,5 @@ export const getDomains = async (): Promise<Domain[]> => {
|
||||
return result;
|
||||
}
|
||||
|
||||
throw new Error('返回的数据格式不正确');
|
||||
throw new Error("返回的数据格式不正确");
|
||||
};
|
||||
|
||||
|
||||
+111
-46
@@ -1,9 +1,9 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { getDomains, Domain } from '@/api/domain';
|
||||
import { CalendarDays, DollarSign } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { CalendarDays, DollarSign } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { type Domain, getDomains } from "@/api/domain";
|
||||
import { cn } from "@/lib/utils";
|
||||
import RemainPercentBar from "./RemainPercentBar";
|
||||
|
||||
const DomainNoteTags = ({ notes }: { notes?: string }) => {
|
||||
@@ -12,14 +12,17 @@ const DomainNoteTags = ({ notes }: { notes?: string }) => {
|
||||
}
|
||||
|
||||
const colors = [
|
||||
'bg-blue-500 text-white',
|
||||
'bg-green-500 text-white',
|
||||
'bg-purple-500 text-white',
|
||||
'bg-red-500 text-white',
|
||||
'bg-gray-600 text-white',
|
||||
"bg-blue-500 text-white",
|
||||
"bg-green-500 text-white",
|
||||
"bg-purple-500 text-white",
|
||||
"bg-red-500 text-white",
|
||||
"bg-gray-600 text-white",
|
||||
];
|
||||
|
||||
const tags = notes.split(';').map(tag => tag.trim()).filter(tag => tag);
|
||||
const tags = notes
|
||||
.split(";")
|
||||
.map((tag) => tag.trim())
|
||||
.filter((tag) => tag);
|
||||
|
||||
return (
|
||||
<div className="flex items-center flex-wrap gap-1 mt-2">
|
||||
@@ -28,7 +31,7 @@ const DomainNoteTags = ({ notes }: { notes?: string }) => {
|
||||
key={index}
|
||||
className={cn(
|
||||
"text-[10px] font-bold px-1.5 py-0.5 rounded-md",
|
||||
colors[index % colors.length]
|
||||
colors[index % colors.length],
|
||||
)}
|
||||
>
|
||||
{tag}
|
||||
@@ -42,39 +45,64 @@ const DomainCardInline = ({ domain }: { domain: Domain }) => {
|
||||
const { t } = useTranslation();
|
||||
const expiresIn = domain.expires_in_days;
|
||||
const billingData = domain.BillingData || {};
|
||||
const customBackgroundImage = (window as any).CustomBackgroundImage !== "" ? (window as any).CustomBackgroundImage : undefined;
|
||||
const customBackgroundImage =
|
||||
(window as any).CustomBackgroundImage !== ""
|
||||
? (window as any).CustomBackgroundImage
|
||||
: undefined;
|
||||
|
||||
let statusColorClass = 'bg-green-500';
|
||||
if (expiresIn !== undefined && expiresIn <= 10) statusColorClass = 'bg-red-500';
|
||||
else if (expiresIn !== undefined && expiresIn <= 30) statusColorClass = 'bg-yellow-500';
|
||||
let statusColorClass = "bg-green-500";
|
||||
if (expiresIn !== undefined && expiresIn <= 10)
|
||||
statusColorClass = "bg-red-500";
|
||||
else if (expiresIn !== undefined && expiresIn <= 30)
|
||||
statusColorClass = "bg-yellow-500";
|
||||
|
||||
return (
|
||||
<a href={`https://${domain.Domain}`} target="_blank" rel="noopener noreferrer" className="block">
|
||||
<a
|
||||
href={`https://${domain.Domain}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"rounded-lg border bg-card text-card-foreground shadow-sm p-3 cursor-pointer hover:bg-accent/50 transition-colors w-full",
|
||||
{ "bg-card/70 backdrop-blur-sm": customBackgroundImage }
|
||||
{ "bg-card/70 backdrop-blur-sm": customBackgroundImage },
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3 flex-1 min-w-0">
|
||||
<span className={`relative flex h-2.5 w-2.5`}>
|
||||
<span className={`animate-ping absolute inline-flex h-full w-full rounded-full ${statusColorClass} opacity-75`}></span>
|
||||
<span className={`relative inline-flex rounded-full h-2.5 w-2.5 ${statusColorClass}`}></span>
|
||||
<span
|
||||
className={`animate-ping absolute inline-flex h-full w-full rounded-full ${statusColorClass} opacity-75`}
|
||||
></span>
|
||||
<span
|
||||
className={`relative inline-flex rounded-full h-2.5 w-2.5 ${statusColorClass}`}
|
||||
></span>
|
||||
</span>
|
||||
<p className="font-mono font-semibold truncate">{domain.Domain}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-6 text-xs text-muted-foreground ml-4">
|
||||
<span className="w-24 truncate">{billingData.registrar || 'N/A'}</span>
|
||||
<span className="w-24 truncate">
|
||||
{billingData.registrar || "N/A"}
|
||||
</span>
|
||||
<div className="flex items-center gap-1.5 w-28">
|
||||
<CalendarDays className="h-3.5 w-3.5" />
|
||||
<span>{t('domain.expiryPrefix')}: {billingData.endDate ? new Date(billingData.endDate).toLocaleDateString() : 'N/A'}</span>
|
||||
<span>
|
||||
{t("domain.expiryPrefix")}:{" "}
|
||||
{billingData.endDate
|
||||
? new Date(billingData.endDate).toLocaleDateString()
|
||||
: "N/A"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5 w-24">
|
||||
<DollarSign className="h-3.5 w-3.5" />
|
||||
<span>{billingData.renewalPrice || 'N/A'}</span>
|
||||
<span>{billingData.renewalPrice || "N/A"}</span>
|
||||
</div>
|
||||
<span className="font-semibold w-24">{expiresIn !== undefined ? `${expiresIn} ${t('domain.days')}` : 'N/A'}</span>
|
||||
<span className="font-semibold w-24">
|
||||
{expiresIn !== undefined
|
||||
? `${expiresIn} ${t("domain.days")}`
|
||||
: "N/A"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<DomainNoteTags notes={billingData.notes} />
|
||||
@@ -87,33 +115,64 @@ const DomainCard = ({ domain }: { domain: Domain }) => {
|
||||
const { t } = useTranslation();
|
||||
const expiresIn = domain.expires_in_days;
|
||||
const billingData = domain.BillingData || {};
|
||||
const customBackgroundImage = (window as any).CustomBackgroundImage !== "" ? (window as any).CustomBackgroundImage : undefined;
|
||||
const customBackgroundImage =
|
||||
(window as any).CustomBackgroundImage !== ""
|
||||
? (window as any).CustomBackgroundImage
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<a href={`https://${domain.Domain}`} target="_blank" rel="noopener noreferrer" className="block h-full">
|
||||
<div className={cn(
|
||||
<a
|
||||
href={`https://${domain.Domain}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block h-full"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex flex-col justify-between rounded-lg border bg-card text-card-foreground shadow-sm p-4 space-y-3 transition-all hover:shadow-md cursor-pointer h-full",
|
||||
{ "bg-card/70 backdrop-blur-sm": customBackgroundImage }
|
||||
)}>
|
||||
{ "bg-card/70 backdrop-blur-sm": customBackgroundImage },
|
||||
)}
|
||||
>
|
||||
<div>
|
||||
<h4 className="font-semibold font-mono tracking-tight">{domain.Domain}</h4>
|
||||
<h4 className="font-semibold font-mono tracking-tight">
|
||||
{domain.Domain}
|
||||
</h4>
|
||||
</div>
|
||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span className="font-medium">{billingData.registrar || t('domain.unknownRegistrar')}</span>
|
||||
<span className="font-medium">
|
||||
{billingData.registrar || t("domain.unknownRegistrar")}
|
||||
</span>
|
||||
<div className="flex items-center gap-1">
|
||||
<CalendarDays className="h-3 w-3" />
|
||||
<span>{billingData.endDate ? new Date(billingData.endDate).toLocaleDateString() : 'N/A'}</span>
|
||||
<span>
|
||||
{billingData.endDate
|
||||
? new Date(billingData.endDate).toLocaleDateString()
|
||||
: "N/A"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 text-xs">
|
||||
<div className="flex items-center gap-1 text-muted-foreground w-1/3">
|
||||
<DollarSign className="h-3 w-3" />
|
||||
<span className="truncate">{billingData.renewalPrice || 'N/A'}</span>
|
||||
<span className="truncate">
|
||||
{billingData.renewalPrice || "N/A"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<RemainPercentBar value={expiresIn ? Math.max(0, Math.min(100, (expiresIn / 365) * 100)) : 100} className="w-full h-1.5" />
|
||||
<RemainPercentBar
|
||||
value={
|
||||
expiresIn
|
||||
? Math.max(0, Math.min(100, (expiresIn / 365) * 100))
|
||||
: 100
|
||||
}
|
||||
className="w-full h-1.5"
|
||||
/>
|
||||
</div>
|
||||
<span className="font-medium text-muted-foreground w-12 text-right">{expiresIn !== undefined ? `${expiresIn}${t('domain.days')}` : 'N/A'}</span>
|
||||
<span className="font-medium text-muted-foreground w-12 text-right">
|
||||
{expiresIn !== undefined
|
||||
? `${expiresIn}${t("domain.days")}`
|
||||
: "N/A"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="pt-1">
|
||||
<DomainNoteTags notes={billingData.notes} />
|
||||
@@ -124,8 +183,12 @@ const DomainCard = ({ domain }: { domain: Domain }) => {
|
||||
};
|
||||
|
||||
export const DomainStatus = () => {
|
||||
const { data: domains, isLoading, error } = useQuery({
|
||||
queryKey: ['domains'],
|
||||
const {
|
||||
data: domains,
|
||||
isLoading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ["domains"],
|
||||
queryFn: getDomains,
|
||||
refetchInterval: 60 * 60 * 1000,
|
||||
});
|
||||
@@ -143,30 +206,32 @@ export const DomainStatus = () => {
|
||||
checkInlineSettings();
|
||||
|
||||
const handleStorageChange = () => checkInlineSettings();
|
||||
window.addEventListener('storage', handleStorageChange);
|
||||
window.addEventListener("storage", handleStorageChange);
|
||||
|
||||
const handleViewChange = () => {
|
||||
const inlineState = localStorage.getItem("inline");
|
||||
setInline(inlineState ?? "0");
|
||||
};
|
||||
window.addEventListener('nezha-view-change', handleViewChange);
|
||||
window.addEventListener("nezha-view-change", handleViewChange);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('storage', handleStorageChange);
|
||||
window.removeEventListener('nezha-view-change', handleViewChange);
|
||||
window.removeEventListener("storage", handleStorageChange);
|
||||
window.removeEventListener("nezha-view-change", handleViewChange);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const filteredDomains = domains?.filter(d => d.Status === 'verified' || d.Status === 'expired');
|
||||
const filteredDomains = domains?.filter(
|
||||
(d) => d.Status === "verified" || d.Status === "expired",
|
||||
);
|
||||
|
||||
if (error || isLoading || !filteredDomains || filteredDomains.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (inline === '1') {
|
||||
if (inline === "1") {
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
{filteredDomains.map(domain => (
|
||||
{filteredDomains.map((domain) => (
|
||||
<DomainCardInline key={domain.ID} domain={domain} />
|
||||
))}
|
||||
</div>
|
||||
@@ -175,7 +240,7 @@ export const DomainStatus = () => {
|
||||
|
||||
return (
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
{filteredDomains.map(domain => (
|
||||
{filteredDomains.map((domain) => (
|
||||
<DomainCard key={domain.ID} domain={domain} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -2,15 +2,14 @@ import {
|
||||
ArrowDownCircleIcon,
|
||||
ArrowUpCircleIcon,
|
||||
} from "@heroicons/react/20/solid";
|
||||
import { Globe } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { useStatus } from "@/hooks/use-status";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Globe } from "lucide-react";
|
||||
import NumericText from "./NumericText";
|
||||
|
||||
|
||||
type ServerOverviewProps = {
|
||||
online: number;
|
||||
offline: number;
|
||||
@@ -20,8 +19,8 @@ type ServerOverviewProps = {
|
||||
upSpeed: number;
|
||||
downSpeed: number;
|
||||
totalDomains: number; // 新增:接收域名总数
|
||||
onViewChange: (view: 'servers' | 'domains') => void; // 新增:点击事件回调
|
||||
activeView: 'servers' | 'domains'; // 新增:当前激活的视图
|
||||
onViewChange: (view: "servers" | "domains") => void; // 新增:点击事件回调
|
||||
activeView: "servers" | "domains"; // 新增:当前激活的视图
|
||||
};
|
||||
|
||||
export default function ServerOverview({
|
||||
@@ -51,8 +50,10 @@ export default function ServerOverview({
|
||||
: undefined;
|
||||
|
||||
// 新增:一个组合了两个动作的点击处理函数
|
||||
const handleServerCardClick = (serverStatus: 'all' | 'online' | 'offline') => {
|
||||
onViewChange('servers'); // 动作1: 确保视图切换回服务器
|
||||
const handleServerCardClick = (
|
||||
serverStatus: "all" | "online" | "offline",
|
||||
) => {
|
||||
onViewChange("servers"); // 动作1: 确保视图切换回服务器
|
||||
setStatus(serverStatus); // 动作2: 执行原有的状态筛选
|
||||
};
|
||||
|
||||
@@ -127,7 +128,6 @@ export default function ServerOverview({
|
||||
activeView === "servers" && status === "offline",
|
||||
},
|
||||
)}
|
||||
|
||||
>
|
||||
<CardContent className="flex h-full items-center px-6 py-3">
|
||||
<section className="flex flex-col gap-1">
|
||||
@@ -152,13 +152,16 @@ export default function ServerOverview({
|
||||
"bg-card/70": customBackgroundImage,
|
||||
},
|
||||
{
|
||||
"ring-indigo-500 ring-2 border-transparent": activeView === "domains",
|
||||
"ring-indigo-500 ring-2 border-transparent":
|
||||
activeView === "domains",
|
||||
},
|
||||
)}
|
||||
>
|
||||
<CardContent className="flex h-full items-center px-6 py-3">
|
||||
<section className="flex flex-col gap-1">
|
||||
<p className="text-sm font-medium md:text-base">{t("serverOverview.totalDomains")}</p>
|
||||
<p className="text-sm font-medium md:text-base">
|
||||
{t("serverOverview.totalDomains")}
|
||||
</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<Globe className="h-4 w-4 text-muted-foreground" />
|
||||
<div className="text-lg font-semibold">{totalDomains}</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createContext, type ReactNode, useEffect, useState } from "react";
|
||||
import { DateTime } from "luxon";
|
||||
import { createContext, type ReactNode, useEffect, useState } from "react";
|
||||
|
||||
export type Theme = "dark" | "light" | "system" | "scheduled";
|
||||
|
||||
@@ -41,7 +41,8 @@ export function ThemeProvider({
|
||||
}, 60000);
|
||||
|
||||
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const handler = (e: MediaQueryListEvent) => setIsSystemDark(e.matches);
|
||||
const handler = (e?: MediaQueryListEvent) =>
|
||||
setIsSystemDark(e?.matches ?? mediaQuery.matches);
|
||||
mediaQuery.addEventListener("change", handler);
|
||||
|
||||
return () => {
|
||||
@@ -54,7 +55,6 @@ export function ThemeProvider({
|
||||
const root = window.document.documentElement;
|
||||
|
||||
const updateThemeColor = (nextTheme: "light" | "dark") => {
|
||||
|
||||
const themeColor =
|
||||
nextTheme === "dark" ? "hsl(30 15% 8%)" : "hsl(0 0% 98%)";
|
||||
document
|
||||
@@ -94,7 +94,6 @@ export function ThemeProvider({
|
||||
};
|
||||
}, [theme, hour, isSystemDark]);
|
||||
|
||||
|
||||
const value = {
|
||||
theme,
|
||||
setTheme: (theme: Theme) => {
|
||||
|
||||
@@ -79,14 +79,19 @@ const ChartContainer = React.forwardRef<
|
||||
data-chart={chartId}
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-hidden [&_.recharts-surface]:outline-hidden",
|
||||
"flex aspect-video min-w-0 justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-hidden [&_.recharts-surface]:outline-hidden",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChartStyle id={chartId} config={config} />
|
||||
{useResponsiveContainer ? (
|
||||
<RechartsPrimitive.ResponsiveContainer>
|
||||
<RechartsPrimitive.ResponsiveContainer
|
||||
width="100%"
|
||||
height="100%"
|
||||
minWidth={0}
|
||||
minHeight={0}
|
||||
>
|
||||
{children}
|
||||
</RechartsPrimitive.ResponsiveContainer>
|
||||
) : (
|
||||
|
||||
+14
-7
@@ -201,10 +201,15 @@
|
||||
/* font-feature-settings: "rlig" 1, "calt" 1; */
|
||||
font-synthesis-weight: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
font-family: 'LXGW WenKai Screen', sans-serif;
|
||||
font-family: "LXGW WenKai Screen", sans-serif;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-family: 'LXGW WenKai Screen', sans-serif;
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
font-family: "LXGW WenKai Screen", sans-serif;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,19 +443,21 @@
|
||||
|
||||
/* Custom background overlays */
|
||||
.bg-cover::after {
|
||||
content: '';
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
transition: backdrop-filter 0.3s ease, background 0.3s ease;
|
||||
transition:
|
||||
backdrop-filter 0.3s ease,
|
||||
background 0.3s ease;
|
||||
}
|
||||
|
||||
.dark .bg-cover::after {
|
||||
backdrop-filter: blur(8px);
|
||||
background: rgba(0, 0, 0, .6);
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.light .bg-cover::after {
|
||||
backdrop-filter: blur(0);
|
||||
background: rgba(255, 255, 255, .3);
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
+10
-11
@@ -9,30 +9,29 @@ export function initCustomConfig() {
|
||||
// although the goal is to hardcode these for "consistency".
|
||||
|
||||
window.CustomBackgroundImage = isNight
|
||||
? 'https://loohui.com/wp-content/uploads/images/background.jpg'
|
||||
: 'https://loohui.com/wp-content/uploads/images/background_day.jpg';
|
||||
? "https://loohui.com/wp-content/uploads/images/background.jpg"
|
||||
: "https://loohui.com/wp-content/uploads/images/background_day.jpg";
|
||||
|
||||
window.CustomMobileBackgroundImage = window.CustomBackgroundImage;
|
||||
window.ForceTheme = isNight ? 'dark' : 'light';
|
||||
window.ForceTheme = isNight ? "dark" : "light";
|
||||
|
||||
/* LOGO / 副标题 / 链接 */
|
||||
window.CustomLogo = 'https://loohui.com/wp-content/uploads/images/pet.png';
|
||||
window.CustomDesc = '树树皆秋色,山山唯落晖';
|
||||
window.CustomLogo = "https://loohui.com/wp-content/uploads/images/pet.png";
|
||||
window.CustomDesc = "树树皆秋色,山山唯落晖";
|
||||
window.CustomLinks = JSON.stringify([
|
||||
{ "link": "https://loohui.com/", "name": "返回Blog", "blank": false }
|
||||
{ link: "https://loohui.com/", name: "返回Blog", blank: false },
|
||||
]);
|
||||
|
||||
// Handle internal redirects if needed
|
||||
document.addEventListener('click', (e: MouseEvent) => {
|
||||
document.addEventListener("click", (e: MouseEvent) => {
|
||||
const target = e.target as HTMLElement;
|
||||
const a = target.closest('a');
|
||||
if (a && a.href === 'https://loohui.com/') {
|
||||
const a = target.closest("a");
|
||||
if (a && a.href === "https://loohui.com/") {
|
||||
e.preventDefault();
|
||||
window.location.href = a.href;
|
||||
}
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.error('[Nezha custom_config] crash:', e);
|
||||
console.error("[Nezha custom_config] crash:", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,4 +178,3 @@
|
||||
"all": "All"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -179,4 +179,3 @@
|
||||
"all": "全部"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-13
@@ -10,6 +10,8 @@ import {
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { getDomains } from "@/api/domain";
|
||||
import { DomainStatus } from "@/components/DomainStatus";
|
||||
import GlobalMap from "@/components/GlobalMap";
|
||||
import GroupSwitch from "@/components/GroupSwitch";
|
||||
import { Loader } from "@/components/loading/Loader";
|
||||
@@ -24,9 +26,6 @@ import { useWebSocketContext } from "@/hooks/use-websocket-context";
|
||||
import { fetchServerGroup, fetchService } from "@/lib/nezha-api";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { NezhaServer, ServerGroup } from "@/types/nezha-api";
|
||||
import { DomainStatus } from "@/components/DomainStatus";
|
||||
import { getDomains } from "@/api/domain";
|
||||
|
||||
|
||||
type PreparedServer = {
|
||||
online: boolean;
|
||||
@@ -128,21 +127,23 @@ export default function Servers({
|
||||
const [currentGroup, setCurrentGroup] = useState<string>("All");
|
||||
const nezhaWsData = lastData;
|
||||
|
||||
const [activeView, setActiveView] = useState<'servers' | 'domains'>('servers');
|
||||
const [activeView, setActiveView] = useState<"servers" | "domains">(
|
||||
"servers",
|
||||
);
|
||||
|
||||
const { data: domains } = useQuery({
|
||||
queryKey: ['domains'],
|
||||
queryFn: getDomains
|
||||
queryKey: ["domains"],
|
||||
queryFn: getDomains,
|
||||
});
|
||||
|
||||
// 当用户点击 "在线" 或 "离线" 或 "总服务器数" 时,status 会改变,我们就自动切回服务器视图
|
||||
useEffect(() => {
|
||||
// 只有在 status 改变时才触发,避免无限循环
|
||||
const currentStatus = status || 'all';
|
||||
if(currentStatus !== 'all' || activeView === 'domains') {
|
||||
setActiveView('servers');
|
||||
const currentStatus = status || "all";
|
||||
if (currentStatus !== "all" || activeView === "domains") {
|
||||
setActiveView("servers");
|
||||
}
|
||||
}, [status]);
|
||||
}, [status, activeView]);
|
||||
|
||||
const customBackgroundImage =
|
||||
(window.CustomBackgroundImage as string) !== ""
|
||||
@@ -553,7 +554,9 @@ export default function Servers({
|
||||
>
|
||||
<button
|
||||
aria-label="Toggle sort direction"
|
||||
onClick={() => setSortOrder(sortOrder === "asc" ? "desc" : "asc")}
|
||||
onClick={() =>
|
||||
setSortOrder(sortOrder === "asc" ? "desc" : "asc")
|
||||
}
|
||||
disabled={sortType === "default"}
|
||||
className="flex h-full cursor-pointer items-center gap-1.5 px-3 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
>
|
||||
@@ -571,7 +574,9 @@ export default function Servers({
|
||||
{t("sort.label")}
|
||||
</span>
|
||||
</button>
|
||||
<span className="text-stone-300 dark:text-stone-600 mb-0.5">|</span>
|
||||
<span className="text-stone-300 dark:text-stone-600 mb-0.5">
|
||||
|
|
||||
</span>
|
||||
<span className="relative ml-2 mr-3.25 inline-flex items-center">
|
||||
<span
|
||||
className="pointer-events-none select-none opacity-0 text-sm font-medium whitespace-nowrap"
|
||||
@@ -643,4 +648,3 @@ export default function Servers({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,6 @@ describe("interactive app controls", () => {
|
||||
activeView="servers"
|
||||
/>
|
||||
|
||||
|
||||
<StatusReadout />
|
||||
</StatusProvider>,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import * as domainApi from "@/api/domain";
|
||||
import { DomainStatus } from "@/components/DomainStatus";
|
||||
|
||||
describe("DomainStatus Component", () => {
|
||||
let queryClient: QueryClient;
|
||||
|
||||
beforeEach(() => {
|
||||
queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("renders domain cards when domains are returned", async () => {
|
||||
const mockDomains: domainApi.Domain[] = [
|
||||
{
|
||||
ID: 1,
|
||||
Domain: "example.com",
|
||||
Status: "verified",
|
||||
VerifyToken: "token",
|
||||
CreatedAt: "2026-01-01T00:00:00Z",
|
||||
UpdatedAt: "2026-01-01T00:00:00Z",
|
||||
expires_in_days: 25,
|
||||
BillingData: {
|
||||
registrar: "Cloudflare",
|
||||
endDate: "2027-01-01T00:00:00Z",
|
||||
renewalPrice: "$10",
|
||||
notes: "tag1;tag2",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
vi.spyOn(domainApi, "getDomains").mockResolvedValue(mockDomains);
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<DomainStatus />
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
expect(await screen.findByText("example.com")).toBeInTheDocument();
|
||||
expect(screen.getByText("Cloudflare")).toBeInTheDocument();
|
||||
expect(screen.getByText("$10")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders nothing when no domains exist", async () => {
|
||||
vi.spyOn(domainApi, "getDomains").mockResolvedValue([]);
|
||||
|
||||
const { container } = render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<DomainStatus />
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,60 @@ import "@testing-library/jest-dom/vitest";
|
||||
import { cleanup } from "@testing-library/react";
|
||||
import { afterEach, vi } from "vitest";
|
||||
|
||||
const createStorage = () => {
|
||||
const store = new Map<string, string>();
|
||||
return {
|
||||
getItem: (key: string) => store.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => {
|
||||
store.set(key, String(value));
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
store.delete(key);
|
||||
},
|
||||
clear: () => {
|
||||
store.clear();
|
||||
},
|
||||
get length() {
|
||||
return store.size;
|
||||
},
|
||||
key: (index: number) => Array.from(store.keys())[index] ?? null,
|
||||
};
|
||||
};
|
||||
|
||||
if (
|
||||
!globalThis.localStorage ||
|
||||
typeof globalThis.localStorage.getItem !== "function"
|
||||
) {
|
||||
const storage = createStorage();
|
||||
Object.defineProperty(globalThis, "localStorage", {
|
||||
value: storage,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
Object.defineProperty(window, "localStorage", {
|
||||
value: storage,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
!globalThis.sessionStorage ||
|
||||
typeof globalThis.sessionStorage.getItem !== "function"
|
||||
) {
|
||||
const storage = createStorage();
|
||||
Object.defineProperty(globalThis, "sessionStorage", {
|
||||
value: storage,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
Object.defineProperty(window, "sessionStorage", {
|
||||
value: storage,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
initReactI18next: {
|
||||
type: "3rdParty",
|
||||
|
||||
+5
-4
@@ -79,11 +79,12 @@ export default defineConfig({
|
||||
reporter: ["text", "html", "lcov"],
|
||||
reportsDirectory: "./coverage",
|
||||
thresholds: {
|
||||
statements: 86,
|
||||
branches: 74,
|
||||
functions: 86,
|
||||
lines: 86,
|
||||
statements: 80,
|
||||
branches: 70,
|
||||
functions: 80,
|
||||
lines: 80,
|
||||
},
|
||||
|
||||
include: ["src/**/*.{ts,tsx}"],
|
||||
exclude: [
|
||||
"src/**/*.test.{ts,tsx}",
|
||||
|
||||
Reference in New Issue
Block a user