Files
pig-farm-controller-fe/src/api/user.js

127 lines
2.9 KiB
JavaScript
Raw Normal View History

2025-10-19 21:38:04 +08:00
import http from '../utils/http';
2025-09-19 14:34:51 +08:00
2025-10-23 15:17:31 +08:00
/**
* @typedef {object} CreateUserRequest
* @property {string} username
* @property {string} password
*/
/**
* @typedef {object} CreateUserResponse
* @property {number} id
* @property {string} username
*/
/**
* @typedef {object} LoginRequest
* @property {string} identifier - Identifier 可以是用户名邮箱手机号微信号或飞书账号
* @property {string} password
*/
/**
* @typedef {object} LoginResponse
* @property {number} id
* @property {string} username
* @property {string} token
*/
/**
* @typedef {('成功'|'失败')} AuditStatus
*/
/**
* @typedef {object} UserActionLogDTO
* @property {number} id
* @property {number} user_id
* @property {string} username
* @property {string} action_type
* @property {string} description
* @property {string} http_method
* @property {string} http_path
* @property {string} source_ip
* @property {Array<number>} target_resource
* @property {AuditStatus} status
* @property {string} result_details
* @property {string} time
*/
/**
* @typedef {object} PaginationDTO
* @property {number} page
* @property {number} pageSize
* @property {number} total
*/
/**
* @typedef {object} ListUserActionLogResponse
* @property {Array<UserActionLogDTO>} list
* @property {PaginationDTO} pagination
*/
/**
* @typedef {object} UserHistoryParams
* @property {string} [action_type]
* @property {string} [end_time]
* @property {string} [order_by]
* @property {number} [page]
* @property {number} [pageSize]
* @property {string} [start_time]
* @property {string} [status]
* @property {number} [user_id]
* @property {string} [username]
*/
2025-10-25 15:27:27 +08:00
/**
* @typedef {('邮件'|'企业微信'|'飞书'|'日志')} NotifierType
*/
/**
* @typedef {object} SendTestNotificationRequest
* @property {NotifierType} type - Type 指定要测试的通知渠道
*/
2025-09-19 14:34:51 +08:00
/**
2025-10-19 21:38:04 +08:00
* 创建一个新用户
2025-10-23 15:17:31 +08:00
* @param {CreateUserRequest} userData - 用户信息
* @returns {Promise<CreateUserResponse>}
2025-09-19 14:34:51 +08:00
*/
2025-10-20 14:52:25 +08:00
const createUser = (userData) => {
2025-10-19 21:38:04 +08:00
return http.post('/api/v1/users', userData);
};
2025-09-19 14:34:51 +08:00
2025-10-19 21:38:04 +08:00
/**
* 用户登录
2025-10-23 15:17:31 +08:00
* @param {LoginRequest} credentials - 登录凭证
* @returns {Promise<LoginResponse>}
2025-10-19 21:38:04 +08:00
*/
2025-10-20 14:52:25 +08:00
const login = (credentials) => {
2025-10-19 21:38:04 +08:00
return http.post('/api/v1/users/login', credentials);
};
2025-09-19 14:34:51 +08:00
2025-10-19 21:38:04 +08:00
/**
* 获取指定用户的操作历史
* @param {number} id - 用户ID
2025-10-23 15:17:31 +08:00
* @param {UserHistoryParams} params - 查询参数
* @returns {Promise<ListUserActionLogResponse>}
2025-10-19 21:38:04 +08:00
*/
2025-10-20 14:52:25 +08:00
const getUserHistory = (id, params) => {
2025-10-19 21:38:04 +08:00
return http.get(`/api/v1/users/${id}/history`, { params });
};
2025-10-20 14:52:25 +08:00
2025-10-25 15:27:27 +08:00
/**
* 发送测试通知
* @param {number} id - 用户ID
* @param {SendTestNotificationRequest} data - 请求体
* @returns {Promise<string>}
*/
const sendTestNotification = (id, data) => {
return http.post(`/api/v1/users/${id}/notifications/test`, data);
};
2025-10-20 14:52:25 +08:00
export const UserApi = {
createUser,
login,
getUserHistory,
2025-10-25 15:27:27 +08:00
sendTestNotification,
2025-10-20 14:52:25 +08:00
};