From e4f45ed9523e87e28170cfa5b164034271bc394a Mon Sep 17 00:00:00 2001 From: yourname Date: Tue, 13 May 2025 11:44:28 +0000 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E4=BB=8E10=E4=B8=AAAPI=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=96=87=E4=BB=B6=E4=B8=AD=E7=A7=BB=E9=99=A4=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84API=5FBASE=5FURL=E5=AE=9A=E4=B9=89=20?= =?UTF-8?q?=E6=89=80=E6=9C=89API=E8=B0=83=E7=94=A8=E7=8E=B0=E5=9C=A8?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8client/admin/api/index.ts?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=85=A8=E5=B1=80axios=E9=85=8D=E7=BD=AE=20?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E5=8E=9F=E6=9C=89=E5=8A=9F=E8=83=BD=E4=B8=8D?= =?UTF-8?q?=E5=8F=98=E7=9A=84=E5=90=8C=E6=97=B6=E7=AE=80=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/admin/api/auth.ts | 18 ++++++++---------- client/admin/api/charts.ts | 10 ++++------ client/admin/api/files.ts | 22 ++++++++++------------ client/admin/api/index.ts | 16 ++++++++++++++++ client/admin/api/know_info.ts | 13 +++++-------- client/admin/api/maps.ts | 5 ++--- client/admin/api/messages.ts | 12 +++++------- client/admin/api/sys.ts | 14 ++++++-------- client/admin/api/theme.ts | 8 +++----- client/admin/api/users.ts | 12 +++++------- 10 files changed, 64 insertions(+), 66 deletions(-) diff --git a/client/admin/api/auth.ts b/client/admin/api/auth.ts index 999fce3..cc46b82 100644 --- a/client/admin/api/auth.ts +++ b/client/admin/api/auth.ts @@ -1,8 +1,6 @@ import axios from 'axios'; import type { User } from '../../share/types.ts'; -const API_BASE_URL = '/api'; - interface AuthLoginResponse { message: string; token: string; @@ -29,7 +27,7 @@ interface AuthAPIType { export const AuthAPI: AuthAPIType = { login: async (username: string, password: string, latitude?: number, longitude?: number) => { try { - const response = await axios.post(`${API_BASE_URL}/auth/login`, { + const response = await axios.post('/auth/login', { username, password, latitude, @@ -43,7 +41,7 @@ export const AuthAPI: AuthAPIType = { register: async (username: string, email: string, password: string) => { try { - const response = await axios.post(`${API_BASE_URL}/auth/register`, { username, email, password }); + const response = await axios.post('/auth/register', { username, email, password }); return response.data; } catch (error) { throw error; @@ -52,7 +50,7 @@ export const AuthAPI: AuthAPIType = { logout: async () => { try { - const response = await axios.post(`${API_BASE_URL}/auth/logout`); + const response = await axios.post('/auth/logout'); return response.data; } catch (error) { throw error; @@ -61,7 +59,7 @@ export const AuthAPI: AuthAPIType = { getCurrentUser: async () => { try { - const response = await axios.get(`${API_BASE_URL}/auth/me`); + const response = await axios.get('/auth/me'); return response.data; } catch (error) { throw error; @@ -70,7 +68,7 @@ export const AuthAPI: AuthAPIType = { updateUser: async (userId: number, userData: Partial) => { try { - const response = await axios.put(`${API_BASE_URL}/auth/users/${userId}`, userData); + const response = await axios.put(`/auth/users/${userId}`, userData); return response.data; } catch (error) { throw error; @@ -79,7 +77,7 @@ export const AuthAPI: AuthAPIType = { changePassword: async (oldPassword: string, newPassword: string) => { try { - const response = await axios.post(`${API_BASE_URL}/auth/change-password`, { oldPassword, newPassword }); + const response = await axios.post('/auth/change-password', { oldPassword, newPassword }); return response.data; } catch (error) { throw error; @@ -88,7 +86,7 @@ export const AuthAPI: AuthAPIType = { requestPasswordReset: async (email: string) => { try { - const response = await axios.post(`${API_BASE_URL}/auth/request-password-reset`, { email }); + const response = await axios.post('/auth/request-password-reset', { email }); return response.data; } catch (error) { throw error; @@ -97,7 +95,7 @@ export const AuthAPI: AuthAPIType = { resetPassword: async (token: string, newPassword: string) => { try { - const response = await axios.post(`${API_BASE_URL}/auth/reset-password`, { token, newPassword }); + const response = await axios.post('/auth/reset-password', { token, newPassword }); return response.data; } catch (error) { throw error; diff --git a/client/admin/api/charts.ts b/client/admin/api/charts.ts index 0fa23ce..64c185e 100644 --- a/client/admin/api/charts.ts +++ b/client/admin/api/charts.ts @@ -1,7 +1,5 @@ import axios from 'axios'; -const API_BASE_URL = '/api'; - interface ChartDataResponse { message: string; data: T; @@ -32,7 +30,7 @@ interface DashboardOverviewData { export const ChartAPI = { getUserActivity: async (): Promise> => { try { - const response = await axios.get(`${API_BASE_URL}/charts/user-activity`); + const response = await axios.get('/charts/user-activity'); return response.data; } catch (error) { throw error; @@ -41,7 +39,7 @@ export const ChartAPI = { getFileUploads: async (): Promise> => { try { - const response = await axios.get(`${API_BASE_URL}/charts/file-uploads`); + const response = await axios.get('/charts/file-uploads'); return response.data; } catch (error) { throw error; @@ -50,7 +48,7 @@ export const ChartAPI = { getFileTypes: async (): Promise> => { try { - const response = await axios.get(`${API_BASE_URL}/charts/file-types`); + const response = await axios.get('/charts/file-types'); return response.data; } catch (error) { throw error; @@ -59,7 +57,7 @@ export const ChartAPI = { getDashboardOverview: async (): Promise> => { try { - const response = await axios.get(`${API_BASE_URL}/charts/dashboard-overview`); + const response = await axios.get('/charts/dashboard-overview'); return response.data; } catch (error) { throw error; diff --git a/client/admin/api/files.ts b/client/admin/api/files.ts index 3ab56bd..a0ccb2a 100644 --- a/client/admin/api/files.ts +++ b/client/admin/api/files.ts @@ -2,8 +2,6 @@ import axios from 'axios'; import type { FileLibrary, FileCategory } from '../../share/types.ts'; import type { MinioUploadPolicy, OSSUploadPolicy } from '@d8d-appcontainer/types'; -const API_BASE_URL = '/api'; - interface FileUploadPolicyResponse { message: string; data: MinioUploadPolicy | OSSUploadPolicy; @@ -59,7 +57,7 @@ interface FileCategoryDeleteResponse { export const FileAPI = { getUploadPolicy: async (filename: string, prefix: string = 'uploads/', maxSize: number = 10 * 1024 * 1024): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/upload/policy`, { + const response = await axios.get('/upload/policy', { params: { filename, prefix, maxSize } }); return response.data; @@ -70,7 +68,7 @@ export const FileAPI = { saveFileInfo: async (fileData: Partial): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/upload/save`, fileData); + const response = await axios.post('/upload/save', fileData); return response.data; } catch (error) { throw error; @@ -85,7 +83,7 @@ export const FileAPI = { keyword?: string }): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/upload/list`, { params }); + const response = await axios.get('/upload/list', { params }); return response.data; } catch (error) { throw error; @@ -94,7 +92,7 @@ export const FileAPI = { getFileInfo: async (id: number): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/upload/${id}`); + const response = await axios.get(`/upload/${id}`); return response.data; } catch (error) { throw error; @@ -103,7 +101,7 @@ export const FileAPI = { updateDownloadCount: async (id: number): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/upload/${id}/download`); + const response = await axios.post(`/upload/${id}/download`); return response.data; } catch (error) { throw error; @@ -112,7 +110,7 @@ export const FileAPI = { deleteFile: async (id: number): Promise => { try { - const response = await axios.delete(`${API_BASE_URL}/upload/${id}`); + const response = await axios.delete(`/upload/${id}`); return response.data; } catch (error) { throw error; @@ -125,7 +123,7 @@ export const FileAPI = { search?: string }): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/file-categories`, { params }); + const response = await axios.get('/file-categories', { params }); return response.data; } catch (error) { throw error; @@ -134,7 +132,7 @@ export const FileAPI = { createCategory: async (data: Partial): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/file-categories`, data); + const response = await axios.post('/file-categories', data); return response.data; } catch (error) { throw error; @@ -143,7 +141,7 @@ export const FileAPI = { updateCategory: async (id: number, data: Partial): Promise => { try { - const response = await axios.put(`${API_BASE_URL}/file-categories/${id}`, data); + const response = await axios.put(`/file-categories/${id}`, data); return response.data; } catch (error) { throw error; @@ -152,7 +150,7 @@ export const FileAPI = { deleteCategory: async (id: number): Promise => { try { - const response = await axios.delete(`${API_BASE_URL}/file-categories/${id}`); + const response = await axios.delete(`/file-categories/${id}`); return response.data; } catch (error) { throw error; diff --git a/client/admin/api/index.ts b/client/admin/api/index.ts index bf427ab..2ac6ce7 100644 --- a/client/admin/api/index.ts +++ b/client/admin/api/index.ts @@ -1,3 +1,19 @@ +import axios from 'axios'; + +// 基础配置 +export const API_BASE_URL = '/api'; +// 全局axios配置 +axios.defaults.baseURL = API_BASE_URL; + +// 获取OSS完整URL +export const getOssUrl = (path: string): string => { + // 获取全局配置中的OSS_HOST,如果不存在使用默认值 + const ossHost = (window.CONFIG?.OSS_BASE_URL) || ''; + // 确保path不以/开头 + const ossPath = path.startsWith('/') ? path.substring(1) : path; + return `${ossHost}/${ossPath}`; +}; + export * from './auth.ts'; export * from './users.ts'; export * from './files.ts'; diff --git a/client/admin/api/know_info.ts b/client/admin/api/know_info.ts index f199261..50ae3fd 100644 --- a/client/admin/api/know_info.ts +++ b/client/admin/api/know_info.ts @@ -32,9 +32,6 @@ interface KnowInfoDeleteResponse { } -const API_BASE_URL = '/api'; - - // 知识库API export const KnowInfoAPI = { // 获取知识库列表 @@ -46,7 +43,7 @@ export const KnowInfoAPI = { tags?: string; }): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/know-infos`, { params }); + const response = await axios.get('/know-infos', { params }); return response.data; } catch (error) { throw error; @@ -56,7 +53,7 @@ export const KnowInfoAPI = { // 获取单个知识详情 getKnowInfo: async (id: number): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/know-infos/${id}`); + const response = await axios.get(`/know-infos/${id}`); return response.data; } catch (error) { throw error; @@ -66,7 +63,7 @@ export const KnowInfoAPI = { // 创建知识 createKnowInfo: async (data: Partial): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/know-infos`, data); + const response = await axios.post('/know-infos', data); return response.data; } catch (error) { throw error; @@ -76,7 +73,7 @@ export const KnowInfoAPI = { // 更新知识 updateKnowInfo: async (id: number, data: Partial): Promise => { try { - const response = await axios.put(`${API_BASE_URL}/know-infos/${id}`, data); + const response = await axios.put(`/know-infos/${id}`, data); return response.data; } catch (error) { throw error; @@ -86,7 +83,7 @@ export const KnowInfoAPI = { // 删除知识 deleteKnowInfo: async (id: number): Promise => { try { - const response = await axios.delete(`${API_BASE_URL}/know-infos/${id}`); + const response = await axios.delete(`/know-infos/${id}`); return response.data; } catch (error) { throw error; diff --git a/client/admin/api/maps.ts b/client/admin/api/maps.ts index 540345c..36e6e3a 100644 --- a/client/admin/api/maps.ts +++ b/client/admin/api/maps.ts @@ -1,10 +1,9 @@ import axios from 'axios'; -import type { +import { API_BASE_URL } from './index.ts'; +import type { LoginLocation, LoginLocationDetail, } from '../../share/types.ts'; -const API_BASE_URL = '/api'; - // 地图相关API的接口类型定义 export interface LoginLocationResponse { diff --git a/client/admin/api/messages.ts b/client/admin/api/messages.ts index a5d5fa2..bc633cb 100644 --- a/client/admin/api/messages.ts +++ b/client/admin/api/messages.ts @@ -1,8 +1,6 @@ import axios from 'axios'; import type { UserMessage, Message } from '../../share/types.ts'; -const API_BASE_URL = '/api'; - interface MessagesResponse { data: UserMessage[]; pagination: { @@ -31,7 +29,7 @@ export const MessageAPI = { search?: string }): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/messages`, { params }); + const response = await axios.get('/messages', { params }); return response.data; } catch (error) { throw error; @@ -45,7 +43,7 @@ export const MessageAPI = { receiver_ids: number[] }): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/messages`, data); + const response = await axios.post('/messages', data); return response.data; } catch (error) { throw error; @@ -54,7 +52,7 @@ export const MessageAPI = { getUnreadCount: async (): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/messages/count/unread`); + const response = await axios.get('/messages/count/unread'); return response.data; } catch (error) { throw error; @@ -63,7 +61,7 @@ export const MessageAPI = { markAsRead: async (id: number): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/messages/${id}/read`); + const response = await axios.post(`/messages/${id}/read`); return response.data; } catch (error) { throw error; @@ -72,7 +70,7 @@ export const MessageAPI = { deleteMessage: async (id: number): Promise => { try { - const response = await axios.delete(`${API_BASE_URL}/messages/${id}`); + const response = await axios.delete(`/messages/${id}`); return response.data; } catch (error) { throw error; diff --git a/client/admin/api/sys.ts b/client/admin/api/sys.ts index f7dc7ff..6130a7e 100644 --- a/client/admin/api/sys.ts +++ b/client/admin/api/sys.ts @@ -1,16 +1,14 @@ import axios from 'axios'; -import type { - SystemSetting, SystemSettingGroupData, +import type { + SystemSetting, SystemSettingGroupData, } from '../../share/types.ts'; -const API_BASE_URL = '/api'; - export const SystemAPI = { // 获取所有系统设置 getSettings: async (): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/settings`); + const response = await axios.get('/settings'); return response.data.data; } catch (error) { throw error; @@ -20,7 +18,7 @@ export const SystemAPI = { // 获取指定分组的系统设置 getSettingsByGroup: async (group: string): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/settings/group/${group}`); + const response = await axios.get(`/settings/group/${group}`); return response.data.data; } catch (error) { throw error; @@ -30,7 +28,7 @@ export const SystemAPI = { // 更新系统设置 updateSettings: async (settings: Partial[]): Promise => { try { - const response = await axios.put(`${API_BASE_URL}/settings`, settings); + const response = await axios.put('/settings', settings); return response.data.data; } catch (error) { throw error; @@ -40,7 +38,7 @@ export const SystemAPI = { // 重置系统设置 resetSettings: async (): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/settings/reset`); + const response = await axios.post('/settings/reset'); return response.data.data; } catch (error) { throw error; diff --git a/client/admin/api/theme.ts b/client/admin/api/theme.ts index 863a6b2..ad9c189 100644 --- a/client/admin/api/theme.ts +++ b/client/admin/api/theme.ts @@ -1,8 +1,6 @@ import axios from 'axios'; import type { ThemeSettings } from '../../share/types.ts'; -const API_BASE_URL = '/api'; - export interface ThemeSettingsResponse { message: string; data: ThemeSettings; @@ -11,7 +9,7 @@ export interface ThemeSettingsResponse { export const ThemeAPI = { getThemeSettings: async (): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/theme`); + const response = await axios.get('/theme'); return response.data.data; } catch (error) { throw error; @@ -20,7 +18,7 @@ export const ThemeAPI = { updateThemeSettings: async (themeData: Partial): Promise => { try { - const response = await axios.put(`${API_BASE_URL}/theme`, themeData); + const response = await axios.put('/theme', themeData); return response.data.data; } catch (error) { throw error; @@ -29,7 +27,7 @@ export const ThemeAPI = { resetThemeSettings: async (): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/theme/reset`); + const response = await axios.post('/theme/reset'); return response.data.data; } catch (error) { throw error; diff --git a/client/admin/api/users.ts b/client/admin/api/users.ts index 8e6c018..052f796 100644 --- a/client/admin/api/users.ts +++ b/client/admin/api/users.ts @@ -1,8 +1,6 @@ import axios from 'axios'; import type { User } from '../../share/types.ts'; -const API_BASE_URL = '/api'; - interface UsersResponse { data: User[]; pagination: { @@ -36,7 +34,7 @@ interface UserDeleteResponse { export const UserAPI = { getUsers: async (params?: { page?: number, limit?: number, search?: string }): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/users`, { params }); + const response = await axios.get('/users', { params }); return response.data; } catch (error) { throw error; @@ -45,7 +43,7 @@ export const UserAPI = { getUser: async (userId: number): Promise => { try { - const response = await axios.get(`${API_BASE_URL}/users/${userId}`); + const response = await axios.get(`/users/${userId}`); return response.data; } catch (error) { throw error; @@ -54,7 +52,7 @@ export const UserAPI = { createUser: async (userData: Partial): Promise => { try { - const response = await axios.post(`${API_BASE_URL}/users`, userData); + const response = await axios.post('/users', userData); return response.data; } catch (error) { throw error; @@ -63,7 +61,7 @@ export const UserAPI = { updateUser: async (userId: number, userData: Partial): Promise => { try { - const response = await axios.put(`${API_BASE_URL}/users/${userId}`, userData); + const response = await axios.put(`/users/${userId}`, userData); return response.data; } catch (error) { throw error; @@ -72,7 +70,7 @@ export const UserAPI = { deleteUser: async (userId: number): Promise => { try { - const response = await axios.delete(`${API_BASE_URL}/users/${userId}`); + const response = await axios.delete(`/users/${userId}`); return response.data; } catch (error) { throw error;