import { useTranslation } from "react-i18next"; import { Box, Typography, Button, Stack, LinearProgress, alpha, useTheme, Link, keyframes, } from "@mui/material"; import { useNavigate } from "react-router-dom"; import { CloudUploadOutlined, StorageOutlined, UpdateOutlined, DnsOutlined, SpeedOutlined, EventOutlined, LaunchOutlined, } from "@mui/icons-material"; import dayjs from "dayjs"; import parseTraffic from "@/utils/parse-traffic"; import { useState } from "react"; import { openWebUrl, updateProfile } from "@/services/cmds"; import { useLockFn } from "ahooks"; import { Notice } from "@/components/base"; import { EnhancedCard } from "./enhanced-card"; // 定义旋转动画 const round = keyframes` from { transform: rotate(0deg); } to { transform: rotate(360deg); } `; // 辅助函数解析URL和过期时间 function parseUrl(url?: string) { if (!url) return "-"; if (url.startsWith("http")) return new URL(url).host; return "local"; } function parseExpire(expire?: number) { if (!expire) return "-"; return dayjs(expire * 1000).format("YYYY-MM-DD"); } // 使用类型定义,而不是导入 interface ProfileExtra { upload: number; download: number; total: number; expire: number; } export interface ProfileItem { uid: string; type?: "local" | "remote" | "merge" | "script"; name?: string; desc?: string; file?: string; url?: string; updated?: number; extra?: ProfileExtra; home?: string; option?: any; // 添加option以兼容原始类型 } export interface HomeProfileCardProps { current: ProfileItem | null | undefined; } export const HomeProfileCard = ({ current }: HomeProfileCardProps) => { const { t } = useTranslation(); const navigate = useNavigate(); const theme = useTheme(); // 更新当前订阅 const [updating, setUpdating] = useState(false); const onUpdateProfile = useLockFn(async () => { if (!current?.uid) return; setUpdating(true); try { await updateProfile(current.uid); Notice.success(t("Update subscription successfully")); } catch (err: any) { Notice.error(err?.message || err.toString()); } finally { setUpdating(false); } }); // 导航到订阅页面 const goToProfiles = () => { navigate("/profile"); }; return ( current.home && openWebUrl(current.home)} sx={{ display: "inline-flex", alignItems: "center", color: "inherit", textDecoration: "none", }} > {current.name} ) : ( current.name ) ) : ( t("Profiles") ) } icon={} iconColor="info" action={ current && ( ) } > {current ? ( // 已导入订阅,显示详情 {current.url && ( {t("From")}:{" "} {current.home ? ( current.home && openWebUrl(current.home)} sx={{ display: "inline-flex", alignItems: "center" }} > {parseUrl(current.url)} ) : ( {parseUrl(current.url)} )} )} {current.updated && ( {t("Update Time")}:{" "} {dayjs(current.updated * 1000).format("YYYY-MM-DD HH:mm")} )} {current.extra && ( <> {t("Used / Total")}:{" "} {parseTraffic( current.extra.upload + current.extra.download, )}{" "} / {parseTraffic(current.extra.total)} {current.extra.expire > 0 && ( {t("Expire Time")}:{" "} {parseExpire(current.extra.expire)} )} {Math.min( Math.round( ((current.extra.download + current.extra.upload) * 100) / (current.extra.total + 0.01), ) + 1, 100, )} % )} ) : ( // 未导入订阅,显示导入按钮 {t("Import")} {t("Profiles")} {t("Click to import subscription")} )} ); };