"use client"; import Link from "next/link"; import Image from "next/image"; interface HostLinkProps { host: { id: string; name: string; avatar: string; bio: string; link?: string }; /** 志愿者招募:无审核通过时显示「立即申请」+ 免费标识 */ ctaText?: string; showFreeBadge?: boolean; /** 卡片有 link 样式但不可点击跳转 */ noLink?: boolean; } /** 移动端优先尝试唤醒小红书 app,PC 新窗口打开。noLink 时仅展示,不跳转 */ export default function HostLink({ host, ctaText, showFreeBadge, noLink }: HostLinkProps) { const href = "link" in host ? host.link : `/host/${host.id}`; const isXiaohongshu = typeof href === "string" && (href.includes("xhslink.com") || href.includes("xiaohongshu.com")); const handleClick = (e: React.MouseEvent) => { if (noLink) { e.preventDefault(); return; } if (!isXiaohongshu || typeof href !== "string") return; const isMobile = /Android|iPhone|iPad|iPod|webOS|Mobile/i.test(navigator.userAgent); if (isMobile) { e.preventDefault(); // 移动端:同窗口打开,xhslink.com 会尝试唤起小红书 app,未安装则打开网页 window.location.assign(href); } }; if (typeof href !== "string") return null; const cardClassName = "flex gap-3 sm:gap-4 p-4 sm:p-5 rounded-xl sm:rounded-2xl bg-white dark:bg-stone-900/80 border border-stone-200/80 dark:border-stone-700/80 hover:border-amber-200 dark:hover:border-amber-900/50 hover:shadow-lg transition-all"; const cardContent = ( <>
{host.name}

{host.name}

{showFreeBadge && ( FREE )}

{host.bio}

{ctaText ?? "查看主页"} →
); if (noLink) { return (
{cardContent}
); } return ( {cardContent} ); }