= ({ src, alt, className = '', placeholder, isCircular = false }) => {
const [hasError, setHasError] = useState(false)
/**
* 处理图片加载失败
*/
const handleError = () => {
setHasError(true)
}
if (!src || hasError) {
return (
{placeholder || alt}
)
}
return
}
/**
* 代理图片 URL,绕过 B 站防盗链
*/
const proxyImageUrl = (url: string): string => {
return `https://images.weserv.nl/?url=${encodeURIComponent(url)}`
}
/**
* 装饰卡片组件
* 接收 JSON 数据并用 React 元素渲染
*/
export const DecorationCard: React.FC<{ data: DecorationCardData | undefined }> = ({ data }) => {
if (!data) return null
const gradientStyle =
data.colors.length > 0 ? `linear-gradient(135deg, ${data.colors.join(', ')} 0%, ${data.colors.join(', ')} 100%)` : undefined
return (
{gradientStyle && data.text && (
{data.text}
)}
)
}