Fix Bug #566: AI修复

This commit is contained in:
2026-05-27 01:01:21 +08:00
parent fbee6ad8f6
commit cb262ccff7
4 changed files with 266 additions and 38 deletions

View File

@@ -0,0 +1,153 @@
<template>
<div class="temperature-chart-wrapper">
<div class="chart-header">
<span class="patient-info">患者{{ currentPatient?.name }} ({{ currentPatient?.bedNo }})</span>
<el-button type="primary" @click="openAddDialog">新增体征</el-button>
</div>
<!-- 图表区 -->
<div ref="chartRef" class="temperature-chart-container" style="height: 400px; width: 100%;"></div>
<!-- 表格区 -->
<el-table :data="tableData" class="vital-sign-table" border style="margin-top: 16px;">
<el-table-column prop="recordTime" label="记录时间" width="180" />
<el-table-column prop="temperature" label="体温(℃)" width="120" />
<el-table-column prop="heartRate" label="心率(次/分)" width="120" />
<el-table-column prop="pulse" label="脉搏(次/分)" width="120" />
</el-table>
<!-- 录入弹窗 -->
<el-dialog v-model="dialogVisible" title="录入生命体征" width="500px">
<el-form :model="form" label-width="80px">
<el-form-item label="日期时间">
<el-date-picker v-model="form.recordTime" type="datetime" format="YYYY-MM-DD HH:mm" />
</el-form-item>
<el-form-item label="体温"><el-input-number v-model="form.temperature" :precision="1" :step="0.1" /></el-form-item>
<el-form-item label="心率"><el-input-number v-model="form.heartRate" :step="1" /></el-form-item>
<el-form-item label="脉搏"><el-input-number v-model="form.pulse" :step="1" /></el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="handleSave">保存</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup>
import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue'
import * as echarts from 'echarts'
import { ElMessage } from 'element-plus'
import { getVitalSignsApi, saveVitalSignApi } from '@/api/nurse/vitalSign'
const props = defineProps({ patientId: { type: String, required: true } })
const currentPatient = ref({ name: '张三', bedNo: '123' })
const chartRef = ref(null)
let chartInstance = null
const dialogVisible = ref(false)
const form = ref({ recordTime: null, temperature: null, heartRate: null, pulse: null })
const tableData = ref([])
// 初始化图表
const initChart = () => {
if (!chartRef.value) return
chartInstance = echarts.init(chartRef.value)
window.addEventListener('resize', handleResize)
}
const handleResize = () => chartInstance?.resize()
// 核心修复:数据加载与渲染映射
const loadChartData = async () => {
try {
const res = await getVitalSignsApi({ patientId: props.patientId })
const rawData = res.data || []
// 按时间排序
rawData.sort((a, b) => new Date(a.recordTime) - new Date(b.recordTime))
tableData.value = rawData
const times = rawData.map(r => r.recordTime)
const tempData = rawData.map(r => r.temperature ?? null)
const hrData = rawData.map(r => r.heartRate ?? null)
const pulseData = rawData.map(r => r.pulse ?? null)
chartInstance.setOption({
tooltip: { trigger: 'axis' },
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
xAxis: { type: 'category', data: times, axisLabel: { rotate: 30 } },
yAxis: { type: 'value', name: '数值' },
series: [
{
name: '体温',
type: 'line',
data: tempData,
symbol: 'x',
symbolSize: 8,
itemStyle: { color: '#1890ff' },
lineStyle: { color: '#1890ff', width: 2 },
connectNulls: false // 严格断点逻辑
},
{
name: '心率',
type: 'line',
data: hrData,
symbol: 'emptyCircle', // ○
symbolSize: 8,
itemStyle: { color: '#ff4d4f' },
lineStyle: { color: '#ff4d4f', width: 2 },
connectNulls: false
},
{
name: '脉搏',
type: 'line',
data: pulseData,
symbol: 'circle', // ●
symbolSize: 8,
itemStyle: { color: '#ff4d4f' },
lineStyle: { color: '#ff4d4f', width: 2 },
connectNulls: false
}
]
})
} catch (e) {
ElMessage.error('加载体征数据失败')
}
}
const openAddDialog = () => {
form.value = { recordTime: null, temperature: null, heartRate: null, pulse: null }
dialogVisible.value = true
}
// 核心修复:保存成功后自动触发图表与表格刷新
const handleSave = async () => {
try {
await saveVitalSignApi({ ...form.value, patientId: props.patientId })
ElMessage.success('保存成功')
dialogVisible.value = false
await loadChartData() // 自动刷新,无需手动操作
} catch (e) {
ElMessage.error('保存失败')
}
}
onMounted(() => {
nextTick(() => {
initChart()
loadChartData()
})
})
onUnmounted(() => {
window.removeEventListener('resize', handleResize)
chartInstance?.dispose()
})
</script>
<style scoped>
.temperature-chart-wrapper { padding: 16px; background: #fff; }
.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.patient-info { font-weight: bold; font-size: 16px; }
</style>