Files
YG_FT/frontend/src/api/modules/system.ts

52 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { del, get, post, put } from '../request'
import type {
CreateUserPayload,
HealthMetrics,
LoginResponse,
SystemInfo,
SystemUser,
UpdateUserAccessPayload,
} from '@/types'
export type { SystemUser } from '@/types'
/** 系统信息CPU/内存/磁盘/GPU/网络/系统) */
export const getSystemInfo = () => get<SystemInfo>('/system-info')
/** 健康指标(顶部栏轻量指标) */
export const getHealth = () => get<HealthMetrics>('/health')
/** 登录 */
export const login = (username: string, password: string) =>
post<LoginResponse>('/login', { username, password })
/** 登出 */
export const logout = (sessionId?: string) =>
post('/logout', { session_id: sessionId || '' })
/** 用户列表 */
export const getUsers = () => get<SystemUser[]>('/users')
/** 创建用户 */
export const createUser = (payload: CreateUserPayload) =>
post<SystemUser>('/users', payload)
/** 更新用户角色、状态及页面权限 */
export const updateUserAccess = (id: string, payload: UpdateUserAccessPayload) =>
put<SystemUser>(`/users/${encodeURIComponent(id)}`, payload)
/** 重置用户密码 */
export const resetUserPassword = (id: string, password?: string) =>
post<{ reset: string }>(`/users/${encodeURIComponent(id)}/reset-password`, { password })
/** 删除用户protected 管理员账号不允许删除) */
export const deleteUser = (id: string) =>
del<{ deleted: string }>(`/users/${encodeURIComponent(id)}`)
/** 用户自行修改密码 */
export const changeMyPassword = (oldPassword: string, newPassword: string) =>
post<{ changed: boolean }>('/users/me/password', {
old_password: oldPassword,
new_password: newPassword,
})