添加屏蔽设备以及82网站数据展示
This commit is contained in:
@ -15,7 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<el-button type="primary" :loading="isRunning" @click="handleManualRefresh" round icon="Refresh">
|
<el-button type="primary" :loading="isRunning" @click="handleManualRefresh" round icon="Refresh">
|
||||||
立即刷新同步
|
立即同步
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -23,121 +23,73 @@
|
|||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<div class="filter-section">
|
<div class="filter-section">
|
||||||
<el-radio-group v-model="filters.site" size="default">
|
<el-radio-group v-model="filters.site" size="default">
|
||||||
<el-radio-button label="all">全部来源</el-radio-button>
|
<el-radio-button label="all">全部</el-radio-button>
|
||||||
<el-radio-button label="106">106 代理</el-radio-button>
|
<el-radio-button label="106">106 代理</el-radio-button>
|
||||||
<el-radio-button label="82">82 气象站</el-radio-button>
|
<el-radio-button label="82">82 气象站</el-radio-button>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
|
<el-input v-model="filters.keyword" placeholder="搜索设备..." prefix-icon="Search" style="width: 200px; margin-left: 15px;" clearable />
|
||||||
<el-input
|
|
||||||
v-model="filters.keyword"
|
|
||||||
placeholder="搜索设备名称..."
|
|
||||||
prefix-icon="Search"
|
|
||||||
style="width: 220px; margin-left: 20px;"
|
|
||||||
clearable
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="action-section">
|
<div class="action-section">
|
||||||
<el-checkbox v-model="showHidden" label="显示已屏蔽" border style="margin-right: 15px"/>
|
<el-checkbox v-model="showHidden" label="显示屏蔽设备" border style="margin-right: 15px"/>
|
||||||
<el-button
|
<el-button type="warning" plain icon="Hide" :disabled="selectedRows.length === 0" @click="hideSelected">
|
||||||
type="warning"
|
批量屏蔽 ({{ selectedRows.length }})
|
||||||
plain
|
|
||||||
icon="Hide"
|
|
||||||
:disabled="selectedRows.length === 0"
|
|
||||||
@click="hideSelectedDevices"
|
|
||||||
>
|
|
||||||
屏蔽选中 ({{ selectedRows.length }})
|
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-table
|
<el-table
|
||||||
:data="sortedData"
|
:data="sortedData"
|
||||||
style="width: 100%; margin-top: 20px;"
|
|
||||||
border
|
border
|
||||||
stripe
|
stripe
|
||||||
height="650"
|
height="650"
|
||||||
v-loading="isRunning"
|
style="width: 100%; margin-top: 15px;"
|
||||||
@selection-change="val => selectedRows = val"
|
@selection-change="val => selectedRows = val"
|
||||||
|
v-loading="isRunning"
|
||||||
>
|
>
|
||||||
<el-table-column type="selection" width="50" align="center" />
|
<el-table-column type="selection" width="50" align="center" />
|
||||||
|
<el-table-column prop="source" label="来源" width="100" />
|
||||||
<el-table-column prop="source" label="来源" width="100" align="center">
|
<el-table-column label="设备名称" min-width="200">
|
||||||
<template #default="scope">
|
<template #default="{ row }">
|
||||||
<el-tag size="small" effect="plain">{{ scope.row.source }}</el-tag>
|
<el-link type="primary" :underline="false" @click="showDetails(row)" style="font-weight: bold;">
|
||||||
</template>
|
{{ row.name }}
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
<el-table-column label="设备名称" min-width="220">
|
|
||||||
<template #default="scope">
|
|
||||||
<el-link type="primary" :underline="false" @click="showDetails(scope.row)" class="device-link">
|
|
||||||
{{ scope.row.name }}
|
|
||||||
</el-link>
|
</el-link>
|
||||||
<el-tag v-if="isHidden(scope.row.name)" type="info" size="small" style="margin-left:8px">已屏蔽</el-tag>
|
<el-tag v-if="isHidden(row.name)" type="info" size="small" style="margin-left:8px">已屏蔽</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" width="120" align="center">
|
||||||
<el-table-column label="运行状态" width="140" align="center">
|
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="getStatusType(row)" effect="dark" round>
|
<el-tag :type="getStatusType(row)" effect="dark">{{ getStatusLabel(row) }}</el-tag>
|
||||||
{{ getStatusLabel(row) }}
|
|
||||||
</el-tag>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column prop="reason" label="详情信息">
|
||||||
<el-table-column prop="reason" label="状态详情" min-width="200">
|
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<span :style="{ color: getStatusColor(row) }">
|
<span :style="{ color: getStatusColor(row) }">{{ row.reason }}</span>
|
||||||
{{ row.reason }}
|
|
||||||
</span>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column prop="offset" label="数据时效" width="120" />
|
||||||
<el-table-column prop="offset" label="数据时效" width="120" align="center" />
|
<el-table-column prop="latest_time" label="最后同步日期" width="170" />
|
||||||
|
<el-table-column label="管理" width="90" align="center" v-if="showHidden">
|
||||||
<el-table-column prop="latest_time" label="最新日期" width="160" align="center" />
|
|
||||||
|
|
||||||
<el-table-column label="管理" width="100" align="center" v-if="showHidden">
|
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-button v-if="isHidden(row.name)" type="info" link @click="restoreDevice(row.name)">恢复</el-button>
|
<el-button v-if="isHidden(row.name)" type="success" link @click="restoreDevice(row.name)">恢复</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
|
||||||
<div class="footer-stats">
|
|
||||||
<span>总监控: {{ rawData.length }}</span> |
|
|
||||||
<span style="color: #F56C6C">严重问题: {{ stats.critical }}</span> |
|
|
||||||
<span style="color: #E6A23C">滞后警告: {{ stats.warning }}</span>
|
|
||||||
</div>
|
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
<el-drawer
|
<el-drawer v-model="drawerVisible" title="原始数据快照" size="45%" destroy-on-close>
|
||||||
v-model="drawerVisible"
|
<div v-if="activeDevice" style="padding: 10px">
|
||||||
title="设备数据详情"
|
<el-descriptions :title="'站点:' + activeDevice.name" :column="1" border>
|
||||||
size="45%"
|
|
||||||
destroy-on-close
|
|
||||||
>
|
|
||||||
<div v-if="activeDevice" class="drawer-content">
|
|
||||||
<el-descriptions :title="`站点名称:${activeDevice.name}`" :column="1" border>
|
|
||||||
<el-descriptions-item label="所属来源">{{ activeDevice.source }}</el-descriptions-item>
|
<el-descriptions-item label="所属来源">{{ activeDevice.source }}</el-descriptions-item>
|
||||||
<el-descriptions-item label="当前状态">
|
<el-descriptions-item label="最后更新">{{ activeDevice.latest_time }}</el-descriptions-item>
|
||||||
<el-tag :type="getStatusType(activeDevice)">{{ getStatusLabel(activeDevice) }}</el-tag>
|
<el-descriptions-item label="时效状态">
|
||||||
|
<el-tag :type="getStatusType(activeDevice)">{{ activeDevice.offset }}</el-tag>
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
<el-descriptions-item label="检测到最新时间">{{ activeDevice.latest_time }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="异常原因">{{ activeDevice.reason }}</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
|
<h3 style="margin-top:20px">📦 JSON 数据报文</h3>
|
||||||
<h3 style="margin: 25px 0 10px 0;">📦 原始 JSON 数据报文</h3>
|
<div class="json-box">
|
||||||
<div class="json-container">
|
<json-viewer v-if="parsedJson" :value="parsedJson" copyable boxed expand-depth="4" />
|
||||||
<json-viewer
|
<el-empty v-else description="无 JSON 详情内容" />
|
||||||
v-if="parsedJson"
|
|
||||||
:value="parsedJson"
|
|
||||||
:expand-depth="5"
|
|
||||||
copyable
|
|
||||||
boxed
|
|
||||||
sort
|
|
||||||
/>
|
|
||||||
<el-empty v-else description="该站点暂无详细 JSON 数据内容" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
@ -149,141 +101,111 @@ import { ref, reactive, computed, onMounted } from 'vue'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
// --- 数据响应式变量 ---
|
|
||||||
const rawData = ref([])
|
const rawData = ref([])
|
||||||
const isRunning = ref(false)
|
const isRunning = ref(false)
|
||||||
const lastUpdateTime = ref('-')
|
const lastUpdateTime = ref('-')
|
||||||
const selectedRows = ref([])
|
const selectedRows = ref([])
|
||||||
const showHidden = ref(false)
|
const showHidden = ref(false)
|
||||||
const drawerVisible = ref(false)
|
const drawerVisible = ref(false)
|
||||||
|
|
||||||
// 初始值设为 null,模板中通过 v-if 保护
|
|
||||||
const activeDevice = ref(null)
|
const activeDevice = ref(null)
|
||||||
|
|
||||||
const filters = reactive({ site: 'all', keyword: '' })
|
const filters = reactive({ site: 'all', keyword: '' })
|
||||||
const ignoredDevices = ref(JSON.parse(localStorage.getItem('ignored_list') || '[]'))
|
const ignoredList = ref(JSON.parse(localStorage.getItem('hide_devices') || '[]'))
|
||||||
|
|
||||||
// --- 逻辑处理 ---
|
// --- 颜色与级别核心逻辑 ---
|
||||||
|
const getLevel = (row) => {
|
||||||
|
if (row.reason.includes('离线') || row.reason.includes('错误')) return 3 // Danger
|
||||||
|
if (!row.latest_time || row.latest_time === 'N/A') return 3
|
||||||
|
|
||||||
const getStatusLevel = (row) => {
|
try {
|
||||||
if (!row || !row.reason) return 'success'
|
const last = new Date(row.latest_time.split(' ')[0].replace(/_/g, '-'))
|
||||||
if (row.reason.includes('离线') || row.reason.includes('失败')) return 'critical'
|
const diff = (new Date() - last) / (1000 * 3600 * 24)
|
||||||
if (row.offset && row.offset.includes('滞后')) return 'warning'
|
if (diff > 3) return 3 // 红色
|
||||||
return 'success'
|
if (diff > 1) return 2 // 黄色
|
||||||
|
return 1 // 绿色
|
||||||
|
} catch { return 3 }
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStatusType = (row) => {
|
const getStatusType = (row) => {
|
||||||
const level = getStatusLevel(row)
|
const lv = getLevel(row)
|
||||||
return level === 'critical' ? 'danger' : (level === 'warning' ? 'warning' : 'success')
|
return lv === 3 ? 'danger' : (lv === 2 ? 'warning' : 'success')
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStatusLabel = (row) => {
|
const getStatusLabel = (row) => {
|
||||||
const level = getStatusLevel(row)
|
const lv = getLevel(row)
|
||||||
return level === 'critical' ? '连接异常' : (level === 'warning' ? '同步滞后' : '运行正常')
|
return lv === 3 ? '严重异常' : (lv === 2 ? '数据滞后' : '运行同步')
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStatusColor = (row) => {
|
const getStatusColor = (row) => {
|
||||||
const level = getStatusLevel(row)
|
const lv = getLevel(row)
|
||||||
return level === 'critical' ? '#F56C6C' : (level === 'warning' ? '#E6A23C' : '#606266')
|
return lv === 3 ? '#F56C6C' : (lv === 2 ? '#E6A23C' : '#67C23A')
|
||||||
}
|
}
|
||||||
|
|
||||||
const isHidden = (name) => ignoredDevices.value.includes(name)
|
// --- 排序与过滤 ---
|
||||||
|
const isHidden = (name) => ignoredList.value.includes(name)
|
||||||
|
|
||||||
const sortedData = computed(() => {
|
const sortedData = computed(() => {
|
||||||
let list = rawData.value.filter(item => {
|
let list = rawData.value.filter(item => {
|
||||||
const matchSite = filters.site === 'all' || item.source.includes(filters.site)
|
const mSite = filters.site === 'all' || item.source.includes(filters.site)
|
||||||
const matchKey = !filters.keyword || item.name.toLowerCase().includes(filters.keyword.toLowerCase())
|
const mKey = item.name.toLowerCase().includes(filters.keyword.toLowerCase())
|
||||||
const hideLogic = showHidden.value ? true : !isHidden(item.name)
|
const mHide = showHidden.value ? true : !isHidden(item.name)
|
||||||
return matchSite && matchKey && hideLogic
|
return mSite && mKey && mHide
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 按照危险程度排序 (3级排最前),同级按时间排序
|
||||||
return list.sort((a, b) => {
|
return list.sort((a, b) => {
|
||||||
const weight = { 'critical': 3, 'warning': 2, 'success': 1 }
|
const lvA = getLevel(a), lvB = getLevel(b)
|
||||||
return weight[getStatusLevel(b)] - weight[getStatusLevel(a)]
|
if (lvA !== lvB) return lvB - lvA
|
||||||
|
return b.latest_time.localeCompare(a.latest_time)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const stats = computed(() => ({
|
// --- 交互 ---
|
||||||
critical: rawData.value.filter(r => getStatusLevel(r) === 'critical').length,
|
const showDetails = (row) => { activeDevice.value = row; drawerVisible.value = true }
|
||||||
warning: rawData.value.filter(r => getStatusLevel(r) === 'warning').length
|
|
||||||
}))
|
|
||||||
|
|
||||||
const parsedJson = computed(() => {
|
const parsedJson = computed(() => {
|
||||||
if (!activeDevice.value || !activeDevice.value.content) return null
|
if (!activeDevice.value?.content) return null
|
||||||
try {
|
try { return JSON.parse(activeDevice.value.content) } catch { return activeDevice.value.content }
|
||||||
return JSON.parse(activeDevice.value.content)
|
|
||||||
} catch (e) {
|
|
||||||
return activeDevice.value.content
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// --- 交互方法 ---
|
const hideSelected = () => {
|
||||||
|
|
||||||
const showDetails = (row) => {
|
|
||||||
activeDevice.value = row
|
|
||||||
drawerVisible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
const hideSelectedDevices = () => {
|
|
||||||
const names = selectedRows.value.map(r => r.name)
|
const names = selectedRows.value.map(r => r.name)
|
||||||
ignoredDevices.value = [...new Set([...ignoredDevices.value, ...names])]
|
ignoredList.value = [...new Set([...ignoredList.value, ...names])]
|
||||||
localStorage.setItem('ignored_list', JSON.stringify(ignoredDevices.value))
|
localStorage.setItem('hide_devices', JSON.stringify(ignoredList.value))
|
||||||
ElMessage.success('已屏蔽选中设备')
|
ElMessage.warning('设备已屏蔽')
|
||||||
}
|
}
|
||||||
|
|
||||||
const restoreDevice = (name) => {
|
const restoreDevice = (name) => {
|
||||||
ignoredDevices.value = ignoredDevices.value.filter(n => n !== name)
|
ignoredList.value = ignoredList.value.filter(n => n !== name)
|
||||||
localStorage.setItem('ignored_list', JSON.stringify(ignoredDevices.value))
|
localStorage.setItem('hide_devices', JSON.stringify(ignoredList.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchLogs = async () => {
|
const fetchLogs = async () => {
|
||||||
try {
|
const res = await axios.get('/api/logs')
|
||||||
const res = await axios.get('/api/logs')
|
rawData.value = res.data
|
||||||
rawData.value = res.data
|
if (res.data.length > 0) lastUpdateTime.value = res.data[0].check_time
|
||||||
if (res.data.length > 0) lastUpdateTime.value = res.data[0].check_time
|
|
||||||
} catch (e) {
|
|
||||||
console.error("无法获取日志数据")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkStatus = async () => {
|
const checkStatus = async () => {
|
||||||
try {
|
const res = await axios.get('/api/status')
|
||||||
const res = await axios.get('/api/status')
|
isRunning.value = res.data.is_running
|
||||||
isRunning.value = res.data.is_running
|
if (isRunning.value) setTimeout(checkStatus, 2000)
|
||||||
if (isRunning.value) {
|
else fetchLogs()
|
||||||
setTimeout(checkStatus, 3000)
|
|
||||||
} else {
|
|
||||||
fetchLogs()
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
isRunning.value = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleManualRefresh = async () => {
|
const handleManualRefresh = async () => {
|
||||||
if (isRunning.value) return
|
await axios.post('/api/run')
|
||||||
try {
|
isRunning.value = true
|
||||||
await axios.post('/api/run')
|
checkStatus()
|
||||||
isRunning.value = true
|
|
||||||
checkStatus()
|
|
||||||
} catch (e) {
|
|
||||||
ElMessage.error('启动同步失败,请检查后端连接')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => { checkStatus(); fetchLogs() })
|
||||||
checkStatus()
|
|
||||||
fetchLogs()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.container { padding: 20px; max-width: 1400px; margin: 0 auto; font-family: sans-serif; }
|
.container { padding: 20px; max-width: 1500px; margin: 0 auto; }
|
||||||
.header-row { display: flex; justify-content: space-between; align-items: center; }
|
.header-row { display: flex; justify-content: space-between; align-items: center; }
|
||||||
.sys-title { margin: 0; color: #303133; }
|
.sys-title { margin:0; }
|
||||||
.sys-status { font-size: 13px; color: #909399; margin-top: 5px; }
|
.sys-status { font-size:13px; color:#909399; margin-top:5px; }
|
||||||
.toolbar { background: #f8f9fa; padding: 15px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; margin-top: 20px; border: 1px solid #ebeef5; }
|
.toolbar { background:#f9f9f9; padding:15px; border-radius:8px; display:flex; justify-content:space-between; margin-top:20px; border:1px solid #eee; }
|
||||||
.device-link { font-weight: bold; }
|
.json-box { border:1px solid #eee; background:#fafafa; border-radius:4px; }
|
||||||
.footer-stats { margin-top: 20px; text-align: right; color: #606266; font-size: 14px; }
|
|
||||||
.json-container { border: 1px solid #eee; border-radius: 4px; overflow: hidden; }
|
|
||||||
.drawer-content { padding: 0 5px; }
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user