|
|
@@ -1,11 +1,10 @@
|
|
|
-import { hc } from 'hono/client'
|
|
|
-import type {
|
|
|
+import { hc } from 'hono/client';
|
|
|
+import type {
|
|
|
AuthRoutes,
|
|
|
UserRoutes,
|
|
|
RoleRoutes,
|
|
|
FileRoutes,
|
|
|
CompanyRoutes,
|
|
|
- MyCompanyRoutes,
|
|
|
JobRoutes,
|
|
|
ApplicationRoutes,
|
|
|
FavoriteRoutes,
|
|
|
@@ -21,144 +20,154 @@ import type {
|
|
|
SilverUsersKnowledgeTagsRoutes,
|
|
|
SilverUsersKnowledgeStatsRoutes,
|
|
|
SilverUsersKnowledgeInteractionsRoutes,
|
|
|
- SilverUsersKnowledgeRankingsRoutes,
|
|
|
+ SilverUsersKnowledgeRankingsRoutes,
|
|
|
SilverUserProfileRoutes,
|
|
|
SilverTalentsAdminRoutes,
|
|
|
+ MyCompanyRoutes,
|
|
|
SilverJobRoutes,
|
|
|
+ CompanyCertificationRoutes,
|
|
|
SilverCompaniesRoutes,
|
|
|
HomeIconRoutes,
|
|
|
SilverKnowledgeRoutes,
|
|
|
AIAgentRoutes
|
|
|
-} from '@/server/api'
|
|
|
-import axios from 'axios'
|
|
|
-
|
|
|
-// 创建自定义fetch函数
|
|
|
-const axiosFetch = async (url: string, options?: RequestInit) => {
|
|
|
- const config: any = {
|
|
|
- url,
|
|
|
- method: options?.method || 'GET',
|
|
|
- headers: options?.headers || {},
|
|
|
- data: options?.body,
|
|
|
- }
|
|
|
-
|
|
|
- // 从localStorage获取token
|
|
|
- const token = localStorage.getItem('token')
|
|
|
- if (token) {
|
|
|
- config.headers.Authorization = `Bearer ${token}`
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- const response = await axios(config)
|
|
|
- return new Response(JSON.stringify(response.data), {
|
|
|
- status: response.status,
|
|
|
- statusText: response.statusText,
|
|
|
- headers: response.headers,
|
|
|
- })
|
|
|
- } catch (error: any) {
|
|
|
- if (error.response) {
|
|
|
- return new Response(JSON.stringify(error.response.data), {
|
|
|
- status: error.response.status,
|
|
|
- statusText: error.response.statusText,
|
|
|
- headers: error.response.headers,
|
|
|
- })
|
|
|
- }
|
|
|
- throw error
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// 创建客户端实例
|
|
|
+} from '@/server/api';
|
|
|
+import { axiosFetch } from './utils/axios'
|
|
|
+
|
|
|
+// 客户端实例 - 严格按照RPC规范命名
|
|
|
export const authClient = hc<AuthRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1.auth
|
|
|
+}).api.v1.auth;
|
|
|
|
|
|
export const userClient = hc<UserRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1.users
|
|
|
+}).api.v1.users;
|
|
|
|
|
|
export const roleClient = hc<RoleRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1.roles
|
|
|
+}).api.v1.roles;
|
|
|
|
|
|
export const fileClient = hc<FileRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1.files
|
|
|
-
|
|
|
-export const companyClient = hc<CompanyRoutes>('/', {
|
|
|
- fetch: axiosFetch,
|
|
|
-}).api.v1['silver-jobs'].companies
|
|
|
+}).api.v1.files;
|
|
|
|
|
|
+// 企业信息客户端 - 新增
|
|
|
export const myCompanyClient = hc<MyCompanyRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1.companies.my
|
|
|
+}).api.v1['companies'].my;
|
|
|
+
|
|
|
+// 银龄岗具体资源客户端(调整为标准格式)
|
|
|
+export const companyClient = hc<CompanyRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+}).api.v1['silver-jobs'].companies;
|
|
|
|
|
|
export const jobClient = hc<JobRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['silver-jobs'].jobs
|
|
|
+}).api.v1['silver-jobs'].jobs;
|
|
|
|
|
|
export const applicationClient = hc<ApplicationRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['silver-jobs'].applications
|
|
|
+}).api.v1['silver-jobs'].applications;
|
|
|
|
|
|
export const favoriteClient = hc<FavoriteRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['silver-jobs'].favorites
|
|
|
+}).api.v1['silver-jobs'].favorites;
|
|
|
|
|
|
export const viewClient = hc<ViewRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['silver-jobs'].views
|
|
|
+}).api.v1['silver-jobs'].views;
|
|
|
|
|
|
export const companyImageClient = hc<CompanyImageRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['silver-jobs']['company-images']
|
|
|
-
|
|
|
-export const silverTalentsClient = hc<SilverTalentsRoutes>('/', {
|
|
|
- fetch: axiosFetch,
|
|
|
-}).api.v1['silver-talents']
|
|
|
-
|
|
|
+}).api.v1['silver-jobs']['company-images'];
|
|
|
+
|
|
|
+// 银龄用户资源客户端 - 重构为集中的对象,避免过深实例化
|
|
|
+export const silverUsersClient = {
|
|
|
+ knowledges: hc<SilverUsersKnowledgesRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+ }).api.v1['silver-users'].knowledges,
|
|
|
+
|
|
|
+ ['knowledge-categories']: hc<SilverUsersKnowledgeCategoriesRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+ }).api.v1['silver-users']['knowledge-categories'],
|
|
|
+
|
|
|
+ ['knowledge-tags']: hc<SilverUsersKnowledgeTagsRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+ }).api.v1['silver-users']['knowledge-tags'],
|
|
|
+
|
|
|
+ ['knowledge-stats']: hc<SilverUsersKnowledgeStatsRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+ }).api.v1['silver-users']['knowledge-stats'],
|
|
|
+
|
|
|
+ ['knowledge-interactions']: hc<SilverUsersKnowledgeInteractionsRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+ }).api.v1['silver-users']['knowledge-interactions'],
|
|
|
+
|
|
|
+ ['knowledge-rankings']: hc<SilverUsersKnowledgeRankingsRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+ }).api.v1['silver-users']['knowledge-rankings'],
|
|
|
+
|
|
|
+ profiles: hc<any>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+ }).api.v1['silver-users'].profiles
|
|
|
+};
|
|
|
+
|
|
|
+// 其他资源客户端
|
|
|
export const elderlyUniversityClient = hc<ElderlyUniversityRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['elderly-universities']
|
|
|
+}).api.v1['elderly-universities'];
|
|
|
|
|
|
export const policyNewsClient = hc<PolicyNewsRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['policy-news']
|
|
|
+}).api.v1['policy-news'];
|
|
|
|
|
|
export const userPreferenceClient = hc<UserPreferenceRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['user-preferences']
|
|
|
+}).api.v1['user-preferences'];
|
|
|
|
|
|
+// 首页API客户端
|
|
|
export const homeClient = hc<HomeRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1.home
|
|
|
+}).api.v1.home;
|
|
|
|
|
|
export const silverUserProfileClient = hc<SilverUserProfileRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
}).api.v1['silver-users'].profiles
|
|
|
|
|
|
+export const silverTalentsClient = hc<SilverTalentsRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+}).api.v1['silver-talents']
|
|
|
+
|
|
|
+
|
|
|
+// 银龄库管理客户端
|
|
|
export const silverTalentsAdminClient = hc<SilverTalentsAdminRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1.admin['silver-talents']
|
|
|
+}).api.v1['admin']['silver-talents']
|
|
|
|
|
|
-export const silverJobClient = hc<SilverJobRoutes>('/', {
|
|
|
+// 公司认证管理客户端
|
|
|
+export const companyCertificationClient = hc<CompanyCertificationRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
-}).api.v1['silver-jobs']
|
|
|
+}).api.v1['company-certification']
|
|
|
|
|
|
+// 银龄公司客户端
|
|
|
export const silverCompaniesClient = hc<SilverCompaniesRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
}).api.v1['silver-companies']
|
|
|
|
|
|
+// 银龄岗管理客户端
|
|
|
+export const silverJobClient = hc<SilverJobRoutes>('/', {
|
|
|
+ fetch: axiosFetch,
|
|
|
+}).api.v1['silver-jobs']
|
|
|
+
|
|
|
+// 首页图标管理客户端
|
|
|
export const homeIconClient = hc<HomeIconRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
}).api.v1['home-icons']
|
|
|
|
|
|
+// 银龄智库管理客户端
|
|
|
export const silverKnowledgeClient = hc<SilverKnowledgeRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
}).api.v1['silver-knowledges']
|
|
|
|
|
|
-export const companyCertificationClient = hc<CompanyCertificationRoutes>('/', {
|
|
|
- fetch: axiosFetch,
|
|
|
-}).api.v1['company-certification']
|
|
|
-
|
|
|
export const aiAgentClient = hc<AIAgentRoutes>('/', {
|
|
|
fetch: axiosFetch,
|
|
|
}).api.v1['ai-agents']
|