/** * API接口封装 * 统一管理所有API接口 */ import httpService from './http.js' // 数据历史接口 export const dataHistoryApi = { // 获取历史数据 getHistory(params) { return httpService.post('/api/data/history', params) } } // 设备相关接口 export const deviceApi = { // 获取设备详情 getDetail(deviceId) { return httpService.get(`/api/devices/${deviceId}`) }, // 获取设备列表 getList(params = {}) { return httpService.get('/api/devices', params) }, // 更新设备状态 updateStatus(deviceId, status) { return httpService.put(`/api/devices/${deviceId}/status`, { status }) } } // 环境参数接口 export const environmentApi = { // 获取环境参数 getParams(params = {}) { return httpService.get('/api/environment/params', params) }, // 获取环境参数历史 getHistory(params) { return httpService.post('/api/environment/history', params) } } // 报警相关接口 export const alarmApi = { // 获取报警记录 getRecords(params = {}) { return httpService.get('/api/alarms', params) }, // 获取报警统计 getStatistics(params = {}) { return httpService.get('/api/alarms/statistics', params) }, // 处理报警 handleAlarm(alarmId, action) { return httpService.put(`/api/alarms/${alarmId}/handle`, { action }) } } // 系统日志接口 export const logApi = { // 获取系统日志 getLogs(params = {}) { return httpService.get('/api/logs', params) }, // 获取日志统计 getStatistics(params = {}) { return httpService.get('/api/logs/statistics', params) } } // 用户相关接口 export const userApi = { // 用户登录 login(credentials) { return httpService.post('/api/auth/login', credentials) }, // 用户登出 logout() { return httpService.post('/api/auth/logout') }, // 获取用户信息 getUserInfo() { return httpService.get('/api/user/info') }, // 更新用户信息 updateUserInfo(userInfo) { return httpService.put('/api/user/info', userInfo) } } // 温湿度数据接口 export const thDataApi = { // 获取最新空调温度 getLatest() { return httpService.get('/api/th/data/latest') }, // 提交温湿度数据 submit(data) { return httpService.post('/api/th/data', data) } } // 告警相关接口 export const alertApi = { // 创建告警 create(data) { return httpService.post('/api/alerts', data) }, // 分页获取告警 getList(params = {}) { return httpService.get('/api/alerts', params) } } // 事件相关接口 export const eventApi = { // 创建事件 create(data) { return httpService.post('/api/events', data) }, // 分页获取事件 getList(params = {}) { return httpService.get('/api/events', params) } } // 导出所有API export default { dataHistory: dataHistoryApi, device: deviceApi, environment: environmentApi, alarm: alarmApi, log: logApi, user: userApi, thData: thDataApi, alert: alertApi, event: eventApi }