页面部分实现
This commit is contained in:
24
zhandianxinxi/my-vue-app/.gitignore
vendored
Normal file
24
zhandianxinxi/my-vue-app/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
3
zhandianxinxi/my-vue-app/.vscode/extensions.json
vendored
Normal file
3
zhandianxinxi/my-vue-app/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["Vue.volar"]
|
||||
}
|
||||
5
zhandianxinxi/my-vue-app/README.md
Normal file
5
zhandianxinxi/my-vue-app/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Vue 3 + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).
|
||||
13
zhandianxinxi/my-vue-app/index.html
Normal file
13
zhandianxinxi/my-vue-app/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>my-vue-app</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
2035
zhandianxinxi/my-vue-app/package-lock.json
generated
Normal file
2035
zhandianxinxi/my-vue-app/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
zhandianxinxi/my-vue-app/package.json
Normal file
21
zhandianxinxi/my-vue-app/package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "my-vue-app",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^3.3.4",
|
||||
"element-plus": "^2.3.14",
|
||||
"axios": "^1.5.1",
|
||||
"@element-plus/icons-vue": "^2.1.0",
|
||||
"vue-json-viewer": "^3.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "4.5.0",
|
||||
"@vitejs/plugin-vue": "4.5.0"
|
||||
}
|
||||
}
|
||||
1
zhandianxinxi/my-vue-app/public/vite.svg
Normal file
1
zhandianxinxi/my-vue-app/public/vite.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
289
zhandianxinxi/my-vue-app/src/App.vue
Normal file
289
zhandianxinxi/my-vue-app/src/App.vue
Normal file
@ -0,0 +1,289 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<el-card shadow="never" class="main-card">
|
||||
<template #header>
|
||||
<div class="header-row">
|
||||
<div class="left-panel">
|
||||
<h2 class="sys-title">📡 终端数据监控大屏</h2>
|
||||
<div class="sys-status">
|
||||
<span v-if="isRunning" class="status-running">
|
||||
<el-icon class="is-loading"><Loading /></el-icon> 正在与远程服务器同步数据...
|
||||
</span>
|
||||
<span v-else class="status-idle">
|
||||
<el-icon><CircleCheck /></el-icon> 数据已更新 ({{ lastUpdateTime }})
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<el-button type="primary" :loading="isRunning" @click="handleManualRefresh" round icon="Refresh">
|
||||
立即刷新同步
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="toolbar">
|
||||
<div class="filter-section">
|
||||
<el-radio-group v-model="filters.site" size="default">
|
||||
<el-radio-button label="all">全部来源</el-radio-button>
|
||||
<el-radio-button label="106">106 代理</el-radio-button>
|
||||
<el-radio-button label="82">82 气象站</el-radio-button>
|
||||
</el-radio-group>
|
||||
|
||||
<el-input
|
||||
v-model="filters.keyword"
|
||||
placeholder="搜索设备名称..."
|
||||
prefix-icon="Search"
|
||||
style="width: 220px; margin-left: 20px;"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="action-section">
|
||||
<el-checkbox v-model="showHidden" label="显示已屏蔽" border style="margin-right: 15px"/>
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
icon="Hide"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="hideSelectedDevices"
|
||||
>
|
||||
屏蔽选中 ({{ selectedRows.length }})
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
:data="sortedData"
|
||||
style="width: 100%; margin-top: 20px;"
|
||||
border
|
||||
stripe
|
||||
height="650"
|
||||
v-loading="isRunning"
|
||||
@selection-change="val => selectedRows = val"
|
||||
>
|
||||
<el-table-column type="selection" width="50" align="center" />
|
||||
|
||||
<el-table-column prop="source" label="来源" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag size="small" effect="plain">{{ scope.row.source }}</el-tag>
|
||||
</template>
|
||||
</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-tag v-if="isHidden(scope.row.name)" type="info" size="small" style="margin-left:8px">已屏蔽</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="运行状态" width="140" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="getStatusType(row)" effect="dark" round>
|
||||
{{ getStatusLabel(row) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column prop="reason" label="状态详情" min-width="200">
|
||||
<template #default="{ row }">
|
||||
<span :style="{ color: getStatusColor(row) }">
|
||||
{{ row.reason }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column prop="offset" label="数据时效" width="120" align="center" />
|
||||
|
||||
<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 }">
|
||||
<el-button v-if="isHidden(row.name)" type="info" link @click="restoreDevice(row.name)">恢复</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</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-drawer
|
||||
v-model="drawerVisible"
|
||||
title="设备数据详情"
|
||||
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="当前状态">
|
||||
<el-tag :type="getStatusType(activeDevice)">{{ getStatusLabel(activeDevice) }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="检测到最新时间">{{ activeDevice.latest_time }}</el-descriptions-item>
|
||||
<el-descriptions-item label="异常原因">{{ activeDevice.reason }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<h3 style="margin: 25px 0 10px 0;">📦 原始 JSON 数据报文</h3>
|
||||
<div class="json-container">
|
||||
<json-viewer
|
||||
v-if="parsedJson"
|
||||
:value="parsedJson"
|
||||
:expand-depth="5"
|
||||
copyable
|
||||
boxed
|
||||
sort
|
||||
/>
|
||||
<el-empty v-else description="该站点暂无详细 JSON 数据内容" />
|
||||
</div>
|
||||
</div>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
// --- 数据响应式变量 ---
|
||||
const rawData = ref([])
|
||||
const isRunning = ref(false)
|
||||
const lastUpdateTime = ref('-')
|
||||
const selectedRows = ref([])
|
||||
const showHidden = ref(false)
|
||||
const drawerVisible = ref(false)
|
||||
|
||||
// 初始值设为 null,模板中通过 v-if 保护
|
||||
const activeDevice = ref(null)
|
||||
|
||||
const filters = reactive({ site: 'all', keyword: '' })
|
||||
const ignoredDevices = ref(JSON.parse(localStorage.getItem('ignored_list') || '[]'))
|
||||
|
||||
// --- 逻辑处理 ---
|
||||
|
||||
const getStatusLevel = (row) => {
|
||||
if (!row || !row.reason) return 'success'
|
||||
if (row.reason.includes('离线') || row.reason.includes('失败')) return 'critical'
|
||||
if (row.offset && row.offset.includes('滞后')) return 'warning'
|
||||
return 'success'
|
||||
}
|
||||
|
||||
const getStatusType = (row) => {
|
||||
const level = getStatusLevel(row)
|
||||
return level === 'critical' ? 'danger' : (level === 'warning' ? 'warning' : 'success')
|
||||
}
|
||||
|
||||
const getStatusLabel = (row) => {
|
||||
const level = getStatusLevel(row)
|
||||
return level === 'critical' ? '连接异常' : (level === 'warning' ? '同步滞后' : '运行正常')
|
||||
}
|
||||
|
||||
const getStatusColor = (row) => {
|
||||
const level = getStatusLevel(row)
|
||||
return level === 'critical' ? '#F56C6C' : (level === 'warning' ? '#E6A23C' : '#606266')
|
||||
}
|
||||
|
||||
const isHidden = (name) => ignoredDevices.value.includes(name)
|
||||
|
||||
const sortedData = computed(() => {
|
||||
let list = rawData.value.filter(item => {
|
||||
const matchSite = filters.site === 'all' || item.source.includes(filters.site)
|
||||
const matchKey = !filters.keyword || item.name.toLowerCase().includes(filters.keyword.toLowerCase())
|
||||
const hideLogic = showHidden.value ? true : !isHidden(item.name)
|
||||
return matchSite && matchKey && hideLogic
|
||||
})
|
||||
return list.sort((a, b) => {
|
||||
const weight = { 'critical': 3, 'warning': 2, 'success': 1 }
|
||||
return weight[getStatusLevel(b)] - weight[getStatusLevel(a)]
|
||||
})
|
||||
})
|
||||
|
||||
const stats = computed(() => ({
|
||||
critical: rawData.value.filter(r => getStatusLevel(r) === 'critical').length,
|
||||
warning: rawData.value.filter(r => getStatusLevel(r) === 'warning').length
|
||||
}))
|
||||
|
||||
const parsedJson = computed(() => {
|
||||
if (!activeDevice.value || !activeDevice.value.content) return null
|
||||
try {
|
||||
return JSON.parse(activeDevice.value.content)
|
||||
} catch (e) {
|
||||
return activeDevice.value.content
|
||||
}
|
||||
})
|
||||
|
||||
// --- 交互方法 ---
|
||||
|
||||
const showDetails = (row) => {
|
||||
activeDevice.value = row
|
||||
drawerVisible.value = true
|
||||
}
|
||||
|
||||
const hideSelectedDevices = () => {
|
||||
const names = selectedRows.value.map(r => r.name)
|
||||
ignoredDevices.value = [...new Set([...ignoredDevices.value, ...names])]
|
||||
localStorage.setItem('ignored_list', JSON.stringify(ignoredDevices.value))
|
||||
ElMessage.success('已屏蔽选中设备')
|
||||
}
|
||||
|
||||
const restoreDevice = (name) => {
|
||||
ignoredDevices.value = ignoredDevices.value.filter(n => n !== name)
|
||||
localStorage.setItem('ignored_list', JSON.stringify(ignoredDevices.value))
|
||||
}
|
||||
|
||||
const fetchLogs = async () => {
|
||||
try {
|
||||
const res = await axios.get('/api/logs')
|
||||
rawData.value = res.data
|
||||
if (res.data.length > 0) lastUpdateTime.value = res.data[0].check_time
|
||||
} catch (e) {
|
||||
console.error("无法获取日志数据")
|
||||
}
|
||||
}
|
||||
|
||||
const checkStatus = async () => {
|
||||
try {
|
||||
const res = await axios.get('/api/status')
|
||||
isRunning.value = res.data.is_running
|
||||
if (isRunning.value) {
|
||||
setTimeout(checkStatus, 3000)
|
||||
} else {
|
||||
fetchLogs()
|
||||
}
|
||||
} catch (e) {
|
||||
isRunning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleManualRefresh = async () => {
|
||||
if (isRunning.value) return
|
||||
try {
|
||||
await axios.post('/api/run')
|
||||
isRunning.value = true
|
||||
checkStatus()
|
||||
} catch (e) {
|
||||
ElMessage.error('启动同步失败,请检查后端连接')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
checkStatus()
|
||||
fetchLogs()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container { padding: 20px; max-width: 1400px; margin: 0 auto; font-family: sans-serif; }
|
||||
.header-row { display: flex; justify-content: space-between; align-items: center; }
|
||||
.sys-title { margin: 0; color: #303133; }
|
||||
.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; }
|
||||
.device-link { font-weight: bold; }
|
||||
.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>
|
||||
1
zhandianxinxi/my-vue-app/src/assets/vue.svg
Normal file
1
zhandianxinxi/my-vue-app/src/assets/vue.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 496 B |
17
zhandianxinxi/my-vue-app/src/main.js
Normal file
17
zhandianxinxi/my-vue-app/src/main.js
Normal file
@ -0,0 +1,17 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
import JsonViewer from 'vue-json-viewer'
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
// 注册所有图标
|
||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
app.component(key, component)
|
||||
}
|
||||
|
||||
app.use(ElementPlus)
|
||||
app.use(JsonViewer)
|
||||
app.mount('#app')
|
||||
79
zhandianxinxi/my-vue-app/src/style.css
Normal file
79
zhandianxinxi/my-vue-app/src/style.css
Normal file
@ -0,0 +1,79 @@
|
||||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
16
zhandianxinxi/my-vue-app/vite.config.js
Normal file
16
zhandianxinxi/my-vue-app/vite.config.js
Normal file
@ -0,0 +1,16 @@
|
||||
// vite.config.js
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://127.0.0.1:5000', // 必须指向你的 Flask 地址
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path // 保持路径 /api 不变
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user