From 375c18a6d2713ff19b22093eec57315992d8333f Mon Sep 17 00:00:00 2001
From: Codex Assistant <codex@example.com>
Date: 星期四, 06 十一月 2025 13:33:52 +0800
Subject: [PATCH] 增加评审下载
---
web/src/api/employee.ts | 100 +++++++++----------------------------------------
1 files changed, 19 insertions(+), 81 deletions(-)
diff --git a/web/src/api/employee.ts b/web/src/api/employee.ts
index dd55bc7..6cb318e 100644
--- a/web/src/api/employee.ts
+++ b/web/src/api/employee.ts
@@ -1,5 +1,7 @@
// 鍛樺伐绠$悊API
+import { API_CONFIG, graphqlRequest } from '@/config/api'
+
// 鍛樺伐鐩稿叧鐨� GraphQL 鏌ヨ鍜屽彉鏇�
export const EMPLOYEE_QUERIES = {
// 鑾峰彇鎵�鏈夊憳宸�
@@ -17,7 +19,7 @@
}
`,
- // 鏍规嵁濮撳悕鎼滅储鍛樺伐
+ // 鎼滅储鍛樺伐
SEARCH_EMPLOYEES: `
query SearchEmployees($name: String) {
employeesByName(name: $name) {
@@ -94,92 +96,41 @@
// API 鍑芥暟
export const employeeApi = {
- // 鑾峰彇鎵�鏈夊憳宸�
+ // 鑾峰彇鍛樺伐鍒楄〃
async getEmployees(): Promise<Employee[]> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: EMPLOYEE_QUERIES.GET_EMPLOYEES
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.employees || []
+ const result = await graphqlRequest(EMPLOYEE_QUERIES.GET_EMPLOYEES)
+ return result?.data?.employees || []
} catch (error: any) {
throw new Error(error.message || '鑾峰彇鍛樺伐鍒楄〃澶辫触')
}
},
- // 鏍规嵁鍚嶇О鎼滅储鍛樺伐
- async searchEmployees(name?: string): Promise<Employee[]> {
+ // 鎼滅储鍛樺伐
+ async searchEmployees(name: string): Promise<Employee[]> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: EMPLOYEE_QUERIES.SEARCH_EMPLOYEES,
- variables: { name }
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.employeesByName || []
+ const result = await graphqlRequest(EMPLOYEE_QUERIES.SEARCH_EMPLOYEES, { name })
+ return result?.data?.employeesByName || []
} catch (error: any) {
throw new Error(error.message || '鎼滅储鍛樺伐澶辫触')
}
},
- // 鑾峰彇鍛樺伐璇︽儏
+ // 鏍规嵁ID鑾峰彇鍛樺伐璇︽儏
async getEmployee(id: string): Promise<Employee | null> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: EMPLOYEE_QUERIES.GET_EMPLOYEE,
- variables: { id }
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.employee || null
+ const result = await graphqlRequest(EMPLOYEE_QUERIES.GET_EMPLOYEE, { id })
+ return result?.data?.employee || null
} catch (error: any) {
throw new Error(error.message || '鑾峰彇鍛樺伐璇︽儏澶辫触')
}
},
- // 淇濆瓨鍛樺伐
- async saveEmployee(input: EmployeeInput): Promise<Employee> {
+ // 淇濆瓨鍛樺伐锛堟柊澧炴垨鏇存柊锛�
+ async saveEmployee(employee: EmployeeInput): Promise<Employee> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: EMPLOYEE_MUTATIONS.SAVE_EMPLOYEE,
- variables: { input }
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.saveEmployee
+ const result = await graphqlRequest(EMPLOYEE_MUTATIONS.SAVE_EMPLOYEE, { input: employee })
+ return result?.data?.saveEmployee
} catch (error: any) {
throw new Error(error.message || '淇濆瓨鍛樺伐澶辫触')
}
@@ -188,21 +139,8 @@
// 鍒犻櫎鍛樺伐
async deleteEmployee(id: string): Promise<boolean> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: EMPLOYEE_MUTATIONS.DELETE_EMPLOYEE,
- variables: { id }
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.deleteEmployee || false
+ const result = await graphqlRequest(EMPLOYEE_MUTATIONS.DELETE_EMPLOYEE, { id })
+ return result?.data?.deleteEmployee || false
} catch (error: any) {
throw new Error(error.message || '鍒犻櫎鍛樺伐澶辫触')
}
--
Gitblit v1.8.0