You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
5.0 KiB
132 lines
5.0 KiB
import axios from 'axios'
|
|
import { ElMessage } from 'element-plus'
|
|
import router from '@/router'
|
|
|
|
const api = axios.create({
|
|
baseURL: '/api',
|
|
timeout: 30000,
|
|
})
|
|
|
|
api.interceptors.request.use((config) => {
|
|
const token = localStorage.getItem('token')
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`
|
|
}
|
|
return config
|
|
})
|
|
|
|
api.interceptors.response.use(
|
|
(response) => response.data,
|
|
(error) => {
|
|
const msg = error.response?.data?.message || error.message || '请求失败'
|
|
if (error.response?.status === 401) {
|
|
localStorage.removeItem('token')
|
|
router.push('/login')
|
|
}
|
|
ElMessage.error(msg)
|
|
return Promise.reject(error)
|
|
}
|
|
)
|
|
|
|
export default api
|
|
|
|
export const authApi = {
|
|
login: (data: { username: string; password: string }) => api.post('/auth/login', data),
|
|
getMe: () => api.get('/auth/me'),
|
|
}
|
|
|
|
export const orgApi = {
|
|
getDepartments: () => api.get('/org/departments'),
|
|
createDepartment: (data: any) => api.post('/org/departments', data),
|
|
updateDepartment: (id: string, data: any) => api.put(`/org/departments/${id}`, data),
|
|
deleteDepartment: (id: string) => api.delete(`/org/departments/${id}`),
|
|
getUsers: () => api.get('/org/users'),
|
|
getUser: (id: string) => api.get(`/org/users/${id}`),
|
|
createUser: (data: any) => api.post('/org/users', data),
|
|
updateUser: (id: string, data: any) => api.put(`/org/users/${id}`, data),
|
|
getSubordinates: () => api.get('/org/subordinates'),
|
|
}
|
|
|
|
export const rbacApi = {
|
|
getRoles: () => api.get('/rbac/roles'),
|
|
getRole: (id: string) => api.get(`/rbac/roles/${id}`),
|
|
createRole: (data: any) => api.post('/rbac/roles', data),
|
|
updateRole: (id: string, data: any) => api.put(`/rbac/roles/${id}`, data),
|
|
deleteRole: (id: string) => api.delete(`/rbac/roles/${id}`),
|
|
getPermissions: () => api.get('/rbac/permissions'),
|
|
}
|
|
|
|
export const monitorApi = {
|
|
getEmployees: () => api.get('/monitor/employees'),
|
|
getDashboard: (id: string) => api.get(`/monitor/employee/${id}/dashboard`),
|
|
getAnalysis: (id: string) => api.get(`/monitor/employee/${id}/analysis`),
|
|
}
|
|
|
|
export const taskApi = {
|
|
getTasks: () => api.get('/tasks'),
|
|
createTask: (data: any) => api.post('/tasks', data),
|
|
getTask: (id: string) => api.get(`/tasks/${id}`),
|
|
updateTask: (id: string, data: any) => api.put(`/tasks/${id}`, data),
|
|
pushTask: (id: string) => api.post(`/tasks/${id}/push`),
|
|
}
|
|
|
|
export const flowApi = {
|
|
getFlows: () => api.get('/flow/definitions'),
|
|
getFlow: (id: string) => api.get(`/flow/definitions/${id}`),
|
|
createFlow: (data: any) => api.post('/flow/definitions', data),
|
|
updateFlow: (id: string, data: any) => api.put(`/flow/definitions/${id}`, data),
|
|
deleteFlow: (id: string) => api.delete(`/flow/definitions/${id}`),
|
|
publishFlow: (id: string) => api.post(`/flow/definitions/${id}/publish`),
|
|
unpublishFlow: (id: string) => api.post(`/flow/definitions/${id}/unpublish`),
|
|
executeFlow: (id: string, data: any) => api.post(`/flow/definitions/${id}/execute`, data),
|
|
testFlow: (id: string) => api.post(`/flow/definitions/${id}/test`),
|
|
getMarket: () => api.get('/flow/market'),
|
|
}
|
|
|
|
export const wecomApi = {
|
|
sendMessage: (data: any) => api.post('/wecom/send', data),
|
|
getConfig: () => api.get('/wecom/config'),
|
|
}
|
|
|
|
export const agentApi = {
|
|
chat: (type: string, data: any) => api.post(`/agent/chat/${type}`, data),
|
|
getList: () => api.get('/agent/list'),
|
|
getHistory: (sessionId: string) => api.get(`/agent/history/${sessionId}`),
|
|
}
|
|
|
|
export const mcpApi = {
|
|
getServers: () => api.get('/mcp/servers'),
|
|
registerServer: (data: any) => api.post('/mcp/servers', data),
|
|
testConnection: (id: string) => api.post(`/mcp/servers/${id}/test`),
|
|
unregisterServer: (id: string) => api.delete(`/mcp/servers/${id}`),
|
|
}
|
|
|
|
export const auditApi = {
|
|
getLogs: (params?: any) => api.get('/audit/logs', { params }),
|
|
getActionTypes: () => api.get('/audit/actions'),
|
|
getStats: () => api.get('/audit/stats'),
|
|
exportLogs: (params?: any) => api.get('/audit/export', { params, responseType: 'blob' }),
|
|
}
|
|
|
|
export const documentApi = {
|
|
upload: (formData: FormData) => api.post('/document/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' } }),
|
|
parse: (fileId: string) => api.post(`/document/parse/${fileId}`),
|
|
deleteFile: (fileId: string) => api.delete(`/document/${fileId}`),
|
|
format: (data: any) => api.post('/document/format', data),
|
|
}
|
|
|
|
export const notificationApi = {
|
|
send: (data: any) => api.post('/notification/send', data),
|
|
getTemplates: () => api.get('/notification/templates'),
|
|
createTemplate: (data: any) => api.post('/notification/templates', data),
|
|
deleteTemplate: (id: string) => api.delete(`/notification/templates/${id}`),
|
|
getWsStats: () => api.get('/notification/ws/stats'),
|
|
}
|
|
|
|
export const systemApi = {
|
|
getHealth: () => api.get('/system/health'),
|
|
getStats: () => api.get('/system/stats'),
|
|
getMetrics: (params?: any) => api.get('/system/metrics', { params }),
|
|
clearCache: (pattern?: string) => api.post('/system/cache/clear', null, { params: { pattern } }),
|
|
getCacheStats: () => api.get('/system/cache/stats'),
|
|
}
|