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/region.js |  255 +++++++++++++++++++++++++++-----------------------
 1 files changed, 138 insertions(+), 117 deletions(-)

diff --git a/web/src/api/region.js b/web/src/api/region.js
index e61e32d..87cbcdf 100644
--- a/web/src/api/region.js
+++ b/web/src/api/region.js
@@ -1,138 +1,159 @@
-const GRAPHQL_ENDPOINT = '/api/graphql'
+import { API_CONFIG, graphqlRequest } from '@/config/api'
 
-// GraphQL璇锋眰鍑芥暟
-async function graphqlRequest(query, variables = {}) {
-  const response = await fetch(GRAPHQL_ENDPOINT, {
-    method: 'POST',
-    headers: {
-      'Content-Type': 'application/json',
-    },
-    body: JSON.stringify({
-      query,
-      variables,
-    }),
-  })
+// GraphQL璇锋眰鍑芥暟 - 浣跨敤缁熶竴鐨刧raphqlRequest
 
-  if (!response.ok) {
-    const errorText = await response.text();
-    throw new Error(`HTTP error! status: ${response.status}, body: ${errorText}`)
-  }
-
-  const result = await response.json()
+// 鑾峰彇鎵�鏈夊湴鍖�
+export const getRegions = async () => {
+  const query = `
+    query GetRegions {
+      regions {
+        id
+        name
+        description
+        createTime
+        updateTime
+      }
+    }
+  `
   
-  if (result.errors) {
-    throw new Error(result.errors.map(e => e.message).join('\n'))
+  try {
+    const data = await graphqlRequest(query)
+    return data.regions || []
+  } catch (error) {
+    throw new Error(error.message || '鑾峰彇鍦板尯鍒楄〃澶辫触')
   }
-
-  return result.data
 }
 
-// --- GraphQL Query Strings ---
-
-const GET_REGIONS = `
-  query GetRegions($name: String, $state: Int, $page: Int!, $size: Int!) {
-    regions(name: $name, state: $state, page: $page, size: $size) {
-      content { id name pid code level leafFlag fullPath state createTime createUserId updateTime updateUserId version }
-      totalElements totalPages currentPage pageSize
+// 鏍规嵁ID鑾峰彇鍦板尯
+export const getRegion = async (id) => {
+  const query = `
+    query GetRegion($id: ID!) {
+      region(id: $id) {
+        id
+        name
+        description
+        createTime
+        updateTime
+      }
     }
+  `
+  
+  try {
+    const data = await graphqlRequest(query, { id })
+    return data.region
+  } catch (error) {
+    throw new Error(error.message || '鑾峰彇鍦板尯璇︽儏澶辫触')
   }
-`
+}
 
-const GET_ALL_REGIONS = `
-  query GetAllRegions {
-    allRegions { id name pid code level leafFlag fullPath state createTime }
+// 淇濆瓨鍦板尯锛堟柊澧炴垨鏇存柊锛�
+export const saveRegion = async (regionData) => {
+  const mutation = `
+    mutation SaveRegion($input: RegionInput!) {
+      saveRegion(input: $input) {
+        id
+        name
+        description
+        createTime
+        updateTime
+      }
+    }
+  `
+  
+  try {
+    const data = await graphqlRequest(mutation, { input: regionData })
+    return data.saveRegion
+  } catch (error) {
+    throw new Error(error.message || '淇濆瓨鍦板尯澶辫触')
   }
-`
+}
 
-const GET_REGION = `
-  query GetRegion($id: ID!) {
-    region(id: $id) { id name pid code level leafFlag fullPath state createTime createUserId updateTime updateUserId version }
+// 鍒犻櫎鍦板尯
+export const deleteRegion = async (id) => {
+  const mutation = `
+    mutation DeleteRegion($id: ID!) {
+      deleteRegion(id: $id)
+    }
+  `
+  
+  try {
+    const data = await graphqlRequest(mutation, { id })
+    return data.deleteRegion
+  } catch (error) {
+    throw new Error(error.message || '鍒犻櫎鍦板尯澶辫触')
   }
-`
+}
 
-const GET_PROVINCES = `
-  query GetProvinces {
-    provinces { id name pid code level state }
+// 鑾峰彇鎵�鏈夌渷浠�
+export const getProvinces = async () => {
+  const query = `
+    query GetProvinces {
+      provinces {
+        id
+        name
+        pid
+        level
+      }
+    }
+  `
+  
+  try {
+    const data = await graphqlRequest(query)
+    return data.provinces || []
+  } catch (error) {
+    throw new Error(error.message || '鑾峰彇鐪佷唤鍒楄〃澶辫触')
   }
-`
+}
 
