From 93eb6b470773bc49ea6e1a9d4cbd914eb95d525b Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期二, 30 九月 2025 17:38:04 +0800
Subject: [PATCH] feat: 完善比赛晋级功能并清理测试文件

---
 web/src/api/player.js |  121 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 104 insertions(+), 17 deletions(-)

diff --git a/web/src/api/player.js b/web/src/api/player.js
index a1ada54..34cec08 100644
--- a/web/src/api/player.js
+++ b/web/src/api/player.js
@@ -1,31 +1,118 @@
-const GRAPHQL_ENDPOINT = '/api/graphql'
+import { API_CONFIG, graphqlRequest } from '@/config/api'
 
-async function graphqlRequest(query, variables = {}) {
-  const response = await fetch(GRAPHQL_ENDPOINT, {
-    method: 'POST',
-    headers: { 'Content-Type': 'application/json' },
-    body: JSON.stringify({ query, variables })
-  })
-  if (!response.ok) {
-    const text = await response.text()
-    throw new Error(`HTTP ${response.status}: ${text}`)
+// 浣跨敤缁熶竴鐨刧raphqlRequest鍑芥暟
+
+// GraphQL鏌ヨ璇彞
+const GET_PLAYERS_QUERY = `
+  query GetPlayers($page: Int!, $size: Int!, $name: String) {
+    players(page: $page, size: $size, name: $name) {
+      content {
+        id
+        name
+        phone
+        regionId
+        region {
+          id
+          name
+        }
+        createTime
+        updateTime
+      }
+      totalElements
+      page
+      size
+    }
   }
-  const result = await response.json()
-  if (result.errors) throw new Error(result.errors.map(e => e.message).join('\\n'))
-  return result.data
+`
+
+const GET_PLAYER_QUERY = `
+  query GetPlayer($id: ID!) {
+    player(id: $id) {
+      id
+      name
+      phone
+      regionId
+      region {
+        id
+        name
+      }
+      createTime
+      updateTime
+    }
+  }
+`
+
+const SAVE_PLAYER_MUTATION = `
+  mutation SavePlayer($input: PlayerInput!) {
+    savePlayer(input: $input) {
+      id
+      name
+      phone
+      regionId
+      region {
+        id
+        name
+      }
+      createTime
+      updateTime
+    }
+  }
+`
+
+const DELETE_PLAYER_MUTATION = `
+  mutation DeletePlayer($id: ID!) {
+    deletePlayer(id: $id)
+  }
+`
+
+// API鍑芥暟
+export const getPlayers = async (page = 0, size = 10, name = '') => {
+  try {
+    const data = await graphqlRequest(GET_PLAYERS_QUERY, { page, size, name })
+    return data.players
+  } catch (error) {
+    throw new Error(error.message || '鑾峰彇瀛﹀憳鍒楄〃澶辫触')
+  }
+}
+
+export const getPlayer = async (id) => {
+  try {
+    const data = await graphqlRequest(GET_PLAYER_QUERY, { id })
+    return data.player
+  } catch (error) {
+    throw new Error(error.message || '鑾峰彇瀛﹀憳璇︽儏澶辫触')
+  }
+}
+
+export const savePlayer = async (playerData) => {
+  try {
+    const data = await graphqlRequest(SAVE_PLAYER_MUTATION, { input: playerData })
+    return data.savePlayer
+  } catch (error) {
+    throw new Error(error.message || '淇濆瓨瀛﹀憳澶辫触')
+  }
+}
+
+export const deletePlayer = async (id) => {
+  try {
+    const data = await graphqlRequest(DELETE_PLAYER_MUTATION, { id })
+    return data.deletePlayer
+  } catch (error) {
+    throw new Error(error.message || '鍒犻櫎瀛﹀憳澶辫触')
+  }
 }
 
 const GET_APPLICATIONS = `
-  query GetApplications($name: String, $activityId: ID, $page: Int, $size: Int) {
-    activityPlayerApplications(name: $name, activityId: $activityId, page: $page, size: $size) {
+  query GetApplications($name: String, $activityId: ID, $state: Int, $page: Int, $size: Int) {
+    activityPlayerApplications(name: $name, activityId: $activityId, state: $state, page: $page, size: $size) {
       id playerName activityName phone applyTime state
     }
   }
 `
 
 export const PlayerApi = {
-  getApplications: async (name, activityId, page, size) => {
-    const data = await graphqlRequest(GET_APPLICATIONS, { name, activityId, page, size })
+  getApplications: async (name, activityId, state, page, size) => {
+    const data = await graphqlRequest(GET_APPLICATIONS, { name, activityId, state, page, size })
     return data.activityPlayerApplications || []
   }
 }
\ No newline at end of file

--
Gitblit v1.8.0