Commit 2805ab54 authored by timel's avatar timel

feat: 默认卡图

parent c964f920
Pipeline #25698 canceled with stages
in 3 minutes and 42 seconds
import classNames from "classnames"; import classNames from "classnames";
import { CSSProperties, useMemo } from "react"; import { CSSProperties, useMemo, useEffect, useState } from "react";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { isSuperReleaseCard } from "@/superPreRelease"; import { isSuperReleaseCard } from "@/superPreRelease";
...@@ -21,33 +21,39 @@ export const YgoCard: React.FC<Props> = (props) => { ...@@ -21,33 +21,39 @@ export const YgoCard: React.FC<Props> = (props) => {
const { const {
className, className,
code = 0, code = 0,
// cardName,
isBack = false, isBack = false,
width, width,
style, style,
onClick, onClick,
onLoad, onLoad,
} = props; } = props;
return useMemo(
() => ( const defaultCardSrc = "https://img2.imgtp.com/2024/03/06/G6wTJRz9.png";
const [src, setSrc] = useState(defaultCardSrc);
useEffect(() => {
setSrc(defaultCardSrc); // 以后应该是一个获取默认卡面的方法
const img = new Image();
img.onload = () => {
setSrc(img.src); // 图片加载完成后更新src状态
};
// 直接设置图片路径,无需url()包裹
img.src = getCardImgUrl(code, isBack);
}, [code, isBack]); // useEffect的依赖数组中加入isBack
return (
<div <div
className={classNames(styles["ygo-card"], className)} className={classNames(styles["ygo-card"], className)}
style={ style={
{ {
width, width,
"--src": `url(${getCardImgUrl(code, isBack)})`, "--src": `url(${src})`,
...style, ...style,
} as any } as any
} }
onClick={onClick} onClick={onClick}
// 加载完成
onLoad={onLoad} onLoad={onLoad}
> ></div>
{/* 暂时不能这么写...但如果用onload的话来判断可能又很消耗性能,再看看吧 */}
{/* {cardName} */}
</div>
),
[code],
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment