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/config/api.ts | 49 +++++++++++++++++++++++++++++++------------------ 1 files changed, 31 insertions(+), 18 deletions(-) diff --git a/web/src/config/api.ts b/web/src/config/api.ts index 485abb2..c1430be 100644 --- a/web/src/config/api.ts +++ b/web/src/config/api.ts @@ -20,33 +20,46 @@ // 鑾峰彇JWT token const { getToken } = await import('@/utils/auth'); const token = getToken(); + + // 鏋勫缓璇锋眰澶� const headers: Record<string, string> = { 'Content-Type': 'application/json', }; + if (token) { headers['Authorization'] = `Bearer ${token}`; } - const response = await fetch(API_CONFIG.GRAPHQL_ENDPOINT, { - method: 'POST', - headers: headers, - body: JSON.stringify({ - query, - variables, - }), - }) + // 鏋勫缓璇锋眰浣� + const requestBody = JSON.stringify({ + query, + variables, + }); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`) + try { + // 鍙戦�佽姹� + const response = await fetch(API_CONFIG.GRAPHQL_ENDPOINT, { + method: 'POST', + headers, + body: requestBody, + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const result = await response.json(); + + if (result.errors) { + throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`); + } + + return result; + } catch (error) { + console.error('=== GraphQL璇锋眰澶辫触 ==='); + console.error('閿欒璇︽儏:', error); + throw error; } - - const result = await response.json() - - if (result.errors) { - throw new Error(result.errors[0].message) - } - - return result.data } // 閫氱敤API璇锋眰宸ュ叿鍑芥暟 -- Gitblit v1.8.0