diff --git a/server/api/power-station/chart-data.get.ts b/server/api/power-station/chart-data.get.ts new file mode 100644 index 0000000..bb2c6c4 --- /dev/null +++ b/server/api/power-station/chart-data.get.ts @@ -0,0 +1,77 @@ +/** + * 获取电站节点图表数据API + * 根据节点ID和图表类型获取应力或温度历史数据 + */ + +export default defineEventHandler(async (event) => { + try { + const query = getQuery(event) + + // 获取必需参数 + const nodeId = query.nodeId as string + const chartType = query.type as 'stress' | 'temp' + + if (!nodeId) { + throw createError({ + statusCode: 400, + statusMessage: '缺少必要参数: nodeId', + }) + } + + if (!chartType || !['stress', 'temp'].includes(chartType)) { + throw createError({ + statusCode: 400, + statusMessage: '缺少必要参数: type (必须为 stress 或 temp)', + }) + } + + // 模拟数据生成(基于数据库结构) + // 实际项目中这里应该连接真实数据库查询 + const dates = [] + const values = [] + const now = new Date() + + // 生成最近30天的数据 + for (let i = 0; i < 30; i++) { + const date = new Date(now.getTime() - (29 - i) * 24 * 60 * 60 * 1000) + dates.push(date.toISOString().split('T')[0]) + + if (chartType === 'stress') { + // 应力数据:100-150 MPa,模拟真实应力变化 + const baseStress = 120 + Math.sin(i * 0.2) * 10 + const randomVariation = (Math.random() - 0.5) * 20 + values.push(Math.round((baseStress + randomVariation) * 10) / 10) + } else { + // 温度数据:560-580°C,模拟真实温度变化 + const baseTemp = 570 + Math.sin(i * 0.15) * 5 + const randomVariation = (Math.random() - 0.5) * 10 + values.push(Math.round((baseTemp + randomVariation) * 10) / 10) + } + } + + // 返回图表数据 + const result = { + dates, + values, + unit: chartType === 'stress' ? 'MPa' : '°C', + name: chartType === 'stress' ? '历史应力 (Stress)' : '历史温度 (Temp)', + nodeId, + chartType, + } + + return { + success: true, + data: result, + message: '成功获取图表数据', + timestamp: new Date().toISOString(), + } + + } catch (error) { + console.error('获取图表数据失败:', error) + + throw createError({ + statusCode: error.statusCode || 500, + statusMessage: error.message || '获取图表数据失败', + }) + } +}) \ No newline at end of file diff --git a/server/api/power-station/properties.get.ts b/server/api/power-station/properties.get.ts new file mode 100644 index 0000000..1b97777 --- /dev/null +++ b/server/api/power-station/properties.get.ts @@ -0,0 +1,42 @@ +export default defineEventHandler(async event => { + const query = getQuery(event) + const nodeId = query.nodeId as string + + if (!nodeId) { + throw createError({ + statusCode: 400, + statusMessage: 'Node ID is required', + }) + } + + try { + // 模拟属性数据 + const mockProperties = { + basic: [ + { label: '节点ID', value: nodeId }, + { label: '节点名称', value: nodeId.split('~').pop() }, + { label: '节点类型', value: '设备' }, + { label: '所属系统', value: '主系统' }, + ], + technical: [ + { label: '设计压力', value: '16.5 MPa', unit: 'MPa' }, + { label: '设计温度', value: '545', unit: '°C' }, + { label: '材料', value: 'SA-516 Gr.70' }, + { label: '厚度', value: '25', unit: 'mm' }, + ], + status: [ + { label: '运行状态', value: '正常运行', status: 'success' }, + { label: '健康度', value: '95%', status: 'success' }, + { label: '维护状态', value: '正常', status: 'success' }, + { label: '报警状态', value: '无报警', status: 'success' }, + ], + } + + return mockProperties + } catch (error) { + throw createError({ + statusCode: 500, + statusMessage: 'Failed to fetch properties data', + }) + } +})