diff --git a/src/components/Tags.tsx b/src/components/Tags.tsx new file mode 100644 index 0000000..5b027d2 --- /dev/null +++ b/src/components/Tags.tsx @@ -0,0 +1,43 @@ +import { useRequest } from "ahooks"; +import { Divider, Flex, Skeleton, Tag, Typography } from "antd"; +import { EType, type XCXTag } from "../types"; +import { useEffect } from "react"; + +interface Props { + uid?: string; +} + +const color: { + [EType.GREEN]: string; + [EType.RED]: string; + [EType.YELLOW]: string; +} = { + [EType.GREEN]: 'success', + [EType.RED]: 'error', + [EType.YELLOW]: 'warning', +}; + +export default function UserTags(props: Props) { + const fetchTags = useRequest(async () => (await fetch(`/api/user/${props.uid}/tags`)).json(), { + refreshDeps: [props.uid], + }); + if (!props.uid) return null; + return ( + <> + 评价标签 + + { fetchTags.loading ? ( + <> + + + + + ) : ( + fetchTags.data?.length + ? fetchTags.data?.map(e => ( + {e.ename}({e.count}) + )): (暂时没人评价))} + + + ); +} \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index ba656ad..9c49a74 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,6 @@ import { serve } from "bun"; import index from "./index.html"; -import { getAdvProfile, getMatchInfo, listEvent } from "./utils"; +import { getAdvProfile, getMatchInfo, getPlayerTags, listEvent } from "./utils"; const server = serve({ port: process.env.PORT || 3000, @@ -25,6 +25,13 @@ const server = serve({ const profile = await getAdvProfile(uid); return Response.json(profile); }, + }, + "/api/user/:uid/tags": { + async GET(req) { + const uid = req.params.uid; + const profile = await getPlayerTags(uid); + return Response.json(profile); + }, } }, diff --git a/src/page/ProfilePage.tsx b/src/page/ProfilePage.tsx index bcdfd23..c783457 100644 --- a/src/page/ProfilePage.tsx +++ b/src/page/ProfilePage.tsx @@ -6,6 +6,7 @@ import { HomeOutlined } from "@ant-design/icons"; import User from "../components/User"; import React from "react"; import { ChangeBackground } from "../components/ChangeBackground"; +import UserTags from "../components/Tags"; function Honor(props: { honors?: XCXProfile['honors'] }) { if (!props.honors?.length) return null; @@ -31,7 +32,14 @@ function Honor(props: { honors?: XCXProfile['honors'] }) { } function Raket(props: { profile?: XCXProfile | null }) { - const { qiupaitype, zhengshoutype, fanshoutype, qiupai, zhengshou, fanshou } = props.profile || {}; + const { + qiupaitype = '', + zhengshoutype = '', + fanshoutype = '', + qiupai = '', + zhengshou = '', + fanshou = '', + } = props.profile || {}; if ([qiupaitype, zhengshoutype, fanshoutype].every(e => !e)) { return null; } @@ -93,6 +101,7 @@ export default function ProfilePage() { {profile?.description} + diff --git a/src/types/index.ts b/src/types/index.ts index 9413d75..c79e2cd 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,5 @@ +export * from './profile'; +export * from './tag'; export interface IEventInfo { title: string; info: string[]; diff --git a/src/types/tag.ts b/src/types/tag.ts new file mode 100644 index 0000000..2af4055 --- /dev/null +++ b/src/types/tag.ts @@ -0,0 +1,12 @@ +export enum EType { + GREEN = "1", + RED = "-1", + YELLOW = "0", +} + +export interface XCXTag { + eid: string; + etype: EType; + ename: string; + count: string; +} \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index da281d1..f633f31 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,6 +5,7 @@ import fs from 'fs'; import path from 'path'; import { chunk } from 'lodash'; import type { XCXProfile } from "./types/profile"; +import type { XCXTag } from "./types/tag"; const BASE_URL = `https://kaiqiuwang.cc`; const XCX_BASE_URL = `${BASE_URL}/xcx/public/index.php`; @@ -145,4 +146,18 @@ export async function getAdvProfile(uid: string) { const data = await resp.json(); if (data.code !== 1) return null; return data.data as XCXProfile; +} + +export async function getPlayerTags(uid: string) { + // return JSON.parse(fs.readFileSync( + // path.resolve(__dirname, '..', '__test__', 'data', 'profile.json'), + // ).toString()).data; + if (!/^\d+$/.test(uid)) return null; + if (!uid) return null; + const resp = await fetch(`${XCX_BASE_URL}/api/User/get_tags?uid=${uid}&limitByCount=50&getNegative=true`, { + headers: xcxDefaultHeaders, + }); + const data = await resp.json(); + if (data.code !== 1) return null; + return (data.data as XCXTag[]).filter(e => Number(e.count) > 0); } \ No newline at end of file