| | |
| | | // 获取所有角色 |
| | | async getRoles(): Promise<Role[]> { |
| | | try { |
| | | const data = await graphqlRequest(ROLE_QUERIES.GET_ROLES) |
| | | return 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 data = await graphqlRequest(ROLE_QUERIES.GET_ACTIVE_ROLES) |
| | | return data?.activeRoles || [] |
| | | const result = await graphqlRequest(ROLE_QUERIES.GET_ACTIVE_ROLES) |
| | | return result?.data?.activeRoles || [] |
| | | } catch (error: any) { |
| | | throw new Error(error.message || '获取激活角色列表失败') |
| | | } |
| | |
| | | // 根据ID获取角色 |
| | | async getRoleById(id: string): Promise<Role | null> { |
| | | try { |
| | | const data = await graphqlRequest(ROLE_QUERIES.GET_ROLE, { id }) |
| | | return data?.role || null |
| | | const result = await graphqlRequest(ROLE_QUERIES.GET_ROLE, { id }) |
| | | return result?.data?.role || null |
| | | } catch (error: any) { |
| | | throw new Error(error.message || '获取角色详情失败') |
| | | } |
| | |
| | | // 根据代码获取角色 |
| | | async getRoleByCode(code: string): Promise<Role | null> { |
| | | try { |
| | | const data = await graphqlRequest(ROLE_QUERIES.GET_ROLE_BY_CODE, { code }) |
| | | return 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 || '获取角色详情失败') |
| | | } |
| | |
| | | // 根据状态获取角色 |
| | | async getRolesByState(state: number): Promise<Role[]> { |
| | | try { |
| | | const data = await graphqlRequest(ROLE_QUERIES.GET_ROLES_BY_STATE, { state }) |
| | | return 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 || '获取角色列表失败') |
| | | } |
| | |
| | | // 根据名称搜索角色 |
| | | async searchRolesByName(name: string): Promise<Role[]> { |
| | | try { |
| | | const data = await graphqlRequest(ROLE_QUERIES.SEARCH_ROLES_BY_NAME, { name }) |
| | | return data?.searchRolesByName || [] |
| | | const result = await graphqlRequest(ROLE_QUERIES.SEARCH_ROLES_BY_NAME, { name }) |
| | | return result?.data?.searchRolesByName || [] |
| | | } catch (error: any) { |
| | | throw new Error(error.message || '搜索角色失败') |
| | | } |