From 8337c34fcc761d07acaad796d10f3e12e9bbe2d1 Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期日, 05 十月 2025 08:56:04 +0800
Subject: [PATCH] feat: 微信项目详情支持阶段评分时间轴
---
web/src/api/role.ts | 156 +++++++++++++--------------------------------------
1 files changed, 41 insertions(+), 115 deletions(-)
diff --git a/web/src/api/role.ts b/web/src/api/role.ts
index 46aed90..441efb4 100644
--- a/web/src/api/role.ts
+++ b/web/src/api/role.ts
@@ -1,5 +1,7 @@
// 瑙掕壊绠$悊API
+import { API_CONFIG, graphqlRequest } from '@/config/api'
+
// 瑙掕壊鐩稿叧鐨� GraphQL 鏌ヨ
export const ROLE_QUERIES = {
// 鑾峰彇鎵�鏈夎鑹�
@@ -78,19 +80,19 @@
`,
// 鏍规嵁鍚嶇О妯$硦鏌ヨ瑙掕壊
- GET_ROLES_BY_NAME: `
- query GetRolesByName($name: String!) {
- rolesByName(name: $name) {
- id
- code
- name
- description
- state
- createTime
- updateTime
- }
- }
- `
+ SEARCH_ROLES_BY_NAME: `
+ query SearchRolesByName($name: String!) {
+ searchRolesByName(name: $name) {
+ id
+ code
+ name
+ description
+ state
+ createTime
+ updateTime
+ }
+ }
+ `
}
// 绫诲瀷瀹氫箟
@@ -109,136 +111,60 @@
// 鑾峰彇鎵�鏈夎鑹�
async getRoles(): Promise<Role[]> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: ROLE_QUERIES.GET_ROLES
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.roles || []
+ const result = await graphqlRequest(ROLE_QUERIES.GET_ROLES)
+ return result?.data?.roles || []
} catch (error: any) {
throw new Error(error.message || '鑾峰彇瑙掕壊鍒楄〃澶辫触')
}
},
- // 鑾峰彇鎵�鏈夊惎鐢ㄧ姸鎬佺殑瑙掕壊
+ // 鑾峰彇婵�娲荤姸鎬佺殑瑙掕壊
async getActiveRoles(): Promise<Role[]> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: ROLE_QUERIES.GET_ACTIVE_ROLES
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.activeRoles || []
+ const result = await graphqlRequest(ROLE_QUERIES.GET_ACTIVE_ROLES)
+ return result?.data?.activeRoles || []
} catch (error: any) {
- throw new Error(error.message || '鑾峰彇鍚敤瑙掕壊鍒楄〃澶辫触')
+ throw new Error(error.message || '鑾峰彇婵�娲昏鑹插垪琛ㄥけ璐�')
}
},
- // 鏍规嵁ID鑾峰彇瑙掕壊璇︽儏
- async getRoleById(id: string): Promise<Role | null> {
- try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: ROLE_QUERIES.GET_ROLE,
- variables: { id }
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.role || null
- } catch (error: any) {
- throw new Error(error.message || '鑾峰彇瑙掕壊璇︽儏澶辫触')
- }
- },
+ // 鏍规嵁ID鑾峰彇瑙掕壊
+ async getRoleById(id: string): Promise<Role | null> {
+ try {
+ const result = await graphqlRequest(ROLE_QUERIES.GET_ROLE, { id })
+ return result?.data?.role || null
+ } catch (error: any) {
+ throw new Error(error.message || '鑾峰彇瑙掕壊璇︽儏澶辫触')
+ }
+ },
- // 鏍规嵁瑙掕壊浠g爜鑾峰彇瑙掕壊
+ // 鏍规嵁浠g爜鑾峰彇瑙掕壊
async getRoleByCode(code: string): Promise<Role | null> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: ROLE_QUERIES.GET_ROLE_BY_CODE,
- variables: { code }
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.roleByCode || null
+ const result = await graphqlRequest(ROLE_QUERIES.GET_ROLE_BY_CODE, { code })
+ return result?.data?.roleByCode || null
} catch (error: any) {
- throw new Error(error.message || '鏍规嵁浠g爜鑾峰彇瑙掕壊澶辫触')
+ throw new Error(error.message || '鑾峰彇瑙掕壊璇︽儏澶辫触')
}
},
// 鏍规嵁鐘舵�佽幏鍙栬鑹�
async getRolesByState(state: number): Promise<Role[]> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: ROLE_QUERIES.GET_ROLES_BY_STATE,
- variables: { state }
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.rolesByState || []
+ const result = await graphqlRequest(ROLE_QUERIES.GET_ROLES_BY_STATE, { state })
+ return result?.data?.rolesByState || []
} catch (error: any) {
- throw new Error(error.message || '鏍规嵁鐘舵�佽幏鍙栬鑹插け璐�')
+ throw new Error(error.message || '鑾峰彇瑙掕壊鍒楄〃澶辫触')
}
},
- // 鏍规嵁鍚嶇О妯$硦鏌ヨ瑙掕壊
+ // 鏍规嵁鍚嶇О鎼滅储瑙掕壊
async searchRolesByName(name: string): Promise<Role[]> {
try {
- const response = await fetch('http://localhost:8080/api/graphql', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- query: ROLE_QUERIES.GET_ROLES_BY_NAME,
- variables: { name }
- })
- })
- const result = await response.json()
- if (result.errors) {
- throw new Error(result.errors[0].message)
- }
- return result.data?.rolesByName || []
+ const result = await graphqlRequest(ROLE_QUERIES.SEARCH_ROLES_BY_NAME, { name })
+ return result?.data?.searchRolesByName || []
} catch (error: any) {
- throw new Error(error.message || '鏍规嵁鍚嶇О鎼滅储瑙掕壊澶辫触')
+ throw new Error(error.message || '鎼滅储瑙掕壊澶辫触')
}
}
}
\ No newline at end of file
--
Gitblit v1.8.0