Jelajahi Sumber

feat: 修改

year 1 bulan lalu
induk
melakukan
f6a7844b25

+ 1 - 1
src/api/home.ts

@@ -375,7 +375,7 @@ export const setFavorite = (data: { game_id: number }) => {
     });
 };
 //取消收藏游戏
-export const cancelFavorite = (data: { game_id: number }) => {
+export const toggleFavorite = (data: { game_id: number }) => {
     return server.post({
         url: "/v1/api/front/game_favorite",
         data,

+ 1 - 1
src/app/[locale]/(TabBar)/gameList/[[...gameListFlag]]/page.tsx

@@ -67,7 +67,7 @@ const GameListFlag: FC<Props> = (props) => {
             <main className={"main-header pb-[.8rem]"}>
                 <Box>
                     <GroupCard data={target.games} row={1} />
-                    <InfiniteScroll loadMore={loadMore} hasMore={!target.page.is_end} />
+                    <InfiniteScroll loadMore={loadMore} hasMore={!target?.page?.is_end!} />
                 </Box>
             </main>
         </>

+ 13 - 8
src/components/Card/Card.tsx

@@ -1,5 +1,5 @@
 "use client";
-import { cancelFavorite, Category, GameListRep, GameRequest, setFavorite } from "@/api/home";
+import { Category, GameListRep, GameRequest, toggleFavorite } from "@/api/home";
 import { userInfoApi } from "@/api/login";
 import Box from "@/components/Box";
 import useGame from "@/hooks/useGame";
@@ -137,16 +137,15 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
 
     const doFavorite = async (evt: React.MouseEvent) => {
         evt.stopPropagation();
+        if (!getToken) {
+            router.push("/login");
+        }
         if (!item?.id) return;
         const params = {
             game_id: item?.id,
         };
         let res = null;
-        if (isFavorite) {
-            res = await cancelFavorite(params);
-        } else {
-            res = await setFavorite(params);
-        }
+        res = await toggleFavorite(params);
         if (res.code === 200) {
             setIsFavorite(!isFavorite);
             Toast.show({
@@ -173,8 +172,14 @@ const Card: FC<PropsWithChildren<CardProps>> = (props) => {
                     />
                     {props.isShowOnline && <div className={styles.cardOnline}>2323 On-Line</div>}
                     {props.isShowFavorite && (
-                        <div className={styles.favorite} onClick={doFavorite}>
-                            <i className="iconfont icon-ertong"></i>
+                        <div
+                            className={clsx(styles.favorite, { [styles.active]: isFavorite })}
+                            onClick={doFavorite}
+                        >
+                            {isFavorite && (
+                                <i className="iconfont icon-ertong21 text-[#f6cf1e]"></i>
+                            )}
+                            {!isFavorite && <i className="iconfont icon-ertong"></i>}
                         </div>
                     )}
                 </div>