From 7ad9c3c93f0cc103347ae2e2429e0122fb512e24 Mon Sep 17 00:00:00 2001 From: lrj <owen.stl@gmail.com> Date: 星期三, 01 十月 2025 21:26:12 +0800 Subject: [PATCH] feat: 修复员工管理功能并优化UI --- web/src/api/activity.js | 115 ++++++++++++++++++++------------------------------------- 1 files changed, 40 insertions(+), 75 deletions(-) diff --git a/web/src/api/activity.js b/web/src/api/activity.js index b704967..c46c220 100644 --- a/web/src/api/activity.js +++ b/web/src/api/activity.js @@ -1,6 +1,6 @@ // 姣旇禌绠$悊 API -const GRAPHQL_ENDPOINT = 'http://localhost:8080/api/graphql'; +import { API_CONFIG, graphqlRequest } from '@/config/api'; // GraphQL 鏌ヨ璇彞 const GET_ACTIVITIES_QUERY = ` @@ -61,10 +61,18 @@ playerMax state stateName + sortOrder ratingScheme { id name } + } + judges { + id + name + phone + description + stageIds } } } @@ -78,6 +86,8 @@ name state stateName + sortOrder + playerCount parent { id name @@ -111,95 +121,50 @@ // API 鍑芥暟 export const getActivities = async (page = 0, size = 10, name = '') => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: GET_ACTIVITIES_QUERY, - variables: { page, size, name } - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const result = await graphqlRequest(GET_ACTIVITIES_QUERY, { page, size, name }); + return result.data.activities; + } catch (error) { + throw new Error(error.message || '鑾峰彇姣旇禌鍒楄〃澶辫触'); } - return result.data.activities; }; export const getActivity = async (id) => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: GET_ACTIVITY_QUERY, - variables: { id } - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const result = await graphqlRequest(GET_ACTIVITY_QUERY, { id }); + return result.data.activity; + } catch (error) { + throw new Error(error.message || '鑾峰彇姣旇禌璇︽儏澶辫触'); } - return result.data.activity; }; export const getAllActivities = async () => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: GET_ALL_ACTIVITIES_QUERY - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const result = await graphqlRequest(GET_ALL_ACTIVITIES_QUERY); + + return result.data.allActivities; + } catch (error) { + console.error('=== getAllActivities API璋冪敤澶辫触 ==='); + console.error('閿欒璇︽儏:', error); + console.error('閿欒娑堟伅:', error.message); + throw new Error(error.message || '鑾峰彇鎵�鏈夋瘮璧涘け璐�'); } - return result.data.allActivities; }; export const saveActivity = async (activityData) => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: SAVE_ACTIVITY_MUTATION, - variables: { input: activityData } - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const data = await graphqlRequest(SAVE_ACTIVITY_MUTATION, { input: activityData }); + return data.saveActivity; + } catch (error) { + throw new Error(error.message || '淇濆瓨姣旇禌澶辫触'); } - return result.data.saveActivity; }; export const deleteActivity = async (id) => { - const response = await fetch(GRAPHQL_ENDPOINT, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - query: DELETE_ACTIVITY_MUTATION, - variables: { id } - }) - }); - - const result = await response.json(); - if (result.errors) { - throw new Error(result.errors[0].message); + try { + const data = await graphqlRequest(DELETE_ACTIVITY_MUTATION, { id }); + return data.deleteActivity; + } catch (error) { + throw new Error(error.message || '鍒犻櫎姣旇禌澶辫触'); } - return result.data.deleteActivity; }; \ No newline at end of file -- Gitblit v1.8.0