refactor(frontend): 重构前端第二版
This commit is contained in:
1 parent
2631f78b00
commit
4b562cfa82
205 files changed
+15399
-12015
No files matched your search
@@ -0,0 +1,178 @@
|
||||
/**
|
||||
* features/admin/api/admin.api.ts
|
||||
* 管理后台 HTTP API:用户、部门、Agent、权限、报表、企业微信、公告等。
|
||||
*/
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import type { AdminDashboardBadges, AdminDashboardSummary } from '../types/dashboard.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
||||
|
||||
// Users
|
||||
export const listAdminUsers = () => requestJson<any[]>('/api/admin/users', auth());
|
||||
export const createAdminUser = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/users', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const updateAdminUser = (id: number, payload: Record<string, unknown>) =>
|
||||
requestJson(`/api/admin/users/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const approveAdminUser = (id: number) =>
|
||||
requestJson(`/api/admin/users/${id}/approve`, { method: 'POST', ...auth() });
|
||||
export const rejectAdminUser = (id: number) =>
|
||||
requestJson(`/api/admin/users/${id}/reject`, { method: 'POST', ...auth() });
|
||||
export const cleanupRejectedAdminUsers = () =>
|
||||
requestJson<{ deleted_count: number }>('/api/admin/users/cleanup-rejected', { method: 'POST', ...auth() });
|
||||
export const batchDeleteAdminUsers = (userIds: number[]) =>
|
||||
requestJson<{ deleted_count: number }>('/api/admin/users/batch-delete', {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify({ user_ids: userIds }),
|
||||
});
|
||||
export const batchUpdateAdminUsers = (userIds: number[], data: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/users/batch', {
|
||||
method: 'PUT',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify({ user_ids: userIds, data }),
|
||||
});
|
||||
export const updateAdminUserPermissions = (userId: number, agentIds: number[]) =>
|
||||
requestJson(`/api/admin/users/${userId}/permissions`, {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify({ agent_ids: agentIds }),
|
||||
});
|
||||
|
||||
// Departments
|
||||
export const listAdminDepartments = () => requestJson<any[]>('/api/admin/departments', auth());
|
||||
export const createAdminDepartment = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/departments', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const updateAdminDepartment = (id: number, payload: Record<string, unknown>) =>
|
||||
requestJson(`/api/admin/departments/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const deleteAdminDepartment = (id: number) =>
|
||||
requestJson(`/api/admin/departments/${id}`, { method: 'DELETE', ...auth() });
|
||||
|
||||
// Agents
|
||||
export const listAdminAgents = () => requestJson<any[]>('/api/admin/agents', auth());
|
||||
export const createAdminAgent = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/agents', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const updateAdminAgent = (id: number, payload: Record<string, unknown>) =>
|
||||
requestJson(`/api/admin/agents/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const deleteAdminAgent = (id: number) =>
|
||||
requestJson(`/api/admin/agents/${id}`, { method: 'DELETE', ...auth() });
|
||||
|
||||
// Agent Guides
|
||||
export const listAdminAgentGuides = (agentId?: number) => {
|
||||
const url = agentId ? `/api/admin/guides?agent_id=${agentId}` : '/api/admin/guides';
|
||||
return requestJson<any[]>(url, auth());
|
||||
};
|
||||
|
||||
export const createAdminAgentGuide = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/guides', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
|
||||
export const updateAdminAgentGuide = (id: number, payload: Record<string, unknown>) =>
|
||||
requestJson(`/api/admin/guides/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
|
||||
export const deleteAdminAgentGuide = (id: number) =>
|
||||
requestJson(`/api/admin/guides/${id}`, { method: 'DELETE', ...auth() });
|
||||
|
||||
export const uploadAdminAgentGuideFile = async (file: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const response = await fetch('/api/admin/guides/upload', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
body: formData,
|
||||
});
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({}));
|
||||
throw new Error(error.message || 'Upload failed');
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
export const testAdminAgent = (id: number) =>
|
||||
requestJson<any>(`/api/admin/agents/${id}/test`, { method: 'POST', ...auth() });
|
||||
export const saveAdminAgentPermissions = (agentId: number, userIds: number[]) =>
|
||||
requestJson(`/api/admin/agents/${agentId}/permissions`, {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify({ user_ids: userIds }),
|
||||
});
|
||||
|
||||
// Permission requests
|
||||
export const listAdminPermissionRequests = () =>
|
||||
requestJson<any[]>('/api/admin/permission-requests', auth());
|
||||
export const approveAdminPermissionRequest = (id: number) =>
|
||||
requestJson(`/api/admin/permission-requests/${id}/approve`, { method: 'POST', ...auth() });
|
||||
export const rejectAdminPermissionRequest = (id: number) =>
|
||||
requestJson(`/api/admin/permission-requests/${id}/reject`, { method: 'POST', ...auth() });
|
||||
export const batchUpdateAdminPermissions = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/permissions/batch', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const importAdminPermissions = (formData: FormData) =>
|
||||
requestJson('/api/admin/permissions/import', { method: 'POST', ...auth(), body: formData });
|
||||
|
||||
// Dashboard
|
||||
/** 仪表盘四张卡片:Agent 数、用户数、对话总数、平均评分 */
|
||||
export const getAdminDashboardSummary = () =>
|
||||
requestJson<AdminDashboardSummary>('/api/admin/dashboard/summary', auth());
|
||||
|
||||
/** 侧栏角标:待审批用户数、待处理权限申请数 */
|
||||
export const getAdminDashboardBadges = () =>
|
||||
requestJson<AdminDashboardBadges>('/api/admin/dashboard/badges', auth());
|
||||
|
||||
// Reports
|
||||
export const getAdminUsageReport = () => requestJson<any>('/api/admin/reports/usage', auth());
|
||||
export const getAdminFeedbackReport = () => requestJson<any>('/api/admin/reports/feedback', auth());
|
||||
export const getAdminReportTable = (url: string) => requestJson<any[]>(url, auth());
|
||||
export const getAdminReportTableCount = (url: string) => requestJson<{ total: number }>(url, auth());
|
||||
export const batchDeleteAdminChatLogs = (ids: number[]) =>
|
||||
requestJson<{ deleted_count: number }>('/api/admin/database/chat_logs/batch-delete', {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify({ ids }),
|
||||
});
|
||||
|
||||
// WeCom admin
|
||||
export const listAdminWecomBindings = (boundOnly: boolean) =>
|
||||
requestJson<any[]>(`/api/admin/wecom/bindings?bound_only=${boundOnly ? 'true' : 'false'}`, auth());
|
||||
export const listAdminWecomLoginAudits = (query: string) =>
|
||||
requestJson<any[]>(`/api/admin/wecom/login-audits?${query}`, auth());
|
||||
export const getAdminWecomSystemSettings = () =>
|
||||
requestJson<any>('/api/admin/wecom/system-settings', auth());
|
||||
export const getAdminWecomIntegrationManifest = () =>
|
||||
requestJson<any>('/api/admin/wecom/integration-manifest', auth());
|
||||
export const saveAdminWecomSystemSettings = (payload: Record<string, unknown>) =>
|
||||
requestJson<any>('/api/admin/wecom/system-settings', {
|
||||
method: 'PUT',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
export const getAdminWecomNotifySettings = () =>
|
||||
requestJson<any>('/api/admin/wecom/notify-settings', auth());
|
||||
export const saveAdminWecomNotifySettings = (payload: Record<string, unknown>) =>
|
||||
requestJson<any>('/api/admin/wecom/notify-settings', {
|
||||
method: 'PUT',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
export const getAdminWecomNotifyMetrics = () =>
|
||||
requestJson<any>('/api/admin/wecom/notify-metrics', auth());
|
||||
export const bindAdminWecomUser = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/wecom/bind', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const unbindAdminWecomUser = (userId: number) =>
|
||||
requestJson('/api/admin/wecom/unbind', {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify({ user_id: userId }),
|
||||
});
|
||||
|
||||
// Announcements (admin module uses user endpoints)
|
||||
export const listAnnouncements = () => requestJson<any[]>('/api/user/announcements', auth());
|
||||
export const createAnnouncement = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/user/announcements', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const deleteAnnouncement = (id: number) =>
|
||||
requestJson(`/api/user/announcements/${id}`, { method: 'DELETE', ...auth() });
|
||||
|
||||
// Quick questions
|
||||
export const listAdminQuickQuestions = () => requestJson<any[]>('/api/admin/quick-questions', auth());
|
||||
export const saveAdminQuickQuestion = (url: string, method: string, payload: Record<string, unknown>) =>
|
||||
requestJson(url, { method, ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const deleteAdminQuickQuestion = (id: number) =>
|
||||
requestJson(`/api/admin/quick-questions/${id}`, { method: 'DELETE', ...auth() });
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* features/admin/api/schedule.api.ts
|
||||
* 管理后台定时任务 HTTP API:任务 CRUD、配置、测试执行、运行记录。
|
||||
*/
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import type {
|
||||
DifyExecutionSnapshot,
|
||||
ScheduleRun,
|
||||
ScheduleTask,
|
||||
StepLog,
|
||||
TestScheduleRunResult,
|
||||
TestScheduleSqlResult,
|
||||
} from '@/shared/types/schedule.types';
|
||||
|
||||
async function getJson<T>(url: string): Promise<T> {
|
||||
return requestJson<T>(url, { headers: getAuthHeaders() });
|
||||
}
|
||||
|
||||
export const listAdminSchedules = () =>
|
||||
getJson<ScheduleTask[]>('/api/admin/schedules');
|
||||
|
||||
export const getAdminSchedule = (taskId: number) =>
|
||||
getJson<ScheduleTask>(`/api/admin/schedules/${taskId}`);
|
||||
|
||||
export const exportAdminScheduleUrl = (taskId: number) => `/api/admin/schedules/${taskId}/export`;
|
||||
|
||||
export const importAdminSchedules = async (payload: any) => {
|
||||
return requestJson('/api/admin/schedules/import', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
};
|
||||
|
||||
export const getAdminScheduleTaskConfig = (taskId: number) =>
|
||||
getJson<{ data_source_type: string; config: Record<string, any> | null }>(`/api/admin/schedule-config/${taskId}`);
|
||||
|
||||
export const updateAdminScheduleTaskConfig = (taskId: number, payload: Record<string, any>) =>
|
||||
requestJson(`/api/admin/schedule-config/${taskId}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const testAdminScheduleSql = (taskId: number, payload: { fetch_where_conditions?: string; fetch_order_by?: string; limit?: number }) =>
|
||||
requestJson<TestScheduleSqlResult>(`/api/admin/schedule-config/${taskId}/test-sql`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const testAdminScheduleRun = (
|
||||
taskId: number,
|
||||
payload: {
|
||||
fetch_where_conditions?: string;
|
||||
fetch_order_by?: string;
|
||||
limit?: number;
|
||||
kb_sync_enabled?: boolean;
|
||||
},
|
||||
) =>
|
||||
requestJson<TestScheduleRunResult>(`/api/admin/schedule-config/${taskId}/test-run`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const createAdminSchedule = (payload: Partial<ScheduleTask> & { config?: Record<string, any> }) =>
|
||||
requestJson('/api/admin/schedules', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const updateAdminSchedule = (id: number, payload: Partial<ScheduleTask> & { config?: Record<string, any> }) =>
|
||||
requestJson(`/api/admin/schedules/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
export const deleteAdminSchedule = (id: number) =>
|
||||
requestJson(`/api/admin/schedules/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
|
||||
export const runAdminSchedule = (id: number) =>
|
||||
requestJson(`/api/admin/schedules/${id}/run`, { method: 'POST', headers: getAuthHeaders() });
|
||||
|
||||
export const toggleAdminSchedule = (id: number, enabled: boolean) =>
|
||||
requestJson(`/api/admin/schedules/${id}/${enabled ? 'enable' : 'disable'}`, { method: 'POST', headers: getAuthHeaders() });
|
||||
|
||||
export const listAdminScheduleRuns = (taskId: number, params?: { status?: string; started_after?: string; started_before?: string }) => {
|
||||
const sp = new URLSearchParams();
|
||||
if (params?.status) sp.set('status', params.status);
|
||||
if (params?.started_after) sp.set('started_after', params.started_after);
|
||||
if (params?.started_before) sp.set('started_before', params.started_before);
|
||||
const qs = sp.toString();
|
||||
return getJson<ScheduleRun[]>(`/api/admin/schedules/${taskId}/runs${qs ? '?' + qs : ''}`);
|
||||
};
|
||||
|
||||
export const adminRunExcelUrl = (runId: number) => `/api/admin/schedule-runs/${runId}/excel`;
|
||||
|
||||
export type { DifyExecutionSnapshot, ScheduleRun, ScheduleTask, StepLog, TestScheduleRunResult, TestScheduleSqlResult };
|
||||
Reference in new issue
Block a user