完整API模块结构:

client/admin/api/ ├── auth.ts (认证API) ├── users.ts (用户API) ├── files.ts (文件API) ├── theme.ts (主题API) ├── charts.ts (图表API) ├── messages.ts (消息API) ├── sys.ts (系统API) ├── know_info.ts (知识库API) ├── maps.ts (地图API) └── index.ts (统一入口)
This commit is contained in:
yourname
2025-05-13 08:06:34 +00:00
parent bd72f60db8
commit 08ae3b85df
21 changed files with 818 additions and 907 deletions

106
client/admin/api/auth.ts Normal file
View File

@@ -0,0 +1,106 @@
import axios from 'axios';
import type { User } from '../../share/types.ts';
const API_BASE_URL = '/api';
interface AuthLoginResponse {
message: string;
token: string;
refreshToken?: string;
user: User;
}
interface AuthResponse {
message: string;
[key: string]: any;
}
interface AuthAPIType {
login: (username: string, password: string, latitude?: number, longitude?: number) => Promise<AuthLoginResponse>;
register: (username: string, email: string, password: string) => Promise<AuthResponse>;
logout: () => Promise<AuthResponse>;
getCurrentUser: () => Promise<User>;
updateUser: (userId: number, userData: Partial<User>) => Promise<User>;
changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
requestPasswordReset: (email: string) => Promise<AuthResponse>;
resetPassword: (token: string, newPassword: string) => Promise<AuthResponse>;
}
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`, {
username,
password,
latitude,
longitude
});
return response.data;
} catch (error) {
throw error;
}
},
register: async (username: string, email: string, password: string) => {
try {
const response = await axios.post(`${API_BASE_URL}/auth/register`, { username, email, password });
return response.data;
} catch (error) {
throw error;
}
},
logout: async () => {
try {
const response = await axios.post(`${API_BASE_URL}/auth/logout`);
return response.data;
} catch (error) {
throw error;
}
},
getCurrentUser: async () => {
try {
const response = await axios.get(`${API_BASE_URL}/auth/me`);
return response.data;
} catch (error) {
throw error;
}
},
updateUser: async (userId: number, userData: Partial<User>) => {
try {
const response = await axios.put(`${API_BASE_URL}/auth/users/${userId}`, userData);
return response.data;
} catch (error) {
throw error;
}
},
changePassword: async (oldPassword: string, newPassword: string) => {
try {
const response = await axios.post(`${API_BASE_URL}/auth/change-password`, { oldPassword, newPassword });
return response.data;
} catch (error) {
throw error;
}
},
requestPasswordReset: async (email: string) => {
try {
const response = await axios.post(`${API_BASE_URL}/auth/request-password-reset`, { email });
return response.data;
} catch (error) {
throw error;
}
},
resetPassword: async (token: string, newPassword: string) => {
try {
const response = await axios.post(`${API_BASE_URL}/auth/reset-password`, { token, newPassword });
return response.data;
} catch (error) {
throw error;
}
}
};

View File

@@ -0,0 +1,68 @@
import axios from 'axios';
const API_BASE_URL = '/api';
interface ChartDataResponse<T> {
message: string;
data: T;
}
interface UserActivityData {
date: string;
count: number;
}
interface FileUploadsData {
month: string;
count: number;
}
interface FileTypesData {
type: string;
value: number;
}
interface DashboardOverviewData {
userCount: number;
fileCount: number;
articleCount: number;
todayLoginCount: number;
}
export const ChartAPI = {
getUserActivity: async (): Promise<ChartDataResponse<UserActivityData[]>> => {
try {
const response = await axios.get(`${API_BASE_URL}/charts/user-activity`);
return response.data;
} catch (error) {
throw error;
}
},
getFileUploads: async (): Promise<ChartDataResponse<FileUploadsData[]>> => {
try {
const response = await axios.get(`${API_BASE_URL}/charts/file-uploads`);
return response.data;
} catch (error) {
throw error;
}
},
getFileTypes: async (): Promise<ChartDataResponse<FileTypesData[]>> => {
try {
const response = await axios.get(`${API_BASE_URL}/charts/file-types`);
return response.data;
} catch (error) {
throw error;
}
},
getDashboardOverview: async (): Promise<ChartDataResponse<DashboardOverviewData>> => {
try {
const response = await axios.get(`${API_BASE_URL}/charts/dashboard-overview`);
return response.data;
} catch (error) {
throw error;
}
}
};

161
client/admin/api/files.ts Normal file
View File

@@ -0,0 +1,161 @@
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;
}
interface FileListResponse {
message: string;
data: {
list: FileLibrary[];
pagination: {
current: number;
pageSize: number;
total: number;
};
};
}
interface FileSaveResponse {
message: string;
data: FileLibrary;
}
interface FileInfoResponse {
message: string;
data: FileLibrary;
}
interface FileDeleteResponse {
message: string;
}
interface FileCategoryListResponse {
data: FileCategory[];
total: number;
page: number;
pageSize: number;
}
interface FileCategoryCreateResponse {
message: string;
data: FileCategory;
}
interface FileCategoryUpdateResponse {
message: string;
data: FileCategory;
}
interface FileCategoryDeleteResponse {
message: string;
}
export const FileAPI = {
getUploadPolicy: async (filename: string, prefix: string = 'uploads/', maxSize: number = 10 * 1024 * 1024): Promise<FileUploadPolicyResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/upload/policy`, {
params: { filename, prefix, maxSize }
});
return response.data;
} catch (error) {
throw error;
}
},
saveFileInfo: async (fileData: Partial<FileLibrary>): Promise<FileSaveResponse> => {
try {
const response = await axios.post(`${API_BASE_URL}/upload/save`, fileData);
return response.data;
} catch (error) {
throw error;
}
},
getFileList: async (params?: {
page?: number,
pageSize?: number,
category_id?: number,
fileType?: string,
keyword?: string
}): Promise<FileListResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/upload/list`, { params });
return response.data;
} catch (error) {
throw error;
}
},
getFileInfo: async (id: number): Promise<FileInfoResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/upload/${id}`);
return response.data;
} catch (error) {
throw error;
}
},
updateDownloadCount: async (id: number): Promise<FileDeleteResponse> => {
try {
const response = await axios.post(`${API_BASE_URL}/upload/${id}/download`);
return response.data;
} catch (error) {
throw error;
}
},
deleteFile: async (id: number): Promise<FileDeleteResponse> => {
try {
const response = await axios.delete(`${API_BASE_URL}/upload/${id}`);
return response.data;
} catch (error) {
throw error;
}
},
getCategories: async (params?: {
page?: number,
pageSize?: number,
search?: string
}): Promise<FileCategoryListResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/file-categories`, { params });
return response.data;
} catch (error) {
throw error;
}
},
createCategory: async (data: Partial<FileCategory>): Promise<FileCategoryCreateResponse> => {
try {
const response = await axios.post(`${API_BASE_URL}/file-categories`, data);
return response.data;
} catch (error) {
throw error;
}
},
updateCategory: async (id: number, data: Partial<FileCategory>): Promise<FileCategoryUpdateResponse> => {
try {
const response = await axios.put(`${API_BASE_URL}/file-categories/${id}`, data);
return response.data;
} catch (error) {
throw error;
}
},
deleteCategory: async (id: number): Promise<FileCategoryDeleteResponse> => {
try {
const response = await axios.delete(`${API_BASE_URL}/file-categories/${id}`);
return response.data;
} catch (error) {
throw error;
}
}
};

View File

@@ -0,0 +1,9 @@
export * from './auth.ts';
export * from './users.ts';
export * from './files.ts';
export * from './theme.ts';
export * from './charts.ts';
export * from './messages.ts';
export * from './sys.ts';
export * from './know_info.ts';
export * from './maps.ts';

View File

@@ -0,0 +1,95 @@
import axios from 'axios';
import type { KnowInfo } from '../../share/types.ts';
export interface KnowInfoListResponse {
data: KnowInfo[];
pagination: {
current: number;
pageSize: number;
total: number;
totalPages: number;
};
}
interface KnowInfoResponse {
data: KnowInfo;
message?: string;
}
interface KnowInfoCreateResponse {
message: string;
data: KnowInfo;
}
interface KnowInfoUpdateResponse {
message: string;
data: KnowInfo;
}
interface KnowInfoDeleteResponse {
message: string;
id: number;
}
const API_BASE_URL = '/api';
// 知识库API
export const KnowInfoAPI = {
// 获取知识库列表
getKnowInfos: async (params?: {
page?: number;
pageSize?: number;
title?: string;
category?: string;
tags?: string;
}): Promise<KnowInfoListResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/know-infos`, { params });
return response.data;
} catch (error) {
throw error;
}
},
// 获取单个知识详情
getKnowInfo: async (id: number): Promise<KnowInfoResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/know-infos/${id}`);
return response.data;
} catch (error) {
throw error;
}
},
// 创建知识
createKnowInfo: async (data: Partial<KnowInfo>): Promise<KnowInfoCreateResponse> => {
try {
const response = await axios.post(`${API_BASE_URL}/know-infos`, data);
return response.data;
} catch (error) {
throw error;
}
},
// 更新知识
updateKnowInfo: async (id: number, data: Partial<KnowInfo>): Promise<KnowInfoUpdateResponse> => {
try {
const response = await axios.put(`${API_BASE_URL}/know-infos/${id}`, data);
return response.data;
} catch (error) {
throw error;
}
},
// 删除知识
deleteKnowInfo: async (id: number): Promise<KnowInfoDeleteResponse> => {
try {
const response = await axios.delete(`${API_BASE_URL}/know-infos/${id}`);
return response.data;
} catch (error) {
throw error;
}
}
};

64
client/admin/api/maps.ts Normal file
View File

@@ -0,0 +1,64 @@
import axios from 'axios';
import type {
LoginLocation, LoginLocationDetail,
} from '../../share/types.ts';
const API_BASE_URL = '/api';
// 地图相关API的接口类型定义
export interface LoginLocationResponse {
message: string;
data: LoginLocation[];
}
export interface LoginLocationDetailResponse {
message: string;
data: LoginLocationDetail;
}
export interface LoginLocationUpdateResponse {
message: string;
data: LoginLocationDetail;
}
// 地图相关API
export const MapAPI = {
// 获取地图标记点数据
getMarkers: async (params?: {
startTime?: string;
endTime?: string;
userId?: number
}): Promise<LoginLocationResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/map/markers`, { params });
return response.data;
} catch (error) {
throw error;
}
},
// 获取登录位置详情
getLocationDetail: async (locationId: number): Promise<LoginLocationDetailResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/map/location/${locationId}`);
return response.data;
} catch (error) {
throw error;
}
},
// 更新登录位置信息
updateLocation: async (locationId: number, data: {
longitude: number;
latitude: number;
location_name?: string;
}): Promise<LoginLocationUpdateResponse> => {
try {
const response = await axios.put(`${API_BASE_URL}/map/location/${locationId}`, data);
return response.data;
} catch (error) {
throw error;
}
}
};

View File

@@ -0,0 +1,81 @@
import axios from 'axios';
import type { UserMessage, Message } from '../../share/types.ts';
const API_BASE_URL = '/api';
interface MessagesResponse {
data: UserMessage[];
pagination: {
total: number;
current: number;
pageSize: number;
totalPages: number;
};
}
interface MessageResponse {
data: Message;
message?: string;
}
interface MessageCountResponse {
count: number;
}
export const MessageAPI = {
getMessages: async (params?: {
page?: number,
pageSize?: number,
type?: string,
status?: string,
search?: string
}): Promise<MessagesResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/messages`, { params });
return response.data;
} catch (error) {
throw error;
}
},
sendMessage: async (data: {
title: string,
content: string,
type: string,
receiver_ids: number[]
}): Promise<MessageResponse> => {
try {
const response = await axios.post(`${API_BASE_URL}/messages`, data);
return response.data;
} catch (error) {
throw error;
}
},
getUnreadCount: async (): Promise<MessageCountResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/messages/count/unread`);
return response.data;
} catch (error) {
throw error;
}
},
markAsRead: async (id: number): Promise<MessageResponse> => {
try {
const response = await axios.post(`${API_BASE_URL}/messages/${id}/read`);
return response.data;
} catch (error) {
throw error;
}
},
deleteMessage: async (id: number): Promise<MessageResponse> => {
try {
const response = await axios.delete(`${API_BASE_URL}/messages/${id}`);
return response.data;
} catch (error) {
throw error;
}
}
};

49
client/admin/api/sys.ts Normal file
View File

@@ -0,0 +1,49 @@
import axios from 'axios';
import type {
SystemSetting, SystemSettingGroupData,
} from '../../share/types.ts';
const API_BASE_URL = '/api';
export const SystemAPI = {
// 获取所有系统设置
getSettings: async (): Promise<SystemSettingGroupData[]> => {
try {
const response = await axios.get(`${API_BASE_URL}/settings`);
return response.data.data;
} catch (error) {
throw error;
}
},
// 获取指定分组的系统设置
getSettingsByGroup: async (group: string): Promise<SystemSetting[]> => {
try {
const response = await axios.get(`${API_BASE_URL}/settings/group/${group}`);
return response.data.data;
} catch (error) {
throw error;
}
},
// 更新系统设置
updateSettings: async (settings: Partial<SystemSetting>[]): Promise<SystemSetting[]> => {
try {
const response = await axios.put(`${API_BASE_URL}/settings`, settings);
return response.data.data;
} catch (error) {
throw error;
}
},
// 重置系统设置
resetSettings: async (): Promise<SystemSetting[]> => {
try {
const response = await axios.post(`${API_BASE_URL}/settings/reset`);
return response.data.data;
} catch (error) {
throw error;
}
}
};

38
client/admin/api/theme.ts Normal file
View File

@@ -0,0 +1,38 @@
import axios from 'axios';
import type { ThemeSettings } from '../../share/types.ts';
const API_BASE_URL = '/api';
export interface ThemeSettingsResponse {
message: string;
data: ThemeSettings;
}
export const ThemeAPI = {
getThemeSettings: async (): Promise<ThemeSettings> => {
try {
const response = await axios.get(`${API_BASE_URL}/theme`);
return response.data.data;
} catch (error) {
throw error;
}
},
updateThemeSettings: async (themeData: Partial<ThemeSettings>): Promise<ThemeSettings> => {
try {
const response = await axios.put(`${API_BASE_URL}/theme`, themeData);
return response.data.data;
} catch (error) {
throw error;
}
},
resetThemeSettings: async (): Promise<ThemeSettings> => {
try {
const response = await axios.post(`${API_BASE_URL}/theme/reset`);
return response.data.data;
} catch (error) {
throw error;
}
}
};

81
client/admin/api/users.ts Normal file
View File

@@ -0,0 +1,81 @@
import axios from 'axios';
import type { User } from '../../share/types.ts';
const API_BASE_URL = '/api';
interface UsersResponse {
data: User[];
pagination: {
total: number;
current: number;
pageSize: number;
totalPages: number;
};
}
interface UserResponse {
data: User;
message?: string;
}
interface UserCreateResponse {
message: string;
data: User;
}
interface UserUpdateResponse {
message: string;
data: User;
}
interface UserDeleteResponse {
message: string;
id: number;
}
export const UserAPI = {
getUsers: async (params?: { page?: number, limit?: number, search?: string }): Promise<UsersResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/users`, { params });
return response.data;
} catch (error) {
throw error;
}
},
getUser: async (userId: number): Promise<UserResponse> => {
try {
const response = await axios.get(`${API_BASE_URL}/users/${userId}`);
return response.data;
} catch (error) {
throw error;
}
},
createUser: async (userData: Partial<User>): Promise<UserCreateResponse> => {
try {
const response = await axios.post(`${API_BASE_URL}/users`, userData);
return response.data;
} catch (error) {
throw error;
}
},
updateUser: async (userId: number, userData: Partial<User>): Promise<UserUpdateResponse> => {
try {
const response = await axios.put(`${API_BASE_URL}/users/${userId}`, userData);
return response.data;
} catch (error) {
throw error;
}
},
deleteUser: async (userId: number): Promise<UserDeleteResponse> => {
try {
const response = await axios.delete(`${API_BASE_URL}/users/${userId}`);
return response.data;
} catch (error) {
throw error;
}
}
};