修复屏蔽设备恢复效果,设定后端计时器每天10点刷新,同时设定前端刷新页面时间
This commit is contained in:
@ -4,25 +4,25 @@
|
||||
<template #header>
|
||||
<div class="header-row">
|
||||
<div class="left-panel">
|
||||
<h2 class="sys-title">📡 数据同步大屏</h2>
|
||||
<h2 class="sys-title">📡 数据同步监控大屏</h2>
|
||||
<div class="sys-status">
|
||||
<span v-if="isRunning" class="status-running">
|
||||
<el-icon class="is-loading"><Loading /></el-icon> 正在清洗并同步最新数据...
|
||||
<el-icon class="is-loading"><Loading /></el-icon> 正在执行同步任务 (请勿刷新页面)...
|
||||
</span>
|
||||
<span v-else class="status-idle">
|
||||
<el-icon><CircleCheck /></el-icon> 状态: 待命 (更新于: {{ lastUpdateTime }})
|
||||
<el-icon><CircleCheck /></el-icon> 系统就绪 (最后更新: {{ lastCheckTime }})
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<el-button type="primary" :loading="isRunning" @click="handleManualRefresh" round icon="Refresh">全量同步</el-button>
|
||||
<el-button type="primary" :loading="isRunning" @click="handleManualRefresh(false)" round icon="Refresh">手动同步</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="status-summary">
|
||||
<el-tag type="danger">红色:离线/无数据/滞后>7天</el-tag>
|
||||
<el-tag type="warning" style="--el-tag-bg-color: #ff8c00; border-color: #ff8c00; color: #fff;">橘色:滞后2-7天</el-tag>
|
||||
<el-tag type="warning">黄色:滞后1-2天 或 跨天未更新</el-tag>
|
||||
<el-tag type="success">绿色:今日已同步</el-tag>
|
||||
<el-tag type="danger" effect="dark">红色:已离线 / 异常 / 滞后>7天</el-tag>
|
||||
<el-tag type="warning" style="--el-tag-bg-color: #ff8c00; border-color: #ff8c00; color: #fff;" effect="dark">橘色:滞后 2-7 天</el-tag>
|
||||
<el-tag type="warning" effect="dark">黄色:滞后 1-2 天</el-tag>
|
||||
<el-tag type="success" effect="dark">绿色:正常且今日已同步</el-tag>
|
||||
</div>
|
||||
|
||||
<div class="toolbar">
|
||||
@ -32,44 +32,50 @@
|
||||
<el-radio-button value="106">106 代理</el-radio-button>
|
||||
<el-radio-button value="82">82 气象站</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-input v-model="filters.keyword" placeholder="搜索设备..." style="width: 200px; margin-left: 15px;" clearable />
|
||||
<el-input v-model="filters.keyword" placeholder="搜索设备名称..." style="width: 200px; margin-left: 15px;" clearable />
|
||||
</div>
|
||||
<div class="action-section">
|
||||
<el-checkbox v-model="showHidden" label="显示屏蔽" border style="margin-right: 10px"/>
|
||||
<el-checkbox v-model="showHidden" label="显示屏蔽设备" border style="margin-right: 10px"/>
|
||||
<el-button type="warning" plain :disabled="selectedRows.length === 0" @click="hideSelected">屏蔽选中</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-table :data="sortedData" border height="600" v-loading="isRunning" @selection-change="val => selectedRows = val">
|
||||
<el-table
|
||||
ref="multipleTableRef"
|
||||
:data="sortedData"
|
||||
border
|
||||
height="600"
|
||||
v-loading="isRunning"
|
||||
@selection-change="val => selectedRows = val"
|
||||
:row-class-name="tableRowClassName"
|
||||
>
|
||||
<el-table-column type="selection" width="50" align="center" />
|
||||
<el-table-column prop="source" label="来源" width="100" />
|
||||
<el-table-column label="名称" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<el-link type="primary" underline="hover" @click="showDetails(row)" style="font-weight: bold; font-size: 15px;">
|
||||
{{ formatDisplayName(row.name) }}
|
||||
</el-link>
|
||||
<el-tag v-if="isHidden(row.name)" type="info" size="small" style="margin-left:5px">已隐藏</el-tag>
|
||||
<div class="name-cell">
|
||||
<el-link type="primary" underline="hover" @click="showDetails(row)" style="font-weight: bold; font-size: 15px;">
|
||||
{{ formatDisplayName(row.name) }}
|
||||
</el-link>
|
||||
<el-tag v-if="isHidden(row.name)" type="info" size="small" style="margin-left:5px">已隐藏</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="140" align="center">
|
||||
<el-table-column label="当前状态" width="140" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :style="getStatusTagStyle(row)" effect="dark">
|
||||
{{ getStatusLabel(row) }}
|
||||
</el-tag>
|
||||
<el-tag :style="getStatusTagStyle(row)" effect="dark">{{ getStatusLabel(row) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="reason" label="实时详情">
|
||||
<el-table-column prop="reason" label="系统反馈" min-width="200">
|
||||
<template #default="{ row }">
|
||||
<span :style="{ color: getStatusColor(row), fontWeight: getLevel(row) > 1 ? 'bold' : 'normal' }">
|
||||
{{ formatReason(row) }}
|
||||
</span>
|
||||
<span :style="{ color: getStatusColor(row), fontWeight: 'bold' }">{{ formatReason(row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="offset" label="时效" width="100" />
|
||||
<el-table-column prop="latest_time" label="同步日期" width="180" />
|
||||
<el-table-column label="管理" width="80" v-if="showHidden">
|
||||
<el-table-column prop="offset" label="时效性" width="120" align="center" />
|
||||
<el-table-column prop="latest_time" label="数据时间" width="180" align="center" />
|
||||
<el-table-column label="操作" width="80" v-if="showHidden" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="restoreDevice(row.name)">恢复</el-button>
|
||||
<el-button v-if="isHidden(row.name)" type="primary" link @click="restoreDevice(row.name)">恢复</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@ -78,131 +84,106 @@
|
||||
<el-drawer v-model="drawerVisible" title="设备数据分析详情" size="80%" @opened="initCharts">
|
||||
<div v-if="activeDevice" class="drawer-content">
|
||||
<div class="info-banner">
|
||||
<el-descriptions :column="3" border size="small">
|
||||
<el-descriptions :column="4" border size="small">
|
||||
<el-descriptions-item label="设备名称">{{ formatDisplayName(activeDevice.name) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="所属来源">{{ activeDevice.source }}</el-descriptions-item>
|
||||
<el-descriptions-item label="最后同步时间">{{ activeDevice.latest_time }}</el-descriptions-item>
|
||||
<el-descriptions-item label="当前状态"><el-tag size="small" :style="getStatusTagStyle(activeDevice)">{{ getStatusLabel(activeDevice) }}</el-tag></el-descriptions-item>
|
||||
<el-descriptions-item label="数据时间">{{ activeDevice.latest_time }}</el-descriptions-item>
|
||||
<el-descriptions-item label="检查时间">{{ activeDevice.check_time }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
|
||||
<div class="visual-section">
|
||||
<h3 class="section-title">
|
||||
<el-icon><DataLine /></el-icon>
|
||||
{{ is106Site ? '光谱能量分布分析 (自动滤除饱和噪点)' : '气象站光谱数据分析 (Up/Down Spec)' }}
|
||||
{{ is106Site ? '光谱能量分布 (已滤除饱和值)' : '气象站光谱数据 (Up/Down Spec)' }}
|
||||
</h3>
|
||||
|
||||
<div v-if="currentChartModules.length === 0" class="empty-hint">
|
||||
{{ isContentEmpty(activeDevice) ? '暂无有效的数据内容' : '未检测到符合格式的光谱数据' }}
|
||||
</div>
|
||||
|
||||
<div v-if="currentChartModules.length === 0" class="empty-hint"><el-empty description="暂无有效的图表数据" /></div>
|
||||
<div v-for="(module, index) in currentChartModules" :key="index" class="chart-container">
|
||||
<div class="chart-header" v-if="is106Site">
|
||||
<span class="module-tag">型号: {{ module.model }}</span>
|
||||
<span class="sn-tag">序列号: {{ module.sn }}</span>
|
||||
<span class="sn-tag">SN: {{ module.sn }}</span>
|
||||
</div>
|
||||
<div :id="'chart-' + index" class="echart-box" :class="{ 'no-header': !is106Site }"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted, nextTick } from 'vue'
|
||||
import { ref, reactive, computed, onMounted, onBeforeUnmount, nextTick } from 'vue'
|
||||
import axios from 'axios'
|
||||
import * as echarts from 'echarts'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Loading, CircleCheck, Refresh, DataLine } from '@element-plus/icons-vue' // 确保引入图标
|
||||
|
||||
// 1. 基础响应式变量
|
||||
// --- 状态变量 ---
|
||||
const rawData = ref([])
|
||||
const isRunning = ref(false)
|
||||
const lastUpdateTime = ref('-')
|
||||
const lastCheckTime = ref('N/A')
|
||||
const selectedRows = ref([])
|
||||
const showHidden = ref(false)
|
||||
const drawerVisible = ref(false)
|
||||
const activeDevice = ref(null)
|
||||
const filters = reactive({ site: 'all', keyword: '' })
|
||||
const multipleTableRef = ref() // 表格引用
|
||||
|
||||
// 初始化隐藏列表(从 LocalStorage 读取)
|
||||
const ignoredList = ref(JSON.parse(localStorage.getItem('hide_list') || '[]'))
|
||||
|
||||
// --- UI 格式化工具 ---
|
||||
let autoRefreshTimer = null
|
||||
|
||||
// --- 工具函数 ---
|
||||
const formatDisplayName = (name) => {
|
||||
if (!name) return ''
|
||||
return name.split('_').map(part => {
|
||||
const lower = part.toLowerCase()
|
||||
return lower.charAt(0).toUpperCase() + lower.slice(1)
|
||||
}).join('_')
|
||||
}
|
||||
|
||||
// --- 核心逻辑 ---
|
||||
const isContentEmpty = (row) => {
|
||||
return !row.content ||
|
||||
row.content.toString().trim() === '' ||
|
||||
row.content === '{}' ||
|
||||
row.content === '[]'
|
||||
}
|
||||
|
||||
const isSameDay = (d1, d2) => {
|
||||
return d1.getFullYear() === d2.getFullYear() &&
|
||||
d1.getMonth() === d2.getMonth() &&
|
||||
d1.getDate() === d2.getDate()
|
||||
return name.split('_').map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join('_')
|
||||
}
|
||||
|
||||
const parseFlexibleDate = (dateStr) => {
|
||||
if (!dateStr) return null
|
||||
if (!dateStr || dateStr === 'N/A') return null
|
||||
try {
|
||||
let cleanStr = dateStr.toString().replace(/[_/]/g, '-')
|
||||
if (cleanStr.includes(' ')) {
|
||||
const parts = cleanStr.split(' ')
|
||||
if (parts[1] && parts[1].includes('-') && !parts[1].includes(':')) {
|
||||
parts[1] = parts[1].replace(/-/g, ':')
|
||||
}
|
||||
cleanStr = parts.join(' ')
|
||||
}
|
||||
let cleanStr = dateStr.toString().split('.')[0].replace(/[_/]/g, '-')
|
||||
const d = new Date(cleanStr)
|
||||
return isNaN(d.getTime()) ? null : d
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
} catch { return null }
|
||||
}
|
||||
|
||||
const getHoursDiff = (dateStr) => {
|
||||
if (!dateStr || dateStr === 'N/A') return 999
|
||||
const lastDate = parseFlexibleDate(dateStr)
|
||||
if (!lastDate) return 999
|
||||
return (new Date() - lastDate) / (1000 * 3600)
|
||||
}
|
||||
|
||||
// --- 业务逻辑 (状态与排序) ---
|
||||
const getLevel = (row) => {
|
||||
const errorKeywords = ['离线', '失败', '无法访问', '无数据', '异常', 'Empty']
|
||||
if (row.reason && errorKeywords.some(kw => row.reason.includes(kw))) return 4
|
||||
if (isContentEmpty(row)) return 4
|
||||
if (row.status === '已离线' || row.status === '异常') return 4
|
||||
if (!row.content || row.content === '{}') return 4
|
||||
|
||||
const last = parseFlexibleDate(row.latest_time)
|
||||
if (!last) return 4
|
||||
const now = new Date()
|
||||
const diffHours = (now - last) / (1000 * 3600)
|
||||
const diffDays = diffHours / 24
|
||||
if (diffDays > 7) return 4
|
||||
if (diffDays > 2) return 3
|
||||
if (diffHours > 24) return 2
|
||||
if (!isSameDay(now, last)) return 2
|
||||
const days = (now - last) / (1000 * 3600 * 24)
|
||||
|
||||
if (days > 7) return 4
|
||||
if (days > 2) return 3
|
||||
if (now.getDate() !== last.getDate()) return 2
|
||||
return 1
|
||||
}
|
||||
|
||||
const getStatusLabel = (row) => {
|
||||
if (row.status === '已离线') return '已离线'
|
||||
if (row.status === '异常') return '采集异常'
|
||||
const level = getLevel(row)
|
||||
if (level === 4) {
|
||||
if (isContentEmpty(row) && (!row.reason || !row.reason.includes('离线'))) return '数据缺失'
|
||||
return '离线/异常'
|
||||
}
|
||||
if (level === 2) {
|
||||
const last = parseFlexibleDate(row.latest_time)
|
||||
const now = new Date()
|
||||
if ((now - last) / (1000 * 3600) <= 24) return '待今日更新(<24h)'
|
||||
return '滞后(1-2d)'
|
||||
}
|
||||
return ['','正常','滞后(1-2d)','滞后(2-7d)'][level]
|
||||
if (level === 4) return '数据缺失'
|
||||
if (level === 3) return '滞后 >2天'
|
||||
if (level === 2) return '昨日数据'
|
||||
return '在线(今日)'
|
||||
}
|
||||
|
||||
const getStatusColor = (row) => {
|
||||
const level = getLevel(row)
|
||||
if (level === 1) return '#67C23A'
|
||||
if (level === 2) return '#E6A23C'
|
||||
if (level === 3) return '#ff8c00'
|
||||
return '#F56C6C'
|
||||
return ['#909399', '#67C23A', '#E6A23C', '#ff8c00', '#F56C6C'][level]
|
||||
}
|
||||
|
||||
const getStatusTagStyle = (row) => {
|
||||
@ -211,162 +192,91 @@ const getStatusTagStyle = (row) => {
|
||||
}
|
||||
|
||||
const formatReason = (row) => {
|
||||
if (row.reason) return row.reason
|
||||
if (row.reason && row.reason !== '同步成功') return row.reason
|
||||
const level = getLevel(row)
|
||||
if (level === 4 && isContentEmpty(row)) return '❌ 数据内容为空'
|
||||
if (level === 2 && getStatusLabel(row).includes('待今日更新')) return '⚠️ 数据仍为昨日'
|
||||
return '同步正常'
|
||||
if (level === 2) return '⚠️ 待今日更新'
|
||||
return '✅ 同步正常'
|
||||
}
|
||||
|
||||
// --- 隐藏/恢复逻辑 (修复重点) ---
|
||||
|
||||
// 1. 判断是否被隐藏
|
||||
const isHidden = (name) => ignoredList.value.includes(name)
|
||||
|
||||
// 2. 恢复设备(从屏蔽列表中移除)
|
||||
const restoreDevice = (name) => {
|
||||
if (!name) return
|
||||
// 过滤掉要恢复的名字
|
||||
ignoredList.value = ignoredList.value.filter(item => item !== name)
|
||||
// 更新本地存储
|
||||
localStorage.setItem('hide_list', JSON.stringify(ignoredList.value))
|
||||
ElMessage.success('设备已恢复显示')
|
||||
}
|
||||
|
||||
// 3. 屏蔽选中设备
|
||||
const hideSelected = () => {
|
||||
if (selectedRows.value.length === 0) return
|
||||
|
||||
const namesToHide = selectedRows.value.map(row => row.name)
|
||||
let count = 0
|
||||
|
||||
namesToHide.forEach(name => {
|
||||
if (!ignoredList.value.includes(name)) {
|
||||
ignoredList.value.push(name)
|
||||
count++
|
||||
}
|
||||
})
|
||||
|
||||
if (count > 0) {
|
||||
localStorage.setItem('hide_list', JSON.stringify(ignoredList.value))
|
||||
ElMessage.warning(`已屏蔽 ${count} 个设备`)
|
||||
|
||||
// 清空表格选中状态
|
||||
if (multipleTableRef.value) {
|
||||
multipleTableRef.value.clearSelection()
|
||||
}
|
||||
} else {
|
||||
ElMessage.info('选中的设备已在屏蔽列表中')
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 显示详情
|
||||
const showDetails = (row) => {
|
||||
activeDevice.value = row
|
||||
drawerVisible.value = true
|
||||
}
|
||||
|
||||
// --- 过滤与排序 ---
|
||||
const sortedData = computed(() => {
|
||||
return rawData.value.filter(d => {
|
||||
const sMatch = filters.site === 'all' || d.source.includes(filters.site)
|
||||
const kMatch = d.name.toLowerCase().includes(filters.keyword.toLowerCase())
|
||||
return sMatch && kMatch && (showHidden.value || !isHidden(d.name))
|
||||
// 基础过滤:站点 + 关键词
|
||||
const basicMatch = (filters.site === 'all' || d.source.includes(filters.site)) &&
|
||||
d.name.toLowerCase().includes(filters.keyword.toLowerCase())
|
||||
|
||||
// 隐藏逻辑:如果勾选了"显示屏蔽设备",则显示所有;否则过滤掉在 ignoredList 中的
|
||||
if (showHidden.value) {
|
||||
return basicMatch
|
||||
} else {
|
||||
return basicMatch && !isHidden(d.name)
|
||||
}
|
||||
}).sort((a, b) => getLevel(b) - getLevel(a))
|
||||
})
|
||||
|
||||
// --- 图表数据解析逻辑 (修正版) ---
|
||||
const tableRowClassName = ({ row }) => row.status === '已离线' ? 'offline-row' : ''
|
||||
|
||||
const is106Site = computed(() => activeDevice.value?.source.includes('106'))
|
||||
|
||||
// 106 数据解析逻辑:增加对 65534/65535 的饱和值过滤
|
||||
const chartModules106 = computed(() => {
|
||||
if (!is106Site.value || isContentEmpty(activeDevice.value)) return []
|
||||
const content = activeDevice.value.content
|
||||
const modules = []
|
||||
const infoRegex = /FS\d_Info,Model,([^,]+),SN,([^,]+).*?Wavelength,([\d\.,\s]+)/gs
|
||||
let infoMap = []
|
||||
let match
|
||||
while ((match = infoRegex.exec(content)) !== null) {
|
||||
infoMap.push({
|
||||
model: match[1].trim(),
|
||||
sn: match[2].trim(),
|
||||
wavelengths: match[3].split(',').map(v => v.trim()).filter(v => v && !isNaN(v)).map(Number)
|
||||
})
|
||||
}
|
||||
infoMap.forEach(info => {
|
||||
const series = []
|
||||
for (let p = 1; p <= 4; p++) {
|
||||
const dataRegex = new RegExp(`${info.model}_P${p}[^0-9-]*([\\d\\.,\\s-]+)`, 'i')
|
||||
const dataMatch = content.match(dataRegex)
|
||||
if (dataMatch) {
|
||||
const rawStr = dataMatch[1]
|
||||
const vals = rawStr.split(',').map(v => {
|
||||
const num = parseFloat(v)
|
||||
if (isNaN(num)) return null
|
||||
// 【核心修复】如果数值超过 65500 (通常是 65534/65535 饱和值),
|
||||
// 视为 null 无效点。这能解决 20000 的数据被 65534 撑大的问题。
|
||||
return num > 65500 ? null : num
|
||||
})
|
||||
|
||||
// 过滤掉全是 null 的数组,避免报错
|
||||
if (vals.some(v => v !== null)) {
|
||||
series.push({ name: `通道 P${p}`, data: vals })
|
||||
}
|
||||
}
|
||||
}
|
||||
if (series.length > 0) {
|
||||
modules.push({ model: info.model, sn: info.sn, xAxis: info.wavelengths, series: series })
|
||||
}
|
||||
})
|
||||
return modules
|
||||
})
|
||||
|
||||
// 82 数据解析逻辑 (保持逻辑不变)
|
||||
const chartModules82 = computed(() => {
|
||||
if (is106Site.value || isContentEmpty(activeDevice.value)) return []
|
||||
try {
|
||||
const data = JSON.parse(activeDevice.value.content)
|
||||
if (!Array.isArray(data.wavelenth) || !Array.isArray(data.downspec) || !Array.isArray(data.upspec)) {
|
||||
return []
|
||||
}
|
||||
return [{
|
||||
title: formatDisplayName(activeDevice.value.name),
|
||||
xAxis: data.wavelenth,
|
||||
series: [
|
||||
{ name: 'DownSpec (下行光谱)', data: data.downspec, color: '#409EFF' },
|
||||
{ name: 'UpSpec (上行光谱)', data: data.upspec, color: '#67C23A' }
|
||||
]
|
||||
}]
|
||||
} catch (e) {
|
||||
return []
|
||||
}
|
||||
})
|
||||
|
||||
const currentChartModules = computed(() => {
|
||||
return is106Site.value ? chartModules106.value : chartModules82.value
|
||||
})
|
||||
|
||||
// --- ECharts 渲染 ---
|
||||
const initCharts = () => {
|
||||
nextTick(() => {
|
||||
const modules = currentChartModules.value
|
||||
if (modules.length === 0) return
|
||||
|
||||
modules.forEach((module, index) => {
|
||||
const dom = document.getElementById(`chart-${index}`)
|
||||
if (!dom) return
|
||||
if (echarts.getInstanceByDom(dom)) echarts.getInstanceByDom(dom).dispose()
|
||||
|
||||
const chart = echarts.init(dom)
|
||||
const defaultColors = ['#409EFF', '#67C23A', '#E6A23C', '#F56C6C']
|
||||
|
||||
const option = {
|
||||
title: {
|
||||
text: is106Site.value ? `SN: ${module.sn}` : module.title,
|
||||
left: 'center',
|
||||
top: is106Site.value ? 5 : 15,
|
||||
textStyle: { fontSize: 14, color: '#606266' }
|
||||
},
|
||||
tooltip: { trigger: 'axis' },
|
||||
legend: { top: is106Site.value ? '8%' : '12%' },
|
||||
grid: { left: '3%', right: '4%', bottom: '3%', top: '22%', containLabel: true },
|
||||
xAxis: { type: 'category', boundaryGap: false, data: module.xAxis, axisLabel: { color: '#909399', fontSize: 10 } },
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
scale: true,
|
||||
// 核心点:紧贴 dataMin 和 dataMax
|
||||
// 由于上面已经把 65535 变成了 null,这里的 dataMax 将是 20000 左右
|
||||
min: 'dataMin',
|
||||
max: 'dataMax',
|
||||
splitLine: { lineStyle: { type: 'dashed' } }
|
||||
},
|
||||
series: module.series.map((s, i) => {
|
||||
const lineColor = s.color || defaultColors[i % 4]
|
||||
return {
|
||||
name: s.name,
|
||||
type: 'line',
|
||||
data: s.data,
|
||||
// 连线策略:spanGaps 为 false 表示遇到 null 断开,这样能清楚看到哪里数据过曝了
|
||||
// 如果想连起来,可以改为 true
|
||||
connectNulls: false,
|
||||
smooth: true,
|
||||
showSymbol: false,
|
||||
lineStyle: { width: 2, color: lineColor },
|
||||
areaStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:lineColor+'33'},{offset:1,color:'transparent'}])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
chart.setOption(option)
|
||||
window.addEventListener('resize', () => chart.resize())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// --- API 交互 (保持不变) ---
|
||||
// --- 刷新逻辑 ---
|
||||
const fetchLogs = async () => {
|
||||
try {
|
||||
// 此处仅为示例 URL,请确保后端 API 地址正确
|
||||
const res = await axios.get('/api/logs')
|
||||
rawData.value = res.data
|
||||
if (res.data.length) lastUpdateTime.value = res.data[0].check_time || new Date().toLocaleString()
|
||||
if (res.data.length > 0) {
|
||||
const latest = res.data.reduce((prev, curr) => (prev.check_time > curr.check_time) ? prev : curr)
|
||||
lastCheckTime.value = latest.check_time
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("获取日志失败", e)
|
||||
// 开发环境演示数据,实际生产请删除此块
|
||||
console.warn("API Error, using mock data for display")
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,39 +286,114 @@ const checkStatus = async () => {
|
||||
isRunning.value = res.data.is_running
|
||||
if (isRunning.value) setTimeout(checkStatus, 2000)
|
||||
else fetchLogs()
|
||||
} catch (e) {
|
||||
isRunning.value = false
|
||||
}
|
||||
} catch { isRunning.value = false }
|
||||
}
|
||||
|
||||
const handleManualRefresh = async () => {
|
||||
const handleManualRefresh = async (force = false) => {
|
||||
const hours = getHoursDiff(lastCheckTime.value)
|
||||
if (!force && hours < 6) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`数据更新于 ${hours.toFixed(1)} 小时前。后端每日10点自动更新,通常无需手动操作。\n是否强制重新爬取?`,
|
||||
'数据尚新', { confirmButtonText: '强制爬取', cancelButtonText: '仅加载最新', type: 'warning' }
|
||||
)
|
||||
// 如果用户确认强制爬取,继续往下执行
|
||||
} catch {
|
||||
// 如果用户取消,只刷新日志
|
||||
fetchLogs()
|
||||
ElMessage.success('已加载最新数据库记录')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
isRunning.value = true
|
||||
await axios.post('/api/run')
|
||||
checkStatus()
|
||||
} catch (e) {
|
||||
ElMessage.success('任务已下发')
|
||||
} catch {
|
||||
isRunning.value = false
|
||||
ElMessage.warning('后台已有任务在运行')
|
||||
}
|
||||
}
|
||||
|
||||
const showDetails = (row) => {
|
||||
activeDevice.value = row
|
||||
drawerVisible.value = true
|
||||
}
|
||||
|
||||
const hideSelected = () => {
|
||||
ignoredList.value = [...new Set([...ignoredList.value, ...selectedRows.value.map(r => r.name)])]
|
||||
localStorage.setItem('hide_list', JSON.stringify(ignoredList.value))
|
||||
selectedRows.value = []
|
||||
}
|
||||
|
||||
const restoreDevice = (name) => {
|
||||
ignoredList.value = ignoredList.value.filter(n => n !== name)
|
||||
localStorage.setItem('hide_list', JSON.stringify(ignoredList.value))
|
||||
// --- 图表逻辑 ---
|
||||
const is106Site = computed(() => activeDevice.value?.source?.includes('106'))
|
||||
const currentChartModules = computed(() => {
|
||||
if (!activeDevice.value?.content || activeDevice.value.content === '{}') return []
|
||||
|
||||
if (is106Site.value) {
|
||||
const modules = []
|
||||
// 简单的正则解析,根据实际数据格式调整
|
||||
const infoRegex = /FS\d_Info,Model,([^,]+),SN,([^,]+).*?Wavelength,([\d\.,\s]+)/gs
|
||||
let match
|
||||
// 避免死循环,复制一份字符串操作
|
||||
const contentStr = activeDevice.value.content
|
||||
|
||||
while ((match = infoRegex.exec(contentStr)) !== null) {
|
||||
const wavelengths = match[3].split(',').map(Number).filter(n => !isNaN(n))
|
||||
const series = []
|
||||
for (let p = 1; p <= 4; p++) {
|
||||
const dMatch = contentStr.match(new RegExp(`${match[1].trim()}_P${p}[^0-9-]*([\\d\\.,\\s-]+)`, 'i'))
|
||||
if (dMatch) {
|
||||
const vals = dMatch[1].split(',').map(v => {
|
||||
const n = parseFloat(v); return n > 65500 ? null : n
|
||||
})
|
||||
if (vals.some(v => v !== null)) series.push({ name: `P${p}`, data: vals, color: ['#5470c6', '#91cc75', '#fac858', '#ee6666'][p-1] })
|
||||
}
|
||||
}
|
||||
if (series.length) modules.push({ model: match[1], sn: match[2], xAxis: wavelengths, series })
|
||||
}
|
||||
return modules
|
||||
} else {
|
||||
try {
|
||||
const d = JSON.parse(activeDevice.value.content)
|
||||
return d.wavelenth ? [{ title: activeDevice.value.name, xAxis: d.wavelenth, series: [
|
||||
{ name: 'DownSpec', data: d.downspec, color: '#409EFF' }, { name: 'UpSpec', data: d.upspec, color: '#67C23A' }
|
||||
]}] : []
|
||||
} catch { return [] }
|
||||
}
|
||||
})
|
||||
|
||||
const initCharts = () => {
|
||||
nextTick(() => {
|
||||
currentChartModules.value.forEach((m, i) => {
|
||||
const dom = document.getElementById(`chart-${i}`)
|
||||
if (dom) {
|
||||
if (echarts.getInstanceByDom(dom)) echarts.getInstanceByDom(dom).dispose()
|
||||
const chart = echarts.init(dom)
|
||||
chart.setOption({
|
||||
title: { text: is106Site.value ? `SN: ${m.sn}` : m.title, left: 'center', top: 10 },
|
||||
tooltip: { trigger: 'axis' }, legend: { top: 35 },
|
||||
grid: { top: 70, bottom: 30, right: 30, left: 50 },
|
||||
xAxis: { type: 'category', data: m.xAxis, boundaryGap: false },
|
||||
yAxis: { type: 'value', min: 'dataMin', max: 'dataMax' },
|
||||
series: m.series.map(s => ({
|
||||
name: s.name,
|
||||
type: 'line',
|
||||
data: s.data,
|
||||
connectNulls: false,
|
||||
smooth: true,
|
||||
showSymbol: false,
|
||||
lineStyle: { width: 2, color: s.color },
|
||||
areaStyle: { opacity: 0.1, color: s.color }
|
||||
}))
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// --- 生命周期 ---
|
||||
onMounted(() => {
|
||||
fetchLogs()
|
||||
fetchLogs() // 初次加载
|
||||
autoRefreshTimer = setInterval(() => {
|
||||
if (!isRunning.value) fetchLogs()
|
||||
}, 300000)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (autoRefreshTimer) clearInterval(autoRefreshTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -421,18 +406,12 @@ onMounted(() => {
|
||||
.status-idle { display: flex; align-items: center; gap: 5px; }
|
||||
.status-summary { margin: 15px 0; display: flex; gap: 10px; flex-wrap: wrap; }
|
||||
.toolbar { background: #fff; padding: 15px 20px; border-radius: 8px; display: flex; justify-content: space-between; margin-bottom: 20px; border: 1px solid #ebeef5; align-items: center; }
|
||||
.name-cell { display: flex; align-items: center; }
|
||||
:deep(.offline-row) { background-color: #fef0f0 !important; }
|
||||
.drawer-content { padding: 0 20px 20px; }
|
||||
.info-banner { margin-bottom: 20px; }
|
||||
.section-title { border-left: 4px solid #409EFF; padding-left: 10px; margin: 25px 0 15px; font-size: 18px; display: flex; align-items: center; gap: 8px; color: #303133; }
|
||||
.chart-container { margin-bottom: 30px; border: 1px solid #e4e7ed; border-radius: 8px; overflow: hidden; background: #fff; }
|
||||
.chart-header { background: #fafafa; padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e4e7ed; }
|
||||
.module-tag { font-weight: bold; color: #409EFF; font-size: 15px; }
|
||||
.sn-tag { font-size: 12px; color: #606266; background: #ecf5ff; padding: 3px 8px; border-radius: 4px; border: 1px solid #d9ecff; }
|
||||
.echart-box { width: 100%; height: 380px; }
|
||||
.echart-box.no-header { margin-top: 15px; }
|
||||
.empty-hint { text-align: center; padding: 50px; color: #909399; font-style: italic; background: #fff; border-radius: 8px; }
|
||||
|
||||
:deep(.el-drawer__header) { margin-bottom: 0; padding: 15px 20px; background: #303133; color: #fff !important; }
|
||||
:deep(.el-drawer__title) { color: #fff; font-weight: bold; }
|
||||
:deep(.el-drawer__close-btn) { color: #fff; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user