-const GET_CITIES = `
-  query GetCities($provinceId: ID!) {
-    cities(provinceId: $provinceId) { id name pid code level state }
+// 鏍规嵁鐪佷唤ID鑾峰彇鍩庡競
+export const getCities = async (provinceId) => {
+  const query = `
+    query GetCities($provinceId: ID!) {
+      cities(provinceId: $provinceId) {
+        id
+        name
+        pid
+        level
+      }
+    }
+  `
+  
+  try {
+    const data = await graphqlRequest(query, { provinceId })
+    return data.cities || []
+  } catch (error) {
+    throw new Error(error.message || '鑾峰彇鍩庡競鍒楄〃澶辫触')
   }
-`
+}
 
-const GET_DISTRICTS = `
-  query GetDistricts($cityId: ID!) {
-    districts(cityId: $cityId) { id name pid code level state }
+// 鏍规嵁鍩庡競ID鑾峰彇鍖哄幙
+export const getDistricts = async (cityId) => {
+  const query = `
+    query GetDistricts($cityId: ID!) {
+      districts(cityId: $cityId) {
+        id
+        name
+        pid
+        level
+      }
+    }
+  `
+  
+  try {
+    const data = await graphqlRequest(query, { cityId })
+    return data.districts || []
+  } catch (error) {
+    throw new Error(error.message || '鑾峰彇鍖哄幙鍒楄〃澶辫触')
   }
-`
+}
 
-const GET_REGION_CHILDREN = `
-  query GetRegionChildren($parentId: ID!) {
-    regionChildren(parentId: $parentId) { id name pid code level leafFlag state }
-  }
-`
-
-const SAVE_REGION = `
-  mutation SaveRegion($input: RegionInput!) {
-    saveRegion(input: $input) { id name pid code level leafFlag fullPath state createTime updateTime version }
-  }
-`
-
-const DELETE_REGION = `
-  mutation DeleteRegion($id: ID!) {
-    deleteRegion(id: $id)
-  }
-`
-
-const TOGGLE_REGION_STATE = `
-  mutation ToggleRegionState($id: ID!) {
-    toggleRegionState(id: $id) { id name state updateTime }
-  }
-`
-
-// --- API Functions ---
-
+// RegionApi 瀵硅薄锛屽寘鍚墍鏈夊尯鍩熺浉鍏崇殑API鏂规硶
 export const RegionApi = {
-  getRegions: async (name, state, page, size) => {
-    const data = await graphqlRequest(GET_REGIONS, { name, state, page, size });
-    return data.regions;
-  },
-  getAllRegions: async () => {
-    const data = await graphqlRequest(GET_ALL_REGIONS);
-    return data.allRegions;
-  },
-  getRegion: async (id) => {
-    const data = await graphqlRequest(GET_REGION, { id });
-    return data.region;
-  },
-  getProvinces: async () => {
-    const data = await graphqlRequest(GET_PROVINCES);
-    return data.provinces || [];
-  },
-  getCities: async (provinceId) => {
-    const data = await graphqlRequest(GET_CITIES, { provinceId });
-    return data.cities || [];
-  },
-  getDistricts: async (cityId) => {
-    const data = await graphqlRequest(GET_DISTRICTS, { cityId });
-    return data.districts || [];
-  },
-  getChildren: async (parentId) => {
-    const data = await graphqlRequest(GET_REGION_CHILDREN, { parentId });
-    return data.regionChildren;
-  },
-  saveRegion: async (input) => {
-    const data = await graphqlRequest(SAVE_REGION, { input });
-    return data.saveRegion;
-  },
-  deleteRegion: async (id) => {
-    const data = await graphqlRequest(DELETE_REGION, { id });
-    return data.deleteRegion;
-  },
-  toggleRegionState: async (id) => {
-    const data = await graphqlRequest(TOGGLE_REGION_STATE, { id });
-    return data.toggleRegionState;
-  }
+  getRegions,
+  getRegion,
+  saveRegion,
+  deleteRegion,
+  getProvinces,
+  getCities,
+  getDistricts
 }
\ No newline at end of file

--
Gitblit v1.8.0