From c4905113d796ef99689b9c934750cf2a54ab25ca Mon Sep 17 00:00:00 2001 From: zyh Date: Thu, 10 Apr 2025 06:38:59 +0000 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=A7=BB=E5=8A=A8=E7=AB=AFAP?= =?UTF-8?q?I=E5=92=8C=E7=BB=84=E4=BB=B6=E4=B8=AD=E7=9A=84=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BB=A3=E7=A0=81=EF=BC=8C=E7=AE=80=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AE=A4=E8=AF=81=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=B8=AA=E4=BA=BA=E9=A1=B5=E9=9D=A2=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=BC=BA=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?= =?UTF-8?q?=E5=92=8C=E4=BB=A3=E7=A0=81=E5=8F=AF=E7=BB=B4=E6=8A=A4=E6=80=A7?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/admin/api.ts | 1133 --------------------------------- client/mobile/api.ts | 1139 ---------------------------------- client/mobile/hooks.tsx | 45 +- client/mobile/mobile_app.tsx | 98 +-- 4 files changed, 65 insertions(+), 2350 deletions(-) diff --git a/client/admin/api.ts b/client/admin/api.ts index ddf4f78..b2aa65f 100644 --- a/client/admin/api.ts +++ b/client/admin/api.ts @@ -218,1035 +218,6 @@ export const UserAPI = { } }; -// 资产管理API -export const ZichanAPI = { - // 获取资产列表 - getZichanList: async (params?: { - page?: number, - limit?: number, - asset_name?: string, - device_category?: DeviceCategory, - device_status?: DeviceStatus - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个资产 - getZichan: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建资产 - createZichan: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/zichan`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新资产 - updateZichan: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/zichan/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除资产 - deleteZichan: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/zichan/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - - - -// 资产流转API接口定义 -export const ZichanTransferAPI = { - // 获取资产流转记录列表 - getTransferList: async (params?: { page?: number, limit?: number, asset_id?: number, asset_transfer?: AssetTransferType }) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-transfer`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取资产流转记录详情 - getTransfer: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-transfer/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建资产流转记录 - createTransfer: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/zichan-transfer`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新资产流转记录 - updateTransfer: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/zichan-transfer/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除资产流转记录 - deleteTransfer: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/zichan-transfer/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 设备实例API接口定义 -interface DeviceInstancesResponse { - data: DeviceInstance[]; - pagination: { - total: number; - current: number; - pageSize: number; - totalPages: number; - }; -} - -interface DeviceInstanceResponse { - data: DeviceInstance; - asset_info?: ZichanInfo; - type_info?: DeviceType; - message?: string; -} - -interface DeviceInstanceCreateResponse { - message: string; - data: DeviceInstance; -} - -interface DeviceInstanceUpdateResponse { - message: string; - data: DeviceInstance; -} - -interface DeviceInstanceDeleteResponse { - message: string; - id: number; -} - -// 设备类型API接口定义 -interface DeviceTypeResponse { - data: DeviceType[]; - pagination: { - total: number; - current: number; - pageSize: number; - totalPages: number; - }; -} - -interface DeviceTypeDetailResponse { - data: DeviceType; - message?: string; -} - -interface DeviceTypeCreateResponse { - message: string; - data: DeviceType; -} - -interface DeviceTypeUpdateResponse { - message: string; - data: DeviceType; -} - -interface DeviceTypeDeleteResponse { - message: string; - id: number; -} - -export const DeviceTypeAPI = { - // 获取设备类型列表 - getDeviceTypes: async (params?: { - page?: number, - pageSize?: number, - code?: string, - name?: string, - is_enabled?: boolean - }): Promise => { - try { - const response = await axios.get('/api/device/types', { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个设备类型信息 - getDeviceType: async (id: number): Promise => { - try { - const response = await axios.get(`/api/device/types/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建设备类型 - createDeviceType: async (data: Partial): Promise => { - try { - const response = await axios.post('/api/device/types', data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新设备类型 - updateDeviceType: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`/api/device/types/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除设备类型 - deleteDeviceType: async (id: number): Promise => { - try { - const response = await axios.delete(`/api/device/types/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取设备类型图标 - getTypeIcons: async (): Promise<{data: Record, success: boolean}> => { - try { - const response = await axios.get('/api/device/types/icons'); - return response.data; - } catch (error) { - throw error; - } - } -}; - -export const DeviceInstanceAPI = { - // 获取设备实例列表 - getDeviceInstances: async (params?: { - page?: number, - limit?: number, - type_id?: number, - protocol?: string, - status?: number - }): Promise => { - try { - const response = await axios.get('/api/device/instances', { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个设备实例信息 - getDeviceInstance: async (id: number): Promise => { - try { - const response = await axios.get(`/api/device/instances/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建设备实例 - createDeviceInstance: async (data: Partial): Promise => { - try { - const response = await axios.post('/api/device/instances', data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新设备实例 - updateDeviceInstance: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`/api/device/instances/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除设备实例 - deleteDeviceInstance: async (id: number): Promise => { - try { - const response = await axios.delete(`/api/device/instances/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 机柜管理API接口定义 -export const RackAPI = { - // 获取机柜列表 - getRackList: async (params?: { - page?: number, - limit?: number, - rack_name?: string, - rack_code?: string, - area?: string - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/racks`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个机柜信息 - getRack: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/racks/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建机柜 - createRack: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/racks`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新机柜 - updateRack: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/racks/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除机柜 - deleteRack: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/racks/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 机柜服务器API接口定义 -export const RackServerAPI = { - // 获取机柜服务器列表 - getRackServerList: async (params?: { - page?: number, - limit?: number, - rack_id?: number, - asset_id?: number, - server_type?: string - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/rack-servers`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个机柜服务器信息 - getRackServer: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/rack-servers/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建机柜服务器 - createRackServer: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/rack-servers`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新机柜服务器 - updateRackServer: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/rack-servers/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除机柜服务器 - deleteRackServer: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/rack-servers/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -interface DeviceMonitorDataResponse { - data: DeviceMonitorData[]; - total: number; - page: number; - pageSize: number; -} - -interface DeviceMonitorResponse { - data: DeviceMonitorData; - message?: string; -} - -interface MonitorCreateResponse { - data: DeviceMonitorData; - message: string; -} - -interface MonitorUpdateResponse { - data: DeviceMonitorData; - message: string; -} - -interface MonitorDeleteResponse { - message: string; -} - -// 告警相关响应类型 -interface DeviceAlertDataResponse { - data: DeviceAlert[]; - total: number; - page: number; - pageSize: number; -} - -interface DeviceAlertResponse { - data: DeviceAlert; - message?: string; -} - -interface AlertCreateResponse { - data: DeviceAlert; - message: string; -} - -interface AlertUpdateResponse { - data: DeviceAlert; - message: string; -} - -interface AlertDeleteResponse { - message: string; -} - -// 告警处理相关响应类型 -interface AlertHandleDataResponse { - data: AlertHandleLog[]; - total: number; - page: number; - pageSize: number; -} - -interface AlertHandleResponse { - data: AlertHandleLog; - message?: string; -} - -// 告警通知配置相关响应类型 -interface AlertNotifyConfigDataResponse { - data: AlertNotifyConfig[]; - total: number; - page: number; - pageSize: number; -} - -interface AlertNotifyConfigResponse { - data: AlertNotifyConfig; - message?: string; -} - -// 监控API接口定义 -export const MonitorAPI = { - // 获取监控数据 - getMonitorData: async (params?: { - page?: number, - limit?: number, - device_id?: number, - device_type?: string, - start_time?: string, - end_time?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/data`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取设备树数据 - getDeviceTree: async (params?: { - status?: string, - keyword?: string - }): Promise<{ data: DeviceTreeNode[] }> => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/devices/tree`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取设备树统计数据 - getDeviceTreeStats: async (): Promise<{ data: DeviceTreeStats }> => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/devices/tree/statistics`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取设备地图数据 - getDeviceMapData: async (params?: { - type_code?: string, - device_status?: DeviceStatus, - keyword?: string, - device_id?: number - }): Promise<{ data: MapViewDevice[], stats: DeviceMapStats }> => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/devices/map`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个监控数据 - getMonitor: async (id: number): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/data/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建监控数据 - createMonitor: async (data: Partial): Promise => { - try { - const response = await axios.post(`${API_BASE_URL}/monitor/data`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新监控数据 - updateMonitor: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`${API_BASE_URL}/monitor/data/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除监控数据 - deleteMonitor: async (id: number): Promise => { - try { - const response = await axios.delete(`${API_BASE_URL}/monitor/data/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 告警API接口定义 -export const AlertAPI = { - // 获取告警数据 - getAlertData: async (params?: { - page?: number, - limit?: number, - alert_type?: string, - alert_level?: string, - start_time?: string, - end_time?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alerts`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个告警数据 - getAlert: async (id: number): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alerts/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建告警数据 - createAlert: async (data: Partial): Promise => { - try { - const response = await axios.post(`${API_BASE_URL}/alerts`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新告警数据 - updateAlert: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`${API_BASE_URL}/alerts/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除告警数据 - deleteAlert: async (id: number): Promise => { - try { - const response = await axios.delete(`${API_BASE_URL}/alerts/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 告警处理API接口定义 -export const AlertHandleAPI = { - // 获取告警处理数据 - getAlertHandleData: async (params?: { - page?: number, - limit?: number, - alert_id?: number, - handle_type?: string, - start_time?: string, - end_time?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alert-handles`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个告警处理数据 - getAlertHandle: async (id: number): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alert-handles/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建告警处理数据 - createAlertHandle: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/alert-handles`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新告警处理数据 - updateAlertHandle: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/alert-handles/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除告警处理数据 - deleteAlertHandle: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/alert-handles/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 告警通知配置API接口定义 -export const AlertNotifyConfigAPI = { - // 获取告警通知配置 - getAlertNotifyConfig: async (params?: { - page?: number, - limit?: number, - device_id?: number, - alert_level?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alert-notify-configs`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建告警通知配置 - createAlertNotifyConfig: async (data: Partial): Promise => { - try { - const response = await axios.post(`${API_BASE_URL}/alert-notify-configs`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新告警通知配置 - updateAlertNotifyConfig: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`${API_BASE_URL}/alert-notify-configs/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除告警通知配置 - deleteAlertNotifyConfig: async (id: number): Promise => { - try { - const response = await axios.delete(`${API_BASE_URL}/alert-notify-configs/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 设备告警规则API接口定义 -export const DeviceAlertRuleAPI = { - // 获取设备告警规则 - getDeviceAlertRules: async (params?: { - page?: number, - limit?: number, - device_id?: number, - rule_type?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/device-alert-rules`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个设备告警规则 - getDeviceAlertRule: async (id: number): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/device-alert-rules/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建设备告警规则 - createDeviceAlertRule: async (data: Partial): Promise => { - try { - const response = await axios.post(`${API_BASE_URL}/device-alert-rules`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新设备告警规则 - updateDeviceAlertRule: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`${API_BASE_URL}/device-alert-rules/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除设备告警规则 - deleteDeviceAlertRule: async (id: number): Promise => { - try { - const response = await axios.delete(`${API_BASE_URL}/device-alert-rules/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - - -// 资产分类API响应类型 -interface ZichanCategoryResponse { - data: ZichanCategory[]; - pagination: { - total: number; - current: number; - pageSize: number; - }; -} - -// 资产归属区域API响应类型 -interface ZichanAreaResponse { - data: ZichanArea[]; - pagination: { - total: number; - current: number; - pageSize: number; - }; -} - -// 机柜服务器类型API响应类型 -interface RackServerTypeResponse { - data: RackServerType[]; - pagination: { - total: number; - current: number; - pageSize: number; - }; -} - -// 资产分类API接口定义 -export const ZichanCategoryAPI = { - // 获取资产分类列表 - getZichanCategoryList: async (params?: { - page?: number, - limit?: number, - name?: string, - code?: string - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-categories`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个资产分类信息 - getZichanCategory: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-categories/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建资产分类 - createZichanCategory: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/zichan-categories`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新资产分类 - updateZichanCategory: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/zichan-categories/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除资产分类 - deleteZichanCategory: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/zichan-categories/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 资产归属区域API接口定义 -export const ZichanAreaAPI = { - // 获取资产归属区域列表 - getZichanAreaList: async (params?: { - page?: number, - limit?: number, - name?: string, - code?: string - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-areas`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个资产归属区域信息 - getZichanArea: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-areas/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建资产归属区域 - createZichanArea: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/zichan-areas`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新资产归属区域 - updateZichanArea: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/zichan-areas/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除资产归属区域 - deleteZichanArea: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/zichan-areas/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 机柜服务器类型API接口定义 -export const RackServerTypeAPI = { - // 获取机柜服务器类型列表 - getRackServerTypeList: async (params?: { - page?: number, - limit?: number, - name?: string, - code?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/rack-server-types`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个机柜服务器类型信息 - getRackServerType: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/rack-server-types/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建机柜服务器类型 - createRackServerType: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/rack-server-types`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新机柜服务器类型 - updateRackServerType: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/rack-server-types/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除机柜服务器类型 - deleteRackServerType: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/rack-server-types/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; // 定义文件相关接口类型 interface FileUploadPolicyResponse { @@ -1417,104 +388,6 @@ export const FileAPI = { } }; -// // 添加图表类型定义(从大屏移植) -// interface CategoryChartData { -// 设备分类: string; -// 设备数: number; -// } - -// interface CategoryChartDataWithPercent extends CategoryChartData { -// 百分比: string; -// } - -// interface OnlineRateChartData { -// time_interval: string; -// online_devices: number; -// total_devices: number; -// } - -// interface StateChartData { -// 资产流转: string; -// 设备数: number; -// } - -// interface StateChartDataWithPercent extends StateChartData { -// 百分比: string; -// } - -// interface AlarmChartData { -// time_interval: string; -// total_devices: number; -// } - -// 统一图表数据查询函数 -export const chartQueryFns = { - // 资产分类数据查询 - fetchCategoryData: async (): Promise => { - const res = await axios.get(`${API_BASE_URL}/big/zichan_category_chart`); - - // 预先计算百分比 - const data = res.data; - const total = data.reduce((sum: number, item: CategoryChartData) => sum + item['设备数'], 0); - - // 为每个数据项添加百分比字段 - return data.map(item => ({ - ...item, - 百分比: total > 0 ? (item['设备数'] / total * 100).toFixed(1) : '0' - })); - }, - - // 在线率变化数据查询 - fetchOnlineRateData: async (params?: { - created_at_gte?: string; - created_at_lte?: string; - dimension?: string; - }): Promise => { - // 可选参数 - // const params = { - // created_at_gte: dayjs().subtract(7, 'day').format('YYYY-MM-DD HH:mm:ss'), - // created_at_lte: dayjs().format('YYYY-MM-DD HH:mm:ss'), - // dimension: 'day' - // }; - - const res = await axios.get(`${API_BASE_URL}/big/zichan_online_rate_chart`, { params }); - return res.data; - }, - - // 资产流转状态数据查询 - fetchStateData: async (): Promise => { - const res = await axios.get(`${API_BASE_URL}/big/zichan_state_chart`); - - // 预先计算百分比 - const data = res.data; - const total = data.reduce((sum: number, item: StateChartData) => sum + item['设备数'], 0); - - // 为每个数据项添加百分比字段 - return data.map(item => ({ - ...item, - 百分比: total > 0 ? (item['设备数'] / total * 100).toFixed(1) : '0' - })); - }, - - // 告警数据变化查询 - fetchAlarmData: async (params?: { - created_at_gte?: string; - created_at_lte?: string; - dimension?: string; - }): Promise => { - // 可选参数 - // const params = { - // created_at_gte: dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'), - // created_at_lte: dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss'), - // dimension: 'hour' - // }; - - - const res = await axios.get(`${API_BASE_URL}/big/zichan_alarm_chart`, { params }); - return res.data; - } -}; - // Theme API 响应类型 export interface ThemeSettingsResponse { message: string; @@ -1683,12 +556,6 @@ export const MapAPI = { } }; -// 系统设置API响应类型 -interface SystemSettingsResponse { - message: string; - data: SystemSetting[]; -} - // 系统设置API export const SystemAPI = { // 获取所有系统设置 diff --git a/client/mobile/api.ts b/client/mobile/api.ts index ddf4f78..08dee14 100644 --- a/client/mobile/api.ts +++ b/client/mobile/api.ts @@ -218,1036 +218,6 @@ export const UserAPI = { } }; -// 资产管理API -export const ZichanAPI = { - // 获取资产列表 - getZichanList: async (params?: { - page?: number, - limit?: number, - asset_name?: string, - device_category?: DeviceCategory, - device_status?: DeviceStatus - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个资产 - getZichan: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建资产 - createZichan: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/zichan`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新资产 - updateZichan: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/zichan/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除资产 - deleteZichan: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/zichan/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - - - -// 资产流转API接口定义 -export const ZichanTransferAPI = { - // 获取资产流转记录列表 - getTransferList: async (params?: { page?: number, limit?: number, asset_id?: number, asset_transfer?: AssetTransferType }) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-transfer`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取资产流转记录详情 - getTransfer: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-transfer/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建资产流转记录 - createTransfer: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/zichan-transfer`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新资产流转记录 - updateTransfer: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/zichan-transfer/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除资产流转记录 - deleteTransfer: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/zichan-transfer/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 设备实例API接口定义 -interface DeviceInstancesResponse { - data: DeviceInstance[]; - pagination: { - total: number; - current: number; - pageSize: number; - totalPages: number; - }; -} - -interface DeviceInstanceResponse { - data: DeviceInstance; - asset_info?: ZichanInfo; - type_info?: DeviceType; - message?: string; -} - -interface DeviceInstanceCreateResponse { - message: string; - data: DeviceInstance; -} - -interface DeviceInstanceUpdateResponse { - message: string; - data: DeviceInstance; -} - -interface DeviceInstanceDeleteResponse { - message: string; - id: number; -} - -// 设备类型API接口定义 -interface DeviceTypeResponse { - data: DeviceType[]; - pagination: { - total: number; - current: number; - pageSize: number; - totalPages: number; - }; -} - -interface DeviceTypeDetailResponse { - data: DeviceType; - message?: string; -} - -interface DeviceTypeCreateResponse { - message: string; - data: DeviceType; -} - -interface DeviceTypeUpdateResponse { - message: string; - data: DeviceType; -} - -interface DeviceTypeDeleteResponse { - message: string; - id: number; -} - -export const DeviceTypeAPI = { - // 获取设备类型列表 - getDeviceTypes: async (params?: { - page?: number, - pageSize?: number, - code?: string, - name?: string, - is_enabled?: boolean - }): Promise => { - try { - const response = await axios.get('/api/device/types', { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个设备类型信息 - getDeviceType: async (id: number): Promise => { - try { - const response = await axios.get(`/api/device/types/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建设备类型 - createDeviceType: async (data: Partial): Promise => { - try { - const response = await axios.post('/api/device/types', data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新设备类型 - updateDeviceType: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`/api/device/types/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除设备类型 - deleteDeviceType: async (id: number): Promise => { - try { - const response = await axios.delete(`/api/device/types/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取设备类型图标 - getTypeIcons: async (): Promise<{data: Record, success: boolean}> => { - try { - const response = await axios.get('/api/device/types/icons'); - return response.data; - } catch (error) { - throw error; - } - } -}; - -export const DeviceInstanceAPI = { - // 获取设备实例列表 - getDeviceInstances: async (params?: { - page?: number, - limit?: number, - type_id?: number, - protocol?: string, - status?: number - }): Promise => { - try { - const response = await axios.get('/api/device/instances', { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个设备实例信息 - getDeviceInstance: async (id: number): Promise => { - try { - const response = await axios.get(`/api/device/instances/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建设备实例 - createDeviceInstance: async (data: Partial): Promise => { - try { - const response = await axios.post('/api/device/instances', data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新设备实例 - updateDeviceInstance: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`/api/device/instances/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除设备实例 - deleteDeviceInstance: async (id: number): Promise => { - try { - const response = await axios.delete(`/api/device/instances/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 机柜管理API接口定义 -export const RackAPI = { - // 获取机柜列表 - getRackList: async (params?: { - page?: number, - limit?: number, - rack_name?: string, - rack_code?: string, - area?: string - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/racks`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个机柜信息 - getRack: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/racks/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建机柜 - createRack: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/racks`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新机柜 - updateRack: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/racks/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除机柜 - deleteRack: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/racks/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 机柜服务器API接口定义 -export const RackServerAPI = { - // 获取机柜服务器列表 - getRackServerList: async (params?: { - page?: number, - limit?: number, - rack_id?: number, - asset_id?: number, - server_type?: string - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/rack-servers`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个机柜服务器信息 - getRackServer: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/rack-servers/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建机柜服务器 - createRackServer: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/rack-servers`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新机柜服务器 - updateRackServer: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/rack-servers/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除机柜服务器 - deleteRackServer: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/rack-servers/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -interface DeviceMonitorDataResponse { - data: DeviceMonitorData[]; - total: number; - page: number; - pageSize: number; -} - -interface DeviceMonitorResponse { - data: DeviceMonitorData; - message?: string; -} - -interface MonitorCreateResponse { - data: DeviceMonitorData; - message: string; -} - -interface MonitorUpdateResponse { - data: DeviceMonitorData; - message: string; -} - -interface MonitorDeleteResponse { - message: string; -} - -// 告警相关响应类型 -interface DeviceAlertDataResponse { - data: DeviceAlert[]; - total: number; - page: number; - pageSize: number; -} - -interface DeviceAlertResponse { - data: DeviceAlert; - message?: string; -} - -interface AlertCreateResponse { - data: DeviceAlert; - message: string; -} - -interface AlertUpdateResponse { - data: DeviceAlert; - message: string; -} - -interface AlertDeleteResponse { - message: string; -} - -// 告警处理相关响应类型 -interface AlertHandleDataResponse { - data: AlertHandleLog[]; - total: number; - page: number; - pageSize: number; -} - -interface AlertHandleResponse { - data: AlertHandleLog; - message?: string; -} - -// 告警通知配置相关响应类型 -interface AlertNotifyConfigDataResponse { - data: AlertNotifyConfig[]; - total: number; - page: number; - pageSize: number; -} - -interface AlertNotifyConfigResponse { - data: AlertNotifyConfig; - message?: string; -} - -// 监控API接口定义 -export const MonitorAPI = { - // 获取监控数据 - getMonitorData: async (params?: { - page?: number, - limit?: number, - device_id?: number, - device_type?: string, - start_time?: string, - end_time?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/data`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取设备树数据 - getDeviceTree: async (params?: { - status?: string, - keyword?: string - }): Promise<{ data: DeviceTreeNode[] }> => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/devices/tree`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取设备树统计数据 - getDeviceTreeStats: async (): Promise<{ data: DeviceTreeStats }> => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/devices/tree/statistics`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取设备地图数据 - getDeviceMapData: async (params?: { - type_code?: string, - device_status?: DeviceStatus, - keyword?: string, - device_id?: number - }): Promise<{ data: MapViewDevice[], stats: DeviceMapStats }> => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/devices/map`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个监控数据 - getMonitor: async (id: number): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/monitor/data/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建监控数据 - createMonitor: async (data: Partial): Promise => { - try { - const response = await axios.post(`${API_BASE_URL}/monitor/data`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新监控数据 - updateMonitor: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`${API_BASE_URL}/monitor/data/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除监控数据 - deleteMonitor: async (id: number): Promise => { - try { - const response = await axios.delete(`${API_BASE_URL}/monitor/data/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 告警API接口定义 -export const AlertAPI = { - // 获取告警数据 - getAlertData: async (params?: { - page?: number, - limit?: number, - alert_type?: string, - alert_level?: string, - start_time?: string, - end_time?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alerts`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个告警数据 - getAlert: async (id: number): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alerts/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建告警数据 - createAlert: async (data: Partial): Promise => { - try { - const response = await axios.post(`${API_BASE_URL}/alerts`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新告警数据 - updateAlert: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`${API_BASE_URL}/alerts/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除告警数据 - deleteAlert: async (id: number): Promise => { - try { - const response = await axios.delete(`${API_BASE_URL}/alerts/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 告警处理API接口定义 -export const AlertHandleAPI = { - // 获取告警处理数据 - getAlertHandleData: async (params?: { - page?: number, - limit?: number, - alert_id?: number, - handle_type?: string, - start_time?: string, - end_time?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alert-handles`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个告警处理数据 - getAlertHandle: async (id: number): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alert-handles/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建告警处理数据 - createAlertHandle: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/alert-handles`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新告警处理数据 - updateAlertHandle: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/alert-handles/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除告警处理数据 - deleteAlertHandle: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/alert-handles/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 告警通知配置API接口定义 -export const AlertNotifyConfigAPI = { - // 获取告警通知配置 - getAlertNotifyConfig: async (params?: { - page?: number, - limit?: number, - device_id?: number, - alert_level?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/alert-notify-configs`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建告警通知配置 - createAlertNotifyConfig: async (data: Partial): Promise => { - try { - const response = await axios.post(`${API_BASE_URL}/alert-notify-configs`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新告警通知配置 - updateAlertNotifyConfig: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`${API_BASE_URL}/alert-notify-configs/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除告警通知配置 - deleteAlertNotifyConfig: async (id: number): Promise => { - try { - const response = await axios.delete(`${API_BASE_URL}/alert-notify-configs/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 设备告警规则API接口定义 -export const DeviceAlertRuleAPI = { - // 获取设备告警规则 - getDeviceAlertRules: async (params?: { - page?: number, - limit?: number, - device_id?: number, - rule_type?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/device-alert-rules`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个设备告警规则 - getDeviceAlertRule: async (id: number): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/device-alert-rules/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建设备告警规则 - createDeviceAlertRule: async (data: Partial): Promise => { - try { - const response = await axios.post(`${API_BASE_URL}/device-alert-rules`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新设备告警规则 - updateDeviceAlertRule: async (id: number, data: Partial): Promise => { - try { - const response = await axios.put(`${API_BASE_URL}/device-alert-rules/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除设备告警规则 - deleteDeviceAlertRule: async (id: number): Promise => { - try { - const response = await axios.delete(`${API_BASE_URL}/device-alert-rules/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - - -// 资产分类API响应类型 -interface ZichanCategoryResponse { - data: ZichanCategory[]; - pagination: { - total: number; - current: number; - pageSize: number; - }; -} - -// 资产归属区域API响应类型 -interface ZichanAreaResponse { - data: ZichanArea[]; - pagination: { - total: number; - current: number; - pageSize: number; - }; -} - -// 机柜服务器类型API响应类型 -interface RackServerTypeResponse { - data: RackServerType[]; - pagination: { - total: number; - current: number; - pageSize: number; - }; -} - -// 资产分类API接口定义 -export const ZichanCategoryAPI = { - // 获取资产分类列表 - getZichanCategoryList: async (params?: { - page?: number, - limit?: number, - name?: string, - code?: string - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-categories`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个资产分类信息 - getZichanCategory: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-categories/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建资产分类 - createZichanCategory: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/zichan-categories`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新资产分类 - updateZichanCategory: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/zichan-categories/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除资产分类 - deleteZichanCategory: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/zichan-categories/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 资产归属区域API接口定义 -export const ZichanAreaAPI = { - // 获取资产归属区域列表 - getZichanAreaList: async (params?: { - page?: number, - limit?: number, - name?: string, - code?: string - }) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-areas`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个资产归属区域信息 - getZichanArea: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/zichan-areas/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建资产归属区域 - createZichanArea: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/zichan-areas`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新资产归属区域 - updateZichanArea: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/zichan-areas/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除资产归属区域 - deleteZichanArea: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/zichan-areas/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - -// 机柜服务器类型API接口定义 -export const RackServerTypeAPI = { - // 获取机柜服务器类型列表 - getRackServerTypeList: async (params?: { - page?: number, - limit?: number, - name?: string, - code?: string - }): Promise => { - try { - const response = await axios.get(`${API_BASE_URL}/rack-server-types`, { params }); - return response.data; - } catch (error) { - throw error; - } - }, - - // 获取单个机柜服务器类型信息 - getRackServerType: async (id: number) => { - try { - const response = await axios.get(`${API_BASE_URL}/rack-server-types/${id}`); - return response.data; - } catch (error) { - throw error; - } - }, - - // 创建机柜服务器类型 - createRackServerType: async (data: Partial) => { - try { - const response = await axios.post(`${API_BASE_URL}/rack-server-types`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 更新机柜服务器类型 - updateRackServerType: async (id: number, data: Partial) => { - try { - const response = await axios.put(`${API_BASE_URL}/rack-server-types/${id}`, data); - return response.data; - } catch (error) { - throw error; - } - }, - - // 删除机柜服务器类型 - deleteRackServerType: async (id: number) => { - try { - const response = await axios.delete(`${API_BASE_URL}/rack-server-types/${id}`); - return response.data; - } catch (error) { - throw error; - } - } -}; - // 定义文件相关接口类型 interface FileUploadPolicyResponse { message: string; @@ -1417,109 +387,6 @@ export const FileAPI = { } }; -// // 添加图表类型定义(从大屏移植) -// interface CategoryChartData { -// 设备分类: string; -// 设备数: number; -// } - -// interface CategoryChartDataWithPercent extends CategoryChartData { -// 百分比: string; -// } - -// interface OnlineRateChartData { -// time_interval: string; -// online_devices: number; -// total_devices: number; -// } - -// interface StateChartData { -// 资产流转: string; -// 设备数: number; -// } - -// interface StateChartDataWithPercent extends StateChartData { -// 百分比: string; -// } - -// interface AlarmChartData { -// time_interval: string; -// total_devices: number; -// } - -// 统一图表数据查询函数 -export const chartQueryFns = { - // 资产分类数据查询 - fetchCategoryData: async (): Promise => { - const res = await axios.get(`${API_BASE_URL}/big/zichan_category_chart`); - - // 预先计算百分比 - const data = res.data; - const total = data.reduce((sum: number, item: CategoryChartData) => sum + item['设备数'], 0); - - // 为每个数据项添加百分比字段 - return data.map(item => ({ - ...item, - 百分比: total > 0 ? (item['设备数'] / total * 100).toFixed(1) : '0' - })); - }, - - // 在线率变化数据查询 - fetchOnlineRateData: async (params?: { - created_at_gte?: string; - created_at_lte?: string; - dimension?: string; - }): Promise => { - // 可选参数 - // const params = { - // created_at_gte: dayjs().subtract(7, 'day').format('YYYY-MM-DD HH:mm:ss'), - // created_at_lte: dayjs().format('YYYY-MM-DD HH:mm:ss'), - // dimension: 'day' - // }; - - const res = await axios.get(`${API_BASE_URL}/big/zichan_online_rate_chart`, { params }); - return res.data; - }, - - // 资产流转状态数据查询 - fetchStateData: async (): Promise => { - const res = await axios.get(`${API_BASE_URL}/big/zichan_state_chart`); - - // 预先计算百分比 - const data = res.data; - const total = data.reduce((sum: number, item: StateChartData) => sum + item['设备数'], 0); - - // 为每个数据项添加百分比字段 - return data.map(item => ({ - ...item, - 百分比: total > 0 ? (item['设备数'] / total * 100).toFixed(1) : '0' - })); - }, - - // 告警数据变化查询 - fetchAlarmData: async (params?: { - created_at_gte?: string; - created_at_lte?: string; - dimension?: string; - }): Promise => { - // 可选参数 - // const params = { - // created_at_gte: dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'), - // created_at_lte: dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss'), - // dimension: 'hour' - // }; - - - const res = await axios.get(`${API_BASE_URL}/big/zichan_alarm_chart`, { params }); - return res.data; - } -}; - -// Theme API 响应类型 -export interface ThemeSettingsResponse { - message: string; - data: ThemeSettings; -} // Theme API 定义 export const ThemeAPI = { @@ -1683,12 +550,6 @@ export const MapAPI = { } }; -// 系统设置API响应类型 -interface SystemSettingsResponse { - message: string; - data: SystemSetting[]; -} - // 系统设置API export const SystemAPI = { // 获取所有系统设置 diff --git a/client/mobile/hooks.tsx b/client/mobile/hooks.tsx index b4b806e..cb0b021 100644 --- a/client/mobile/hooks.tsx +++ b/client/mobile/hooks.tsx @@ -6,45 +6,6 @@ import type { User, AuthContextType, ThemeContextType, ThemeSettings } from '../ import { ThemeMode, FontSize, CompactMode } from '../share/types.ts'; import { AuthAPI, ThemeAPI } from './api.ts'; -// 创建axios实例 -const api = axios.create({ - baseURL: window.CONFIG?.API_BASE_URL || '/api', - timeout: 10000, - headers: { - 'Content-Type': 'application/json', - } -}); - -// 请求拦截器添加token -api.interceptors.request.use( - (config) => { - const token = getLocalStorageWithExpiry('token'); - if (token) { - config.headers['Authorization'] = `Bearer ${token}`; - } - return config; - }, - (error) => { - return Promise.reject(error); - } -); - -// 响应拦截器处理错误 -api.interceptors.response.use( - (response) => { - return response; - }, - (error) => { - if (error.response && error.response.status === 401) { - // 清除本地存储并刷新页面 - localStorage.removeItem('token'); - localStorage.removeItem('user'); - window.location.href = '/mobile/login'; - } - return Promise.reject(error); - } -); - // 默认主题设置 const defaultThemeSettings: ThemeSettings = { user_id: 0, @@ -82,7 +43,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children try { // 设置请求头 - api.defaults.headers.common['Authorization'] = `Bearer ${token}`; + axios.defaults.headers.common['Authorization'] = `Bearer ${token}`; // 获取当前用户信息 const currentUser = await AuthAPI.getCurrentUser(); setUser(currentUser); @@ -114,7 +75,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children setLocalStorageWithExpiry('user', user, 24); // 设置请求头 - api.defaults.headers.common['Authorization'] = `Bearer ${token}`; + axios.defaults.headers.common['Authorization'] = `Bearer ${token}`; } catch (error) { console.error('登录失败:', error); @@ -136,7 +97,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children localStorage.removeItem('token'); localStorage.removeItem('user'); // 清除请求头 - delete api.defaults.headers.common['Authorization']; + delete axios.defaults.headers.common['Authorization']; // 清除所有查询缓存 queryClient.clear(); } diff --git a/client/mobile/mobile_app.tsx b/client/mobile/mobile_app.tsx index 497a07d..0690917 100644 --- a/client/mobile/mobile_app.tsx +++ b/client/mobile/mobile_app.tsx @@ -192,45 +192,71 @@ const ErrorPage = () => { }; // 添加个人页面组件 -const ProfilePage = () => ( -
-

我的

-
-
-
- 用户 -
-
-

用户名

-

个人信息

+const ProfilePage = () => { + const { logout, user } = useAuth(); + const navigate = useNavigate(); + + const handleLogout = async () => { + if (confirm('确定要退出登录吗?')) { + await logout(); + navigate('/mobile/login'); + } + }; + + return ( +
+

我的

+
+
+
+ {user?.avatar ? ( + {user?.nickname + ) : ( + 用户 + )} +
+
+

{user?.nickname || user?.username || '未登录用户'}

+

个人信息

+
+
+
+ 设置 +
+
+
+ 账号安全 + +
+
+ 通知设置 + +
+
+ 隐私 + +
+
+ 关于 + +
+
+
+
-
-
- 设置 -
-
-
- 账号安全 - -
-
- 通知设置 - -
-
- 隐私 - -
-
- 关于 - -
-
-
-
-); + ); +}; // 添加通知页面组件 const NotificationsPage = () => (