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";
<div const [src, setSrc] = useState(defaultCardSrc);
className={classNames(styles["ygo-card"], className)}
style={ useEffect(() => {
{ setSrc(defaultCardSrc); // 以后应该是一个获取默认卡面的方法
width, const img = new Image();
"--src": `url(${getCardImgUrl(code, isBack)})`, img.onload = () => {
...style, setSrc(img.src); // 图片加载完成后更新src状态
} as any };
} // 直接设置图片路径,无需url()包裹
onClick={onClick} img.src = getCardImgUrl(code, isBack);
// 加载完成 }, [code, isBack]); // useEffect的依赖数组中加入isBack
onLoad={onLoad}
> return (
{/* 暂时不能这么写...但如果用onload的话来判断可能又很消耗性能,再看看吧 */} <div
{/* {cardName} */} className={classNames(styles["ygo-card"], className)}
</div> style={
), {
[code], width,
"--src": `url(${src})`,
...style,
} as any
}
onClick={onClick}
onLoad={onLoad}
></div>
); );
}; };
......
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