修复两个网站json展示问题
This commit is contained in:
Binary file not shown.
118
1.1/test1.py
118
1.1/test1.py
@ -46,10 +46,12 @@ CONFIG = {
|
|||||||
is_running = False
|
is_running = False
|
||||||
|
|
||||||
|
|
||||||
|
# --- 通用工具函数 ---
|
||||||
def add_error_to_db(source, name, reason, latest_time="N/A", content=None):
|
def add_error_to_db(source, name, reason, latest_time="N/A", content=None):
|
||||||
days_diff = "N/A"
|
days_diff = "N/A"
|
||||||
if latest_time and latest_time != "N/A":
|
if latest_time and latest_time != "N/A":
|
||||||
try:
|
try:
|
||||||
|
# 兼容 2024_05_20 和 2024-05-20 两种格式
|
||||||
clean_date_str = str(latest_time).split()[0].replace('_', '-')
|
clean_date_str = str(latest_time).split()[0].replace('_', '-')
|
||||||
target_date = datetime.strptime(clean_date_str, "%Y-%m-%d").date()
|
target_date = datetime.strptime(clean_date_str, "%Y-%m-%d").date()
|
||||||
diff = (datetime.now().date() - target_date).days
|
diff = (datetime.now().date() - target_date).days
|
||||||
@ -65,39 +67,119 @@ def add_error_to_db(source, name, reason, latest_time="N/A", content=None):
|
|||||||
db.session.add(log)
|
db.session.add(log)
|
||||||
|
|
||||||
|
|
||||||
# --- 106 逻辑 ---
|
# --- 106 专用辅助函数 ---
|
||||||
def get_106_token(port):
|
def get_106_dynamic_token(port):
|
||||||
|
login_url = f"http://106.75.72.40:{port}/api/login"
|
||||||
try:
|
try:
|
||||||
resp = requests.post(f"http://106.75.72.40:{port}/api/login", json=CONFIG["106"]["login_payload"], timeout=5)
|
resp = requests.post(login_url, json=CONFIG["106"]["login_payload"], timeout=10)
|
||||||
return resp.text.strip().replace('"', '') if resp.status_code == 200 else None
|
if resp.status_code == 200:
|
||||||
|
return resp.text.strip().replace('"', '')
|
||||||
|
return None
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def find_closest_item(items, is_date_level=True):
|
||||||
|
if not items or not isinstance(items, list): return None
|
||||||
|
today = datetime.now()
|
||||||
|
scored_items = []
|
||||||
|
for item in items:
|
||||||
|
name_val = item.get('name', '')
|
||||||
|
path_val = item.get('path', '')
|
||||||
|
target_str = name_val if name_val else path_val.split('/')[-1]
|
||||||
|
try:
|
||||||
|
if is_date_level:
|
||||||
|
current_date = datetime.strptime(target_str, "%Y_%m_%d")
|
||||||
|
else:
|
||||||
|
mod_str = item.get('modified', '')
|
||||||
|
current_date = datetime.fromisoformat(mod_str.replace('Z', '+00:00'))
|
||||||
|
diff = abs((today - current_date.replace(tzinfo=None)).total_seconds())
|
||||||
|
scored_items.append((diff, item, target_str))
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
if not scored_items: return None
|
||||||
|
scored_items.sort(key=lambda x: x[0])
|
||||||
|
return scored_items[0]
|
||||||
|
|
||||||
|
|
||||||
|
# --- 106 核心采集逻辑 ---
|
||||||
def run_106_logic():
|
def run_106_logic():
|
||||||
c = CONFIG["106"]
|
c = CONFIG["106"]
|
||||||
today_str = datetime.now().strftime("%Y_%m_%d")
|
today_str = datetime.now().strftime("%Y_%m_%d")
|
||||||
|
main_headers = {"Authorization": c["primary_auth"], "User-Agent": "Mozilla/5.0"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = requests.get(c["base_url"], headers={"Authorization": c["primary_auth"]}, timeout=10)
|
resp = requests.get(c["base_url"], headers=main_headers, timeout=15)
|
||||||
for item in resp.json().get('proxies', []):
|
proxies = resp.json().get('proxies', [])
|
||||||
|
|
||||||
|
for item in proxies:
|
||||||
name = item.get('name', '')
|
name = item.get('name', '')
|
||||||
|
# 严格过滤
|
||||||
if not name.lower().endswith('_data'): continue
|
if not name.lower().endswith('_data'): continue
|
||||||
|
name_upper = name.upper()
|
||||||
|
is_tower_underscore = "TOWER_" in name_upper
|
||||||
|
is_tower_i = "TOWER" in name_upper and not is_tower_underscore
|
||||||
|
if not (is_tower_underscore or is_tower_i): continue
|
||||||
|
|
||||||
|
# 状态检查
|
||||||
if str(item.get('status')).lower() != 'online':
|
if str(item.get('status')).lower() != 'online':
|
||||||
add_error_to_db("106网站", name, f"离线({item.get('status')})")
|
add_error_to_db("106网站", name, f"离线({item.get('status')})")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 此处应包含 106 具体的 JSON 内容爬取逻辑,拿到 content 字符串
|
try:
|
||||||
# 示例:add_error_to_db("106网站", name, "运行正常", today_str, content=raw_json_str)
|
port = item.get('conf', {}).get('remote_port')
|
||||||
add_error_to_db("106网站", name, "同步成功", today_str, content='{"info": "106数据报文示例"}')
|
token = get_106_dynamic_token(port)
|
||||||
|
if not token:
|
||||||
|
add_error_to_db("106网站", name, "Token获取失败")
|
||||||
|
continue
|
||||||
|
|
||||||
|
headers = {"Authorization": c["primary_auth"], "x-auth": token, "User-Agent": "Mozilla/5.0"}
|
||||||
|
api_root = "/api/resources/Data/" if is_tower_underscore else "/api/resources/data/"
|
||||||
|
|
||||||
|
# Step 1: 寻找日期目录
|
||||||
|
res1 = requests.get(f"http://106.75.72.40:{port}{api_root}", headers=headers, timeout=10)
|
||||||
|
best_date = find_closest_item(res1.json().get('items', []), is_date_level=True)
|
||||||
|
|
||||||
|
if not best_date or best_date[2] != today_str:
|
||||||
|
add_error_to_db("106网站", name, "未找到今日文件夹", best_date[2] if best_date else "无")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Step 2: 寻找最新文件
|
||||||
|
date_path = f"{api_root}{best_date[2]}/"
|
||||||
|
res2 = requests.get(f"http://106.75.72.40:{port}{date_path}", headers=headers, timeout=10)
|
||||||
|
best_file = find_closest_item(res2.json().get('items', []), is_date_level=False)
|
||||||
|
|
||||||
|
if not best_file:
|
||||||
|
add_error_to_db("106网站", name, "文件夹内无文件", today_str)
|
||||||
|
continue
|
||||||
|
|
||||||
|
file_item = best_file[1]
|
||||||
|
full_path = file_item.get('path') or f"{date_path}{file_item.get('name')}"
|
||||||
|
|
||||||
|
# Step 3: 获取内容
|
||||||
|
final_content = ""
|
||||||
|
if is_tower_i:
|
||||||
|
download_url = f"http://106.75.72.40:{port}/api/raw{full_path}"
|
||||||
|
res3 = requests.get(download_url, headers=headers, timeout=20)
|
||||||
|
final_content = f"Binary Data Size: {len(res3.content)}"
|
||||||
|
else:
|
||||||
|
file_api_url = f"http://106.75.72.40:{port}/api/resources{full_path}"
|
||||||
|
res3 = requests.get(file_api_url, headers=headers, timeout=20)
|
||||||
|
final_content = res3.json().get('content', '')
|
||||||
|
|
||||||
|
add_error_to_db("106网站", name, "同步成功", today_str, content=final_content)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
add_error_to_db("106网站", name, f"采集异常: {str(e)}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
add_error_to_db("106网站", "全局错误", str(e))
|
add_error_to_db("106网站", "全局错误", str(e))
|
||||||
|
|
||||||
|
|
||||||
# --- 82 逻辑 ---
|
# --- 82 逻辑 (保持不变) ---
|
||||||
def run_82_logic():
|
def run_82_logic():
|
||||||
c = CONFIG["82"]
|
c = CONFIG["82"]
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
today_fmt = datetime.now().strftime("%Y-%m-%d")
|
|
||||||
try:
|
try:
|
||||||
session.post(f"{c['base_url']}/login.php", data=c["login"], timeout=10)
|
session.post(f"{c['base_url']}/login.php", data=c["login"], timeout=10)
|
||||||
resp = session.post(f"{c['base_url']}/GetStationList.php", timeout=10)
|
resp = session.post(f"{c['base_url']}/GetStationList.php", timeout=10)
|
||||||
@ -117,10 +199,11 @@ def run_82_logic():
|
|||||||
add_error_to_db("82网站", "初始化错误", str(e))
|
add_error_to_db("82网站", "初始化错误", str(e))
|
||||||
|
|
||||||
|
|
||||||
|
# --- Flask 路由 ---
|
||||||
def background_task():
|
def background_task():
|
||||||
global is_running
|
global is_running
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
ErrorLog.query.delete()
|
ErrorLog.query.delete() # 每次开始前清理旧日志
|
||||||
run_106_logic()
|
run_106_logic()
|
||||||
run_82_logic()
|
run_82_logic()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@ -143,8 +226,15 @@ def status(): return jsonify({"is_running": is_running})
|
|||||||
@app.route('/api/logs')
|
@app.route('/api/logs')
|
||||||
def logs():
|
def logs():
|
||||||
data = ErrorLog.query.all()
|
data = ErrorLog.query.all()
|
||||||
return jsonify([{"source": l.source, "name": l.name, "reason": l.reason, "offset": l.offset,
|
return jsonify([{
|
||||||
"latest_time": l.latest_time, "check_time": l.check_time, "content": l.content} for l in data])
|
"source": l.source,
|
||||||
|
"name": l.name,
|
||||||
|
"reason": l.reason,
|
||||||
|
"offset": l.offset,
|
||||||
|
"latest_time": l.latest_time,
|
||||||
|
"check_time": l.check_time,
|
||||||
|
"content": l.content
|
||||||
|
} for l in data])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -4,92 +4,74 @@
|
|||||||
<template #header>
|
<template #header>
|
||||||
<div class="header-row">
|
<div class="header-row">
|
||||||
<div class="left-panel">
|
<div class="left-panel">
|
||||||
<h2 class="sys-title">📡 终端数据监控大屏</h2>
|
<h2 class="sys-title">📡 数据同步大屏</h2>
|
||||||
<div class="sys-status">
|
<div class="sys-status">
|
||||||
<span v-if="isRunning" class="status-running">
|
<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>
|
||||||
<span v-else class="status-idle">
|
<span v-else class="status-idle">
|
||||||
<el-icon><CircleCheck /></el-icon> 数据已更新 ({{ lastUpdateTime }})
|
<el-icon><CircleCheck /></el-icon> 状态: 待命 (更新于: {{ lastUpdateTime }})
|
||||||
</span>
|
</span>
|
||||||
</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>
|
||||||
|
|
||||||
<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">
|
||||||
<el-radio-button label="all">全部</el-radio-button>
|
<el-radio-button value="all">全部</el-radio-button>
|
||||||
<el-radio-button label="106">106 代理</el-radio-button>
|
<el-radio-button value="106">106 代理</el-radio-button>
|
||||||
<el-radio-button label="82">82 气象站</el-radio-button>
|
<el-radio-button value="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="搜索..." style="width: 200px; margin-left: 15px;" 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: 10px"/>
|
||||||
<el-button type="warning" plain icon="Hide" :disabled="selectedRows.length === 0" @click="hideSelected">
|
<el-button type="warning" plain :disabled="selectedRows.length === 0" @click="hideSelected">屏蔽选中</el-button>
|
||||||
批量屏蔽 ({{ selectedRows.length }})
|
|
||||||
</el-button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-table
|
<el-table :data="sortedData" border height="600" v-loading="isRunning" @selection-change="val => selectedRows = val">
|
||||||
:data="sortedData"
|
|
||||||
border
|
|
||||||
stripe
|
|
||||||
height="650"
|
|
||||||
style="width: 100%; margin-top: 15px;"
|
|
||||||
@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" />
|
||||||
<el-table-column label="设备名称" min-width="200">
|
<el-table-column label="名称" min-width="180">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-link type="primary" :underline="false" @click="showDetails(row)" style="font-weight: bold;">
|
<el-link type="primary" underline="hover" @click="showDetails(row)" style="font-weight: bold;">{{ row.name }}</el-link>
|
||||||
{{ row.name }}
|
<el-tag v-if="isHidden(row.name)" type="info" size="small" style="margin-left:5px">隐藏</el-tag>
|
||||||
</el-link>
|
|
||||||
<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="100" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="getStatusType(row)" effect="dark">{{ getStatusLabel(row) }}</el-tag>
|
<el-tag :type="getStatusType(row)" effect="dark">{{ getStatusLabel(row) }}</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="reason" label="详情信息">
|
<el-table-column prop="reason" label="详情">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<span :style="{ color: getStatusColor(row) }">{{ row.reason }}</span>
|
<span :style="{ color: getStatusColor(row) }">{{ 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="100" />
|
||||||
<el-table-column prop="latest_time" label="最后同步日期" width="170" />
|
<el-table-column prop="latest_time" label="同步日期" width="160" />
|
||||||
<el-table-column label="管理" width="90" align="center" v-if="showHidden">
|
<el-table-column label="管理" width="80" v-if="showHidden">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-button v-if="isHidden(row.name)" type="success" link @click="restoreDevice(row.name)">恢复</el-button>
|
<el-button type="primary" link @click="restoreDevice(row.name)">恢复</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
<el-drawer v-model="drawerVisible" title="原始数据快照" size="45%" destroy-on-close>
|
<el-drawer v-model="drawerVisible" title="报文详情" size="45%">
|
||||||
<div v-if="activeDevice" style="padding: 10px">
|
<div v-if="activeDevice" style="padding: 15px">
|
||||||
<el-descriptions :title="'站点:' + activeDevice.name" :column="1" border>
|
<el-descriptions :column="1" border>
|
||||||
<el-descriptions-item label="所属来源">{{ activeDevice.source }}</el-descriptions-item>
|
<el-descriptions-item label="名称">{{ activeDevice.name }}</el-descriptions-item>
|
||||||
<el-descriptions-item label="最后更新">{{ activeDevice.latest_time }}</el-descriptions-item>
|
<el-descriptions-item label="同步日期">{{ activeDevice.latest_time }}</el-descriptions-item>
|
||||||
<el-descriptions-item label="时效状态">
|
|
||||||
<el-tag :type="getStatusType(activeDevice)">{{ activeDevice.offset }}</el-tag>
|
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
<h3 style="margin-top:20px">📦 JSON 数据报文</h3>
|
<h3 style="margin-top:20px">📦 原始数据</h3>
|
||||||
<div class="json-box">
|
<div class="json-box">
|
||||||
<json-viewer v-if="parsedJson" :value="parsedJson" copyable boxed expand-depth="4" />
|
<json-viewer v-if="parsedData" :value="parsedData" copyable boxed expand-depth="4" />
|
||||||
<el-empty v-else description="无 JSON 详情内容" />
|
<el-empty v-else description="内容为空" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
@ -99,113 +81,65 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, computed, onMounted } from 'vue'
|
import { ref, reactive, computed, onMounted } from 'vue'
|
||||||
import axios from 'axios'
|
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)
|
|
||||||
const activeDevice = ref(null)
|
|
||||||
|
|
||||||
|
const rawData = ref([]); const isRunning = ref(false); const lastUpdateTime = ref('-')
|
||||||
|
const selectedRows = ref([]); const showHidden = ref(false); const drawerVisible = ref(false); const activeDevice = ref(null)
|
||||||
const filters = reactive({ site: 'all', keyword: '' })
|
const filters = reactive({ site: 'all', keyword: '' })
|
||||||
const ignoredList = ref(JSON.parse(localStorage.getItem('hide_devices') || '[]'))
|
const ignoredList = ref(JSON.parse(localStorage.getItem('hide_list') || '[]'))
|
||||||
|
|
||||||
// --- 颜色与级别核心逻辑 ---
|
|
||||||
const getLevel = (row) => {
|
const getLevel = (row) => {
|
||||||
if (row.reason.includes('离线') || row.reason.includes('错误')) return 3 // Danger
|
if (row.reason.includes('离线') || row.reason.includes('失败')) return 3
|
||||||
if (!row.latest_time || row.latest_time === 'N/A') return 3
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const last = new Date(row.latest_time.split(' ')[0].replace(/_/g, '-'))
|
const last = new Date(row.latest_time.split(' ')[0].replace(/_/g, '-'))
|
||||||
const diff = (new Date() - last) / (1000 * 3600 * 24)
|
const diff = (new Date() - last) / (1000 * 3600 * 24)
|
||||||
if (diff > 3) return 3 // 红色
|
return diff > 3 ? 3 : (diff > 1 ? 2 : 1)
|
||||||
if (diff > 1) return 2 // 黄色
|
|
||||||
return 1 // 绿色
|
|
||||||
} catch { return 3 }
|
} catch { return 3 }
|
||||||
}
|
}
|
||||||
|
const getStatusType = (row) => ['','success','warning','danger'][getLevel(row)]
|
||||||
const getStatusType = (row) => {
|
const getStatusLabel = (row) => ['','正常','滞后','异常'][getLevel(row)]
|
||||||
const lv = getLevel(row)
|
const getStatusColor = (row) => ['','#67C23A','#E6A23C','#F56C6C'][getLevel(row)]
|
||||||
return lv === 3 ? 'danger' : (lv === 2 ? 'warning' : 'success')
|
|
||||||
}
|
|
||||||
|
|
||||||
const getStatusLabel = (row) => {
|
|
||||||
const lv = getLevel(row)
|
|
||||||
return lv === 3 ? '严重异常' : (lv === 2 ? '数据滞后' : '运行同步')
|
|
||||||
}
|
|
||||||
|
|
||||||
const getStatusColor = (row) => {
|
|
||||||
const lv = getLevel(row)
|
|
||||||
return lv === 3 ? '#F56C6C' : (lv === 2 ? '#E6A23C' : '#67C23A')
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 排序与过滤 ---
|
|
||||||
const isHidden = (name) => ignoredList.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(d => {
|
||||||
const mSite = filters.site === 'all' || item.source.includes(filters.site)
|
const sMatch = filters.site === 'all' || d.source.includes(filters.site)
|
||||||
const mKey = item.name.toLowerCase().includes(filters.keyword.toLowerCase())
|
const kMatch = d.name.toLowerCase().includes(filters.keyword.toLowerCase())
|
||||||
const mHide = showHidden.value ? true : !isHidden(item.name)
|
return sMatch && kMatch && (showHidden.value || !isHidden(d.name))
|
||||||
return mSite && mKey && mHide
|
|
||||||
})
|
|
||||||
|
|
||||||
// 按照危险程度排序 (3级排最前),同级按时间排序
|
|
||||||
return list.sort((a, b) => {
|
|
||||||
const lvA = getLevel(a), lvB = getLevel(b)
|
|
||||||
if (lvA !== lvB) return lvB - lvA
|
|
||||||
return b.latest_time.localeCompare(a.latest_time)
|
|
||||||
})
|
})
|
||||||
|
return list.sort((a, b) => getLevel(b) - getLevel(a))
|
||||||
})
|
})
|
||||||
|
|
||||||
// --- 交互 ---
|
|
||||||
const showDetails = (row) => { activeDevice.value = row; drawerVisible.value = true }
|
const showDetails = (row) => { activeDevice.value = row; drawerVisible.value = true }
|
||||||
const parsedJson = computed(() => {
|
const parsedData = computed(() => {
|
||||||
if (!activeDevice.value?.content) return null
|
if (!activeDevice.value?.content) return null
|
||||||
try { return JSON.parse(activeDevice.value.content) } catch { return activeDevice.value.content }
|
try { return JSON.parse(activeDevice.value.content) } catch { return { text: activeDevice.value.content } }
|
||||||
})
|
})
|
||||||
|
|
||||||
const hideSelected = () => {
|
const hideSelected = () => {
|
||||||
const names = selectedRows.value.map(r => r.name)
|
ignoredList.value = [...new Set([...ignoredList.value, ...selectedRows.value.map(r => r.name)])]
|
||||||
ignoredList.value = [...new Set([...ignoredList.value, ...names])]
|
localStorage.setItem('hide_list', JSON.stringify(ignoredList.value))
|
||||||
localStorage.setItem('hide_devices', JSON.stringify(ignoredList.value))
|
|
||||||
ElMessage.warning('设备已屏蔽')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const restoreDevice = (name) => {
|
const restoreDevice = (name) => {
|
||||||
ignoredList.value = ignoredList.value.filter(n => n !== name)
|
ignoredList.value = ignoredList.value.filter(n => n !== name)
|
||||||
localStorage.setItem('hide_devices', JSON.stringify(ignoredList.value))
|
localStorage.setItem('hide_list', JSON.stringify(ignoredList.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchLogs = async () => {
|
const fetchLogs = async () => {
|
||||||
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) lastUpdateTime.value = res.data[0].check_time
|
||||||
if (res.data.length > 0) lastUpdateTime.value = res.data[0].check_time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkStatus = async () => {
|
const checkStatus = async () => {
|
||||||
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) setTimeout(checkStatus, 2000); else fetchLogs()
|
||||||
else fetchLogs()
|
|
||||||
}
|
}
|
||||||
|
const handleManualRefresh = async () => { await axios.post('/api/run'); isRunning.value = true; checkStatus() }
|
||||||
const handleManualRefresh = async () => {
|
|
||||||
await axios.post('/api/run')
|
|
||||||
isRunning.value = true
|
|
||||||
checkStatus()
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => { checkStatus(); fetchLogs() })
|
onMounted(() => { checkStatus(); fetchLogs() })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.container { padding: 20px; max-width: 1500px; margin: 0 auto; }
|
.container { padding: 20px; max-width: 1200px; 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; }
|
.toolbar { background: #f9f9f9; padding: 15px; border-radius: 8px; display: flex; justify-content: space-between; margin: 20px 0; border: 1px solid #eee; }
|
||||||
.sys-status { font-size:13px; color:#909399; margin-top:5px; }
|
.json-box { border: 1px solid #eee; background: #fafafa; border-radius: 4px; }
|
||||||
.toolbar { background:#f9f9f9; padding:15px; border-radius:8px; display:flex; justify-content:space-between; margin-top:20px; border:1px solid #eee; }
|
|
||||||
.json-box { border:1px solid #eee; background:#fafafa; border-radius:4px; }
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user