262 lines
7.3 KiB
TypeScript
262 lines
7.3 KiB
TypeScript
import { request } from '../request'
|
|
import { ApiResponse, PaginatedResponse, QueryRequest } from '../types'
|
|
|
|
// 中心配置相关类型
|
|
export interface Tenant {
|
|
id: string
|
|
name: string
|
|
code: string
|
|
type: 'individual' | 'enterprise' | 'cooperative'
|
|
status: 'active' | 'inactive' | 'suspended'
|
|
contactPerson: string
|
|
contactPhone: string
|
|
contactEmail: string
|
|
address: string
|
|
maxUsers: number
|
|
currentUsers: number
|
|
subscriptionPlan: 'basic' | 'standard' | 'premium'
|
|
subscriptionExpiry?: string
|
|
settings: {
|
|
timezone: string
|
|
language: string
|
|
currency: string
|
|
dateFormat: string
|
|
numberFormat: string
|
|
}
|
|
features: string[]
|
|
createdAt: string
|
|
updatedAt: string
|
|
}
|
|
|
|
export interface User {
|
|
id: string
|
|
username: string
|
|
email: string
|
|
phone: string
|
|
realName: string
|
|
avatar?: string
|
|
role: 'admin' | 'manager' | 'operator' | 'viewer'
|
|
tenantId: string
|
|
status: 'active' | 'inactive' | 'locked'
|
|
lastLoginAt?: string
|
|
permissions: string[]
|
|
preferences: {
|
|
language: string
|
|
theme: 'light' | 'dark' | 'auto'
|
|
notifications: {
|
|
email: boolean
|
|
sms: boolean
|
|
push: boolean
|
|
}
|
|
}
|
|
createdAt: string
|
|
updatedAt: string
|
|
}
|
|
|
|
export interface SystemParameter {
|
|
id: string
|
|
category: 'system' | 'business' | 'notification' | 'security' | 'integration'
|
|
key: string
|
|
value: string
|
|
type: 'string' | 'number' | 'boolean' | 'json'
|
|
description: string
|
|
isEditable: boolean
|
|
requiresRestart: boolean
|
|
validationRules?: {
|
|
required?: boolean
|
|
min?: number
|
|
max?: number
|
|
pattern?: string
|
|
options?: string[]
|
|
}
|
|
tenantId?: string
|
|
createdAt: string
|
|
updatedAt: string
|
|
}
|
|
|
|
export interface SystemLog {
|
|
id: string
|
|
level: 'debug' | 'info' | 'warn' | 'error' | 'fatal'
|
|
category: 'system' | 'business' | 'security' | 'performance'
|
|
message: string
|
|
details?: any
|
|
userId?: string
|
|
tenantId?: string
|
|
ip?: string
|
|
userAgent?: string
|
|
timestamp: string
|
|
duration?: number
|
|
stackTrace?: string
|
|
}
|
|
|
|
export interface Message {
|
|
id: string
|
|
type: 'system' | 'business' | 'notification' | 'alert'
|
|
category: 'info' | 'warning' | 'error' | 'success'
|
|
title: string
|
|
content: string
|
|
senderId?: string
|
|
recipientId?: string
|
|
recipientRole?: string
|
|
tenantId?: string
|
|
status: 'unread' | 'read' | 'archived'
|
|
priority: 'low' | 'medium' | 'high' | 'urgent'
|
|
expiresAt?: string
|
|
metadata?: Record<string, any>
|
|
createdAt: string
|
|
readAt?: string
|
|
}
|
|
|
|
export const configApi = {
|
|
// 租户管理
|
|
getTenantList: (params: QueryRequest): Promise<ApiResponse<PaginatedResponse<Tenant>>> => {
|
|
return request.get('/config/tenants', params)
|
|
},
|
|
|
|
getTenantDetail: (id: string): Promise<ApiResponse<Tenant>> => {
|
|
return request.get(`/config/tenants/${id}`)
|
|
},
|
|
|
|
createTenant: (data: Omit<Tenant, 'id' | 'createdAt' | 'updatedAt' | 'currentUsers'>): Promise<ApiResponse<Tenant>> => {
|
|
return request.post('/config/tenants', data)
|
|
},
|
|
|
|
updateTenant: (id: string, data: Partial<Tenant>): Promise<ApiResponse<Tenant>> => {
|
|
return request.put(`/config/tenants/${id}`, data)
|
|
},
|
|
|
|
deleteTenant: (id: string): Promise<ApiResponse<void>> => {
|
|
return request.delete(`/config/tenants/${id}`)
|
|
},
|
|
|
|
suspendTenant: (id: string): Promise<ApiResponse<Tenant>> => {
|
|
return request.post(`/config/tenants/${id}/suspend`)
|
|
},
|
|
|
|
activateTenant: (id: string): Promise<ApiResponse<Tenant>> => {
|
|
return request.post(`/config/tenants/${id}/activate`)
|
|
},
|
|
|
|
// 用户管理
|
|
getUserList: (params: QueryRequest): Promise<ApiResponse<PaginatedResponse<User>>> => {
|
|
return request.get('/config/users', params)
|
|
},
|
|
|
|
getUserDetail: (id: string): Promise<ApiResponse<User>> => {
|
|
return request.get(`/config/users/${id}`)
|
|
},
|
|
|
|
createUser: (data: Omit<User, 'id' | 'createdAt' | 'updatedAt' | 'lastLoginAt'>): Promise<ApiResponse<User>> => {
|
|
return request.post('/config/users', data)
|
|
},
|
|
|
|
updateUser: (id: string, data: Partial<User>): Promise<ApiResponse<User>> => {
|
|
return request.put(`/config/users/${id}`, data)
|
|
},
|
|
|
|
deleteUser: (id: string): Promise<ApiResponse<void>> => {
|
|
return request.delete(`/config/users/${id}`)
|
|
},
|
|
|
|
resetPassword: (id: string, newPassword: string): Promise<ApiResponse<void>> => {
|
|
return request.post(`/config/users/${id}/reset-password`, { newPassword })
|
|
},
|
|
|
|
lockUser: (id: string): Promise<ApiResponse<User>> => {
|
|
return request.post(`/config/users/${id}/lock`)
|
|
},
|
|
|
|
unlockUser: (id: string): Promise<ApiResponse<User>> => {
|
|
return request.post(`/config/users/${id}/unlock`)
|
|
},
|
|
|
|
// 系统参数
|
|
getParameterList: (params: QueryRequest): Promise<ApiResponse<PaginatedResponse<SystemParameter>>> => {
|
|
return request.get('/config/parameters', params)
|
|
},
|
|
|
|
getParameterDetail: (id: string): Promise<ApiResponse<SystemParameter>> => {
|
|
return request.get(`/config/parameters/${id}`)
|
|
},
|
|
|
|
createParameter: (data: Omit<SystemParameter, 'id' | 'createdAt' | 'updatedAt'>): Promise<ApiResponse<SystemParameter>> => {
|
|
return request.post('/config/parameters', data)
|
|
},
|
|
|
|
updateParameter: (id: string, data: Partial<SystemParameter>): Promise<ApiResponse<SystemParameter>> => {
|
|
return request.put(`/config/parameters/${id}`, data)
|
|
},
|
|
|
|
deleteParameter: (id: string): Promise<ApiResponse<void>> => {
|
|
return request.delete(`/config/parameters/${id}`)
|
|
},
|
|
|
|
getParametersByCategory: (category: string): Promise<ApiResponse<SystemParameter[]>> => {
|
|
return request.get(`/config/parameters/category/${category}`)
|
|
},
|
|
|
|
// 系统监控
|
|
getSystemLogs: (params: QueryRequest & { level?: string; category?: string }): Promise<ApiResponse<PaginatedResponse<SystemLog>>> => {
|
|
return request.get('/config/logs', params)
|
|
},
|
|
|
|
getSystemMetrics: (): Promise<ApiResponse<{
|
|
totalUsers: number
|
|
activeUsers: number
|
|
totalTenants: number
|
|
activeTenants: number
|
|
systemUptime: number
|
|
cpuUsage: number
|
|
memoryUsage: number
|
|
diskUsage: number
|
|
databaseConnections: number
|
|
}>> => {
|
|
return request.get('/config/metrics')
|
|
},
|
|
|
|
getSystemHealth: (): Promise<ApiResponse<{
|
|
status: 'healthy' | 'warning' | 'critical'
|
|
services: Array<{
|
|
name: string
|
|
status: 'up' | 'down'
|
|
responseTime: number
|
|
lastCheck: string
|
|
}>
|
|
issues: Array<{
|
|
type: 'error' | 'warning'
|
|
message: string
|
|
timestamp: string
|
|
}>
|
|
}>> => {
|
|
return request.get('/config/health')
|
|
},
|
|
|
|
// 消息中心
|
|
getMessageList: (params: QueryRequest): Promise<ApiResponse<PaginatedResponse<Message>>> => {
|
|
return request.get('/config/messages', params)
|
|
},
|
|
|
|
getMessageDetail: (id: string): Promise<ApiResponse<Message>> => {
|
|
return request.get(`/config/messages/${id}`)
|
|
},
|
|
|
|
createMessage: (data: Omit<Message, 'id' | 'createdAt' | 'readAt' | 'status'>): Promise<ApiResponse<Message>> => {
|
|
return request.post('/config/messages', data)
|
|
},
|
|
|
|
markMessageAsRead: (id: string): Promise<ApiResponse<Message>> => {
|
|
return request.put(`/config/messages/${id}/read`)
|
|
},
|
|
|
|
archiveMessage: (id: string): Promise<ApiResponse<Message>> => {
|
|
return request.put(`/config/messages/${id}/archive`)
|
|
},
|
|
|
|
deleteMessage: (id: string): Promise<ApiResponse<void>> => {
|
|
return request.delete(`/config/messages/${id}`)
|
|
},
|
|
|
|
getUnreadCount: (): Promise<ApiResponse<{ count: number }>> => {
|
|
return request.get('/config/messages/unread/count')
|
|
}
|
|
} |