- WS下载: 5s静默超时自动完成(socketClosed标志避免死锁) - WS下载: 视频帧日志跳过(op=0x02)防止日志膨胀 - 10s无数据: 直接标记永久失败(录像机无此时间视频),不再重试 - receiveTask: 强制推送时终止进行中的旧下载,防止同一NVR双下载 - API层: 内存error状态统一映射为failed,与DB一致 - 调度器: per-IP槽位+全局并发上限 - UI: 新增完成时间列,输出显示文件大小/时长
1799 lines
84 KiB
HTML
1799 lines
84 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-cn">
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>打印电脑设置</title>
|
||
<script>
|
||
(function loadExternalDeps() {
|
||
function loadScript(candidates) {
|
||
return new Promise(function (resolve, reject) {
|
||
var idx = 0;
|
||
function tryNext() {
|
||
if (idx >= candidates.length) {
|
||
reject(new Error('All CDN sources failed: ' + candidates.join(', ')));
|
||
return;
|
||
}
|
||
var src = candidates[idx++];
|
||
var script = document.createElement('script');
|
||
script.src = src;
|
||
script.async = false;
|
||
script.onload = function () { resolve(src); };
|
||
script.onerror = tryNext;
|
||
document.head.appendChild(script);
|
||
}
|
||
tryNext();
|
||
});
|
||
}
|
||
|
||
Promise.resolve()
|
||
.then(function () {
|
||
return loadScript([
|
||
'https://cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js',
|
||
'https://unpkg.com/vue@2/dist/vue.min.js',
|
||
'https://cdn.bootcdn.net/ajax/libs/vue/2.7.16/vue.min.js'
|
||
]);
|
||
})
|
||
.then(function () {
|
||
return loadScript([
|
||
'https://cdn.jsdelivr.net/npm/qrcodejs2@0.0.2/qrcode.min.js',
|
||
'https://unpkg.com/qrcodejs2@0.0.2/qrcode.min.js',
|
||
'https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js'
|
||
]);
|
||
})
|
||
.then(function () {
|
||
window.__depsReady = true;
|
||
window.dispatchEvent(new Event('deps-ready'));
|
||
})
|
||
.catch(function (err) {
|
||
console.error('依赖脚本加载失败:', err);
|
||
window.__depsReady = false;
|
||
window.dispatchEvent(new Event('deps-failed'));
|
||
});
|
||
})();
|
||
</script>
|
||
<style>
|
||
:root {
|
||
--bg: #edf1f6;
|
||
--panel: #ffffff;
|
||
--panel-soft: #f7f9fc;
|
||
--line: #d3dce8;
|
||
--text: #1d2a39;
|
||
--subtext: #5d6b7c;
|
||
--accent: #0b69c7;
|
||
--accent-hover: #0858a7;
|
||
--danger: #c42b1c;
|
||
}
|
||
|
||
* {
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
html,
|
||
body {
|
||
margin: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
overflow: hidden;
|
||
}
|
||
|
||
body {
|
||
font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
|
||
color: var(--text);
|
||
background: linear-gradient(150deg, #f8fbff 0%, var(--bg) 72%);
|
||
padding: 12px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
#app {
|
||
width: 100%;
|
||
flex: 1;
|
||
min-height: 0;
|
||
background: var(--panel);
|
||
border: 1px solid var(--line);
|
||
border-radius: 12px;
|
||
box-shadow: 0 14px 34px rgba(34, 50, 74, 0.12);
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.topbar {
|
||
flex: 0 0 auto;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 12px 14px;
|
||
border-bottom: 1px solid var(--line);
|
||
background: linear-gradient(180deg, #ffffff 0%, #f5f8fc 100%);
|
||
}
|
||
|
||
.title {
|
||
margin: 0;
|
||
font-size: 24px;
|
||
font-weight: 700;
|
||
letter-spacing: 0.2px;
|
||
}
|
||
|
||
.name-badge {
|
||
font-size: 13px;
|
||
color: var(--subtext);
|
||
background: #fff;
|
||
border: 1px solid var(--line);
|
||
border-radius: 999px;
|
||
padding: 5px 10px;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.tabbar {
|
||
flex: 0 0 auto;
|
||
display: flex;
|
||
gap: 8px;
|
||
padding: 10px 14px 0;
|
||
border-bottom: 1px solid var(--line);
|
||
background: #f8fbff;
|
||
}
|
||
|
||
.tab {
|
||
appearance: none;
|
||
border: 1px solid #b7c4d5;
|
||
border-bottom: none;
|
||
background: linear-gradient(180deg, #ffffff 0%, #edf2f8 100%);
|
||
color: #2a3b52;
|
||
border-radius: 8px 8px 0 0;
|
||
padding: 9px 14px;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.tab:hover {
|
||
border-color: #8ca0b8;
|
||
}
|
||
|
||
.tab.active {
|
||
background: #fff;
|
||
color: #0c2f57;
|
||
border-color: #8ea6c2;
|
||
box-shadow: inset 0 2px 0 #0b69c7;
|
||
}
|
||
|
||
.content {
|
||
flex: 1 1 auto;
|
||
min-height: 0;
|
||
padding: 14px;
|
||
overflow: auto;
|
||
background: #fff;
|
||
}
|
||
|
||
.tab-panel {
|
||
height: 100%;
|
||
}
|
||
|
||
.main-grid {
|
||
height: 100%;
|
||
display: flex;
|
||
gap: 14px;
|
||
min-height: 480px;
|
||
}
|
||
|
||
.left {
|
||
flex: 1 1 64%;
|
||
min-width: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 14px;
|
||
}
|
||
|
||
.right {
|
||
flex: 1 1 36%;
|
||
min-width: 320px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.panel {
|
||
border: 1px solid var(--line);
|
||
border-radius: 10px;
|
||
background: var(--panel-soft);
|
||
padding: 12px;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
flex: 1;
|
||
}
|
||
|
||
.panel-title {
|
||
margin: 0;
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
color: #26384d;
|
||
padding-bottom: 8px;
|
||
border-bottom: 1px solid #e2e8f0;
|
||
}
|
||
|
||
.list-title-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 10px;
|
||
margin-top: 10px;
|
||
}
|
||
|
||
.list-title {
|
||
font-size: 14px;
|
||
color: var(--subtext);
|
||
font-weight: 600;
|
||
}
|
||
|
||
button {
|
||
appearance: none;
|
||
border: 1px solid #a9b6c7;
|
||
background: linear-gradient(180deg, #ffffff 0%, #eaf0f8 100%);
|
||
color: #243446;
|
||
border-radius: 6px;
|
||
padding: 7px 13px;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
cursor: pointer;
|
||
}
|
||
|
||
button:hover {
|
||
border-color: #8698af;
|
||
background: linear-gradient(180deg, #ffffff 0%, #e1e9f3 100%);
|
||
}
|
||
|
||
.refresh-btn {
|
||
border-color: var(--accent);
|
||
background: var(--accent);
|
||
color: #fff;
|
||
}
|
||
|
||
.refresh-btn:hover {
|
||
border-color: var(--accent-hover);
|
||
background: var(--accent-hover);
|
||
}
|
||
|
||
.list {
|
||
margin-top: 8px;
|
||
border: 1px solid #dde5ef;
|
||
border-radius: 7px;
|
||
background: #fff;
|
||
padding: 8px 10px;
|
||
overflow-y: auto;
|
||
min-height: 140px;
|
||
flex: 1;
|
||
}
|
||
|
||
.item {
|
||
font-size: 14px;
|
||
color: #243446;
|
||
padding: 7px 3px;
|
||
border-bottom: 1px dashed #e5ebf3;
|
||
}
|
||
|
||
.printer-item {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
}
|
||
|
||
.printer-name {
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.printer-state {
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
border-radius: 999px;
|
||
padding: 2px 8px;
|
||
border: 1px solid transparent;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.printer-state.online {
|
||
color: #107c10;
|
||
background: #e9f6ea;
|
||
border-color: #c8e6ca;
|
||
}
|
||
|
||
.printer-state.offline {
|
||
color: #c42b1c;
|
||
background: #fdeeee;
|
||
border-color: #f5c7c2;
|
||
}
|
||
|
||
.item:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.qrcode-box {
|
||
margin-top: 10px;
|
||
text-align: center;
|
||
display: flex;
|
||
flex-direction: column;
|
||
flex: 1;
|
||
justify-content: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
#qrcode {
|
||
width: 256px;
|
||
height: 256px;
|
||
margin: 0 auto;
|
||
text-align: center;
|
||
border: 1px solid #dce4ee;
|
||
border-radius: 8px;
|
||
background: #fff;
|
||
padding: 10px;
|
||
}
|
||
|
||
img {
|
||
width: auto;
|
||
height: 100%;
|
||
display: inline-block !important;
|
||
}
|
||
|
||
.error {
|
||
color: var(--danger);
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.placeholder {
|
||
height: 100%;
|
||
border: 1px dashed #c5d2e3;
|
||
border-radius: 10px;
|
||
background: #fbfdff;
|
||
color: #607289;
|
||
font-size: 14px;
|
||
padding: 16px;
|
||
}
|
||
|
||
.form-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
margin-bottom: 12px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.form-row label {
|
||
min-width: 120px;
|
||
color: #344a62;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.form-row input {
|
||
width: 180px;
|
||
border: 1px solid #b8c7d9;
|
||
border-radius: 6px;
|
||
padding: 7px 10px;
|
||
font-size: 14px;
|
||
color: #203246;
|
||
background: #fff;
|
||
}
|
||
|
||
.hint {
|
||
margin-top: 8px;
|
||
color: #556a83;
|
||
font-size: 13px;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
.inline-ok {
|
||
color: #107c10;
|
||
font-size: 13px;
|
||
margin-top: 8px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.update-card {
|
||
margin-top: 18px;
|
||
border: 1px solid #c8d8ec;
|
||
border-radius: 10px;
|
||
background: #ffffff;
|
||
padding: 12px;
|
||
}
|
||
|
||
.update-title {
|
||
margin: 0 0 10px 0;
|
||
color: #2c425d;
|
||
font-size: 15px;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.update-meta {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 12px;
|
||
color: #4d627a;
|
||
font-size: 13px;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.update-progress-track {
|
||
width: 100%;
|
||
height: 12px;
|
||
border-radius: 999px;
|
||
background: #e7edf6;
|
||
overflow: hidden;
|
||
border: 1px solid #d7e1ee;
|
||
}
|
||
|
||
.update-progress-fill {
|
||
height: 100%;
|
||
background: linear-gradient(90deg, #0b69c7 0%, #2f87de 100%);
|
||
transition: width 0.25s ease;
|
||
}
|
||
|
||
.update-progress-text {
|
||
margin-top: 8px;
|
||
font-size: 13px;
|
||
color: #38506a;
|
||
}
|
||
|
||
.update-actions {
|
||
margin-top: 10px;
|
||
display: flex;
|
||
gap: 8px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.statusbar {
|
||
flex: 0 0 auto;
|
||
border-top: 1px solid var(--line);
|
||
background: #f8fbff;
|
||
padding: 9px 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
overflow-x: auto;
|
||
}
|
||
|
||
.status-item {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 7px;
|
||
white-space: nowrap;
|
||
color: #3a4d64;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.status-action {
|
||
border-color: #bf8a1d;
|
||
background: linear-gradient(180deg, #ffe5aa 0%, #ffd27a 100%);
|
||
color: #6d4a03;
|
||
}
|
||
|
||
.status-action.restart {
|
||
margin-left: auto;
|
||
}
|
||
|
||
.status-action:hover {
|
||
border-color: #9f6e0d;
|
||
background: linear-gradient(180deg, #ffdc94 0%, #ffc862 100%);
|
||
}
|
||
|
||
.status-dot {
|
||
width: 10px;
|
||
height: 10px;
|
||
border-radius: 50%;
|
||
border: 1px solid rgba(0, 0, 0, 0.12);
|
||
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.status-link {
|
||
cursor: pointer;
|
||
text-decoration: underline;
|
||
text-underline-offset: 2px;
|
||
}
|
||
|
||
@media (max-width: 980px) {
|
||
.main-grid {
|
||
flex-direction: column;
|
||
min-height: 0;
|
||
}
|
||
|
||
.right {
|
||
min-width: 0;
|
||
}
|
||
}
|
||
|
||
@media (max-width: 640px) {
|
||
body {
|
||
padding: 8px;
|
||
}
|
||
|
||
#app {
|
||
height: calc(100vh - 16px);
|
||
}
|
||
|
||
.topbar {
|
||
flex-direction: column;
|
||
align-items: flex-start;
|
||
gap: 6px;
|
||
}
|
||
|
||
.title {
|
||
font-size: 22px;
|
||
}
|
||
|
||
#qrcode {
|
||
width: 220px;
|
||
height: 220px;
|
||
}
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
<div id="app">
|
||
<div class="topbar">
|
||
<h1 class="title">天豹云仓打印服务台</h1>
|
||
<div class="name-badge">工作台:{{ name || '未命名' }}</div>
|
||
</div>
|
||
|
||
<div class="tabbar">
|
||
<button class="tab" :class="{ active: activeTab === 'overview' }" @click="activeTab = 'overview'">运行总览</button>
|
||
<button class="tab" :class="{ active: activeTab === 'playback' }" @click="activeTab = 'playback'; loadHikTasks()" v-if="recording.isRecording">录像回放</button>
|
||
<button class="tab" :class="{ active: activeTab === 'extension' }" @click="activeTab = 'extension'">设置</button>
|
||
</div>
|
||
|
||
<div class="content">
|
||
<div class="tab-panel" v-show="activeTab === 'overview'">
|
||
<div class="main-grid">
|
||
<div class="left">
|
||
<div class="panel">
|
||
<h2 class="panel-title">打印机列表</h2>
|
||
<div class="list-title-row">
|
||
<div class="list-title">当前可用打印机</div>
|
||
<button @click="loadPrinters" class="refresh-btn">刷新打印机状态</button>
|
||
</div>
|
||
<div class="list">
|
||
<div class="item" v-if="printers.length === 0">无打印机</div>
|
||
<div class="item printer-item" v-for="p in printers" :key="p.name">
|
||
<span class="printer-name">{{ p.name }}</span>
|
||
<span class="printer-state" :class="isPrinterOffline(p) ? 'offline' : 'online'">{{ isPrinterOffline(p) ? '离线' : '在线' }}</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="panel">
|
||
<h2 class="panel-title">打印组件状态</h2>
|
||
<div class="list-title-row">
|
||
<div class="list-title">组件连接状态总览</div>
|
||
</div>
|
||
<div class="list">
|
||
<div class="item" v-if="components.length === 0">无打印组件</div>
|
||
<div class="item" v-for="c in components" :key="c.name">{{ c.name }}
|
||
<i :style="{color: wsStatus[getStatus(c.name)].color}">{{wsStatus[getStatus(c.name)].title}}</i>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="right" v-if="!isBind">
|
||
<div class="panel">
|
||
<h2 class="panel-title">绑定工作台</h2>
|
||
<div class="qrcode-box">
|
||
<div id="qrcode" ref="qrcode"></div>
|
||
<div class="error">未绑定打印台,请使用微信扫码二维码完成绑定。</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="tab-panel" v-show="activeTab === 'playback'">
|
||
<div class="main-grid">
|
||
<div class="left">
|
||
<div class="panel">
|
||
<h2 class="panel-title">海康 NVR 下载任务</h2>
|
||
<div class="list-title-row" style="flex-wrap:wrap;gap:6px;">
|
||
<div class="list-title">
|
||
存储 {{ formatBytes(hikStorageUsed) }} / {{ formatBytes(hikStorageMax) }}
|
||
</div>
|
||
<select v-model="hikStatusFilter" @change="loadHikTasks(1)" style="font-size:11px;padding:2px 6px;border:1px solid #ccc;border-radius:3px;background:#fff;">
|
||
<option value="">全部状态</option>
|
||
<option value="pending">待处理</option>
|
||
<option value="running">录制中</option>
|
||
<option value="completed">已完成</option>
|
||
<option value="failed">失败</option>
|
||
<option value="timeout">超时</option>
|
||
<option value="error">异常</option>
|
||
</select>
|
||
<button @click="loadHikTasks" class="refresh-btn">刷新</button>
|
||
<button @click="toggleAutoRefresh" class="refresh-btn" :style="hikAutoRefresh ? {background:'#e8f5e9',color:'#107c10',borderColor:'#107c10'} : {}" style="white-space:nowrap;">{{ hikAutoRefresh ? '⏸ 停止刷新' : '▶ 自动刷新' }}</button>
|
||
<input v-if="!hikAutoRefresh" v-model.number="hikAutoRefreshInterval" type="number" min="1" max="300" style="width:40px;font-size:11px;padding:2px 4px;border:1px solid #ccc;border-radius:3px;text-align:center;" title="刷新间隔(秒)" />
|
||
<span v-if="!hikAutoRefresh" style="font-size:11px;color:#888;">秒</span>
|
||
<button @click="batchRetryHikTasks" class="refresh-btn" style="border-color:#f59f00;color:#f59f00;background:#fff8f0;" :disabled="!hikTasks.some(function(t){return t._checked})">批量强制重录</button>
|
||
<span v-if="batchRetryMsg" style="font-size:11px;color:#107c10;">{{ batchRetryMsg }}</span>
|
||
</div>
|
||
<div v-if="hikTasks.length === 0" style="color:#999;padding:16px;text-align:center;">暂无任务</div>
|
||
<div v-else style="max-height:460px;overflow-y:auto;border:1px solid #e0e0e0;border-radius:6px;">
|
||
<table style="width:100%;border-collapse:collapse;font-size:11px;">
|
||
<thead>
|
||
<tr style="background:#f5f6f8;position:sticky;top:0;z-index:1;">
|
||
<th style="padding:5px 4px;text-align:center;border-bottom:2px solid #ddd;width:28px;">
|
||
<input type="checkbox" v-model="hikSelectAll" @change="toggleSelectAllHikTasks">
|
||
</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">任务ID</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">状态</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">通道</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">时长</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">倍速</th>
|
||
<th style="padding:5px 6px;text-align:left;min-width:100px;border-bottom:2px solid #ddd;">输出文件</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">重试</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">创建时间</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">录制开始</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">录制结束</th>
|
||
<th style="padding:5px 6px;text-align:left;white-space:nowrap;border-bottom:2px solid #ddd;">完成时间</th>
|
||
<th style="padding:5px 6px;text-align:center;white-space:nowrap;border-bottom:2px solid #ddd;">操作</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-for="t in hikTasks" :key="t.task_id" style="border-bottom:1px solid #eee;" :style="t.status === 'running' ? {background:'#f0f7ff'} : {}">
|
||
<td style="padding:4px;text-align:center;"><input type="checkbox" v-model="t._checked"></td>
|
||
<td style="padding:4px 6px;white-space:nowrap;font-weight:600;">{{ t.unique_code || '-' }}</td>
|
||
<td style="padding:4px 6px;white-space:nowrap;">
|
||
<span :style="{color: taskStatusColor(t.status),fontWeight:'600'}">{{ taskStatusText(t.status) }}</span>
|
||
<div v-if="t.status === 'running'" style="margin-top:2px;background:#d0e0f0;border-radius:2px;height:3px;overflow:hidden;width:48px;">
|
||
<div style="height:100%;background:linear-gradient(90deg,#0b69c7,#2f87de);width:60%;"></div>
|
||
</div>
|
||
</td>
|
||
<td style="padding:4px 6px;white-space:nowrap;">{{ t.ip || '-' }}<br><span style="font-size:9px;color:#888;">ch{{ t.channel }}</span></td>
|
||
<td style="padding:4px 6px;white-space:nowrap;">{{ fmtDuration(t.videoTime) }}</td>
|
||
<td style="padding:4px 6px;white-space:nowrap;">{{ t.speed }}x</td>
|
||
<td style="padding:4px 6px;max-width:140px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" :title="getFileName(t.output)">
|
||
<div v-if="t.status === 'completed' || t.status === 'done'" style="color:#333;">{{ getFileName(t.output) }}</div>
|
||
<div v-if="t.status === 'completed' || t.status === 'done'" style="font-size:9px;color:#888;">{{ formatBytes((t.result && t.result.size) || 0) }} / {{ (t.result && t.result.duration) ? (t.result.duration).toFixed(1) + 's' : '-' }}</div>
|
||
<div v-if="(t.status === 'failed' || t.status === 'timeout' || t.status === 'error') && t.error_message" style="font-size:10px;color:#c42b1c;">{{ t.error_message }}</div>
|
||
<div v-else-if="t.status !== 'completed' && t.status !== 'done' && t.status !== 'failed' && t.status !== 'timeout' && t.status !== 'error'" style="color:#aaa;">-</div>
|
||
</td>
|
||
<td style="padding:4px 6px;white-space:nowrap;text-align:center;">{{ t.retry || 0 }}</td>
|
||
<td style="padding:4px 6px;white-space:nowrap;font-size:10px;color:#888;">{{ (t.created_at || '').substring(0,16) || '-' }}</td>
|
||
<td style="padding:4px 6px;white-space:nowrap;font-size:10px;color:#888;">{{ (t.rec_start || '').substring(0,16) || '-' }}</td>
|
||
<td style="padding:4px 6px;white-space:nowrap;font-size:10px;color:#888;">{{ (t.rec_end || '').substring(0,16) || '-' }}</td>
|
||
<td style="padding:4px 6px;white-space:nowrap;font-size:10px;color:#888;">{{ (t.end_time || '').substring(0,16) || '-' }}</td>
|
||
<td style="padding:4px 6px;text-align:center;white-space:nowrap;">
|
||
<button v-if="t.status === 'completed' || t.status === 'done'" style="font-size:10px;padding:1px 5px;margin:1px;" @click="previewHikTask(t)">预览</button>
|
||
<button v-if="t.status === 'completed' || t.status === 'done'" style="font-size:10px;padding:1px 5px;margin:1px;border-color:#f59f00;color:#f59f00;" @click="retryHikTask(t.task_id)">重录</button>
|
||
<button v-if="t.status === 'failed' || t.status === 'timeout'" style="font-size:10px;padding:1px 5px;margin:1px;border-color:#c42b1c;color:#c42b1c;" @click="retryHikTask(t.task_id)">重试</button>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<!-- 分页控件 -->
|
||
<div v-if="hikTotal > hikPageSize" style="display:flex;align-items:center;justify-content:center;gap:8px;padding:8px 0;font-size:13px;color:#555;">
|
||
<button @click="loadHikTasks(1)" :disabled="hikPage <= 1" style="font-size:11px;padding:2px 8px;">首页</button>
|
||
<button @click="loadHikTasks(hikPage - 1)" :disabled="hikPage <= 1" style="font-size:11px;padding:2px 8px;">上一页</button>
|
||
<span>第</span>
|
||
<input type="number" v-model.number="hikJumpPage" @keyup.enter="loadHikTasks(hikJumpPage)" :min="1" :max="hikTotalPages" style="width:44px;text-align:center;font-size:12px;padding:2px 4px;border:1px solid #ccc;border-radius:3px;" />
|
||
<span>/ {{ hikTotalPages }} 页(共 {{ hikTotal }} 条)</span>
|
||
<button @click="loadHikTasks(hikJumpPage)" :disabled="!hikJumpPage || hikJumpPage < 1 || hikJumpPage > hikTotalPages" style="font-size:11px;padding:2px 8px;">跳转</button>
|
||
<button @click="loadHikTasks(hikPage + 1)" :disabled="hikPage >= hikTotalPages" style="font-size:11px;padding:2px 8px;">下一页</button>
|
||
<button @click="loadHikTasks(hikTotalPages)" :disabled="hikPage >= hikTotalPages" style="font-size:11px;padding:2px 8px;">末页</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="right" v-if="previewFile">
|
||
<div class="panel">
|
||
<h2 class="panel-title">录像预览</h2>
|
||
<div style="margin-top:8px;">
|
||
<video v-if="previewFile.downloadUrl" :src="previewFile.downloadUrl" controls
|
||
style="width:100%;max-height:360px;background:#000;border-radius:8px;"
|
||
@error="previewError = true">
|
||
</video>
|
||
<div v-if="previewError" class="error">视频加载失败</div>
|
||
<div style="margin-top:6px;font-size:13px;color:#555;">
|
||
<strong>{{ getFileName(previewFile.output_path) }}</strong><br>
|
||
<span style="font-size:11px;color:#999;">{{ formatBytes(previewFile.file_size || 0) }} · {{ previewFile.duration || 0 }}s</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="tab-panel" v-show="activeTab === 'extension'">
|
||
<div class="update-card">
|
||
<h4 class="update-title">应用更新</h4>
|
||
<div class="update-meta">
|
||
<span>当前版本:{{ updateState.currentVersion || '-' }}</span>
|
||
<span>最新版本:{{ updateState.latestVersion || '-' }}</span>
|
||
<span>状态:{{ updateStatusText }}</span>
|
||
</div>
|
||
<div class="update-progress-track">
|
||
<div class="update-progress-fill" :style="{ width: updateProgressPercent + '%' }"></div>
|
||
</div>
|
||
<div class="update-progress-text">{{ updateState.message || '未开始下载' }}({{ updateProgressPercent }}%)</div>
|
||
<div class="update-progress-text" v-if="updateState.downloadedBytes > 0">
|
||
{{ formatBytes(updateState.downloadedBytes) }} / {{ updateState.totalBytes > 0 ? formatBytes(updateState.totalBytes) : '未知大小' }}
|
||
</div>
|
||
<div class="update-actions">
|
||
<button class="refresh-btn" @click="checkUpdate(true)" :disabled="updateChecking || updatingInApp">{{ updateChecking ? '检查中...' : '检查更新' }}</button>
|
||
<button @click="startInAppUpdate()" :disabled="!updateState.hasUpdate || updatingInApp || !updateState.downloadUrl">
|
||
{{ updatingInApp ? '下载中...' : '应用内下载并安装' }}
|
||
</button>
|
||
<button @click="openDownloadedInstaller()" :disabled="!updateState.filePath || updatingInApp">再次打开安装包</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="update-card" style="margin-top: 18px;">
|
||
<h4 class="update-title">录制设置(由服务器下发)</h4>
|
||
<div class="form-row">
|
||
<label>录制状态</label>
|
||
<span :style="{ color: recording.isRecording ? '#107c10' : '#c42b1c', fontWeight: 'bold' }">{{ recording.isRecording ? '已启用' : '未启用' }}</span>
|
||
</div>
|
||
<div class="form-row">
|
||
<label>存储上限</label>
|
||
<span>{{ recording.maxStorage || '-' }}</span>
|
||
</div>
|
||
<div class="form-row">
|
||
<label>录制目录</label>
|
||
<span style="font-size:13px;word-break:break-all;">{{ recording.downloadDir || '-' }}</span>
|
||
</div>
|
||
<div class="form-row" v-if="recording.remotePlayUrl">
|
||
<label>远程回放</label>
|
||
<a :href="recording.remotePlayUrl" target="_blank" style="font-size:13px;color:#0b69c7;">{{ recording.remotePlayUrl }}</a>
|
||
</div>
|
||
</div>
|
||
<div class="update-card" style="margin-top: 18px;">
|
||
<h4 class="update-title">内网穿透(frpc)</h4>
|
||
<div class="form-row">
|
||
<label>穿透状态</label>
|
||
<span :style="{ color: frpcStatusColor, fontWeight: 'bold' }">{{ frpcStatusText }}</span>
|
||
</div>
|
||
<div class="form-row">
|
||
<label>说明</label>
|
||
<span style="font-size:13px;color:#888;">frpc 配置由服务器下发,自动管理启停</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="statusbar">
|
||
<div class="status-item">
|
||
<span class="status-dot" :style="{ backgroundColor: wsStatus[wsClientStatus].color }"></span>
|
||
<span>本地服务:<strong :style="{color: wsStatus[wsClientStatus].color}">{{ wsStatus[wsClientStatus].title }}</strong></span>
|
||
</div>
|
||
|
||
<div class="status-item">
|
||
<span class="status-dot" :style="{ backgroundColor: wsStatus[wsServerStatus].color }"></span>
|
||
<span>服务器连接:<strong :style="{color: wsStatus[wsServerStatus].color}">{{ wsStatus[wsServerStatus].title }}</strong></span>
|
||
</div>
|
||
<div class="status-item">
|
||
<span class="status-dot" :style="{ backgroundColor: isBind ? '#107c10' : '#c42b1c' }"></span>
|
||
<span>打印服务绑定:<strong :style="{ color: isBind ? '#107c10' : '#c42b1c' }">{{ isBind ? '已绑定' : '未绑定' }}</strong></span>
|
||
</div>
|
||
<button class="status-action" id="btnCheckUpdate">{{ updateChecking ? '检查中...' : '检查更新' }}</button>
|
||
<button class="status-action restart" id="btnRestartBackend">{{ restartingBackend ? '重启中...' : '重启服务' }}</button>
|
||
<div class="status-item" style="margin-left:auto;">
|
||
<span class="status-dot" :style="{ backgroundColor: frpcStatusColor }"></span>
|
||
<span>穿透:<strong :style="{color: frpcStatusColor}">{{ frpcStatusText }}</strong></span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
(function initApp() {
|
||
if (!window.__depsReady) {
|
||
window.addEventListener('deps-ready', initApp, { once: true });
|
||
window.addEventListener('deps-failed', function () {
|
||
var root = document.getElementById('app');
|
||
if (root) {
|
||
root.innerHTML = '<h2 style="color:#c62828;">页面依赖加载失败,请检查网络或更换可用 CDN。</h2>';
|
||
}
|
||
}, { once: true });
|
||
return;
|
||
}
|
||
|
||
// ─── IPC 通讯层 ───
|
||
// 使用 window.printServerAPI(由 preload.cjs 通过 contextBridge 注入)
|
||
// callService(method, data) → Promise
|
||
// onEvent(method, callback) → unsubscribe function
|
||
|
||
// ─── 浏览器模式兼容层(非 Electron 环境自动启用 WebSocket 直连)───
|
||
if (!window.printServerAPI) {
|
||
(function () {
|
||
var wsUrl = 'ws://' + location.hostname + ':17301';
|
||
var httpBase = 'http://' + location.hostname + ':17311';
|
||
var ws = null;
|
||
var eventListeners = {};
|
||
var statusListeners = [];
|
||
var pendingCalls = {};
|
||
var callId = 0;
|
||
var currentStatus = 'disconnected';
|
||
var reconnectTimer = null;
|
||
|
||
function setStatus(s) {
|
||
if (currentStatus === s) return;
|
||
currentStatus = s;
|
||
statusListeners.forEach(function (fn) { try { fn(s); } catch (e) {} });
|
||
}
|
||
|
||
function connect() {
|
||
if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) return;
|
||
setStatus('connecting');
|
||
try {
|
||
ws = new WebSocket(wsUrl);
|
||
ws.onopen = function () {
|
||
setStatus('connected');
|
||
console.log('[BrowserAPI] WebSocket 已连接:', wsUrl);
|
||
};
|
||
ws.onclose = function () {
|
||
setStatus('disconnected');
|
||
ws = null;
|
||
// 3 秒后重连
|
||
clearTimeout(reconnectTimer);
|
||
reconnectTimer = setTimeout(connect, 3000);
|
||
};
|
||
ws.onerror = function () {
|
||
setStatus('error');
|
||
};
|
||
ws.onmessage = function (evt) {
|
||
try {
|
||
var msg = JSON.parse(evt.data);
|
||
// 处理 RPC 回调
|
||
if (msg._callId && pendingCalls[msg._callId]) {
|
||
var cb = pendingCalls[msg._callId];
|
||
delete pendingCalls[msg._callId];
|
||
if (msg.success === false) {
|
||
cb.reject(new Error(msg.message || '调用失败'));
|
||
} else {
|
||
cb.resolve(msg);
|
||
}
|
||
return;
|
||
}
|
||
// 处理事件推送
|
||
if (msg.method) {
|
||
var list = eventListeners[msg.method];
|
||
if (list) {
|
||
list.forEach(function (fn) { try { fn(msg); } catch (e) {} });
|
||
}
|
||
}
|
||
} catch (e) { /* 非 JSON 消息忽略 */ }
|
||
};
|
||
} catch (e) {
|
||
setStatus('error');
|
||
clearTimeout(reconnectTimer);
|
||
reconnectTimer = setTimeout(connect, 3000);
|
||
}
|
||
}
|
||
|
||
connect();
|
||
|
||
window.printServerAPI = {
|
||
callService: function (method, data) {
|
||
return new Promise(function (resolve, reject) {
|
||
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
||
reject(new Error('WebSocket 未连接'));
|
||
return;
|
||
}
|
||
var id = ++callId;
|
||
pendingCalls[id] = { resolve: resolve, reject: reject };
|
||
try {
|
||
ws.send(JSON.stringify({ method: method, data: data, _callId: id }));
|
||
} catch (e) {
|
||
delete pendingCalls[id];
|
||
reject(e);
|
||
}
|
||
// 10 秒超时
|
||
setTimeout(function () {
|
||
if (pendingCalls[id]) {
|
||
delete pendingCalls[id];
|
||
reject(new Error('调用超时'));
|
||
}
|
||
}, 10000);
|
||
});
|
||
},
|
||
callApi: function (path, options) {
|
||
var url = httpBase + path;
|
||
var fetchOpts = { headers: { 'Content-Type': 'application/json' } };
|
||
if (options && options.method) fetchOpts.method = options.method;
|
||
if (options && options.body) fetchOpts.body = JSON.stringify(options.body);
|
||
return fetch(url, fetchOpts).then(function (r) { return r.json(); });
|
||
},
|
||
onEvent: function (method, callback) {
|
||
if (!eventListeners[method]) eventListeners[method] = [];
|
||
eventListeners[method].push(callback);
|
||
return function () {
|
||
var arr = eventListeners[method];
|
||
if (arr) {
|
||
eventListeners[method] = arr.filter(function (f) { return f !== callback; });
|
||
}
|
||
};
|
||
},
|
||
onBackendStatusChange: function (callback) {
|
||
statusListeners.push(callback);
|
||
// 立即发送当前状态
|
||
try { callback && callback(currentStatus); } catch (e) {}
|
||
return function () {
|
||
statusListeners = statusListeners.filter(function (f) { return f !== callback; });
|
||
};
|
||
},
|
||
getBackendStatus: function () {
|
||
return Promise.resolve(currentStatus);
|
||
},
|
||
getHttpPort: function () {
|
||
return Promise.resolve(17311);
|
||
},
|
||
selectFolder: function () {
|
||
return Promise.resolve({ canceled: true });
|
||
}
|
||
};
|
||
console.log('[BrowserAPI] 浏览器兼容模式已启用, wsUrl=' + wsUrl);
|
||
})();
|
||
}
|
||
|
||
new Vue({
|
||
el: '#app',
|
||
data: {
|
||
activeTab: 'overview',
|
||
printers: [],
|
||
components: [],
|
||
statusList: [],
|
||
isBind: false,
|
||
wsClientStatus: 'connected',
|
||
wsServerStatus: 'disconnected',
|
||
name: '',
|
||
restartingBackend: false,
|
||
updateChecking: false,
|
||
updatingInApp: false,
|
||
updateState: {
|
||
hasUpdate: false,
|
||
currentVersion: '',
|
||
latestVersion: '',
|
||
downloadUrl: '',
|
||
status: 'idle',
|
||
percent: 0,
|
||
downloadedBytes: 0,
|
||
totalBytes: 0,
|
||
message: ''
|
||
},
|
||
code: '',
|
||
qrcode: null,
|
||
wsStatus: {
|
||
'disconnected': { title: '未连接', color: 'red' },
|
||
'connecting': { title: '连接中', color: '#f59f00' },
|
||
'reconnecting': { title: '重连中', color: '#f59f00' },
|
||
'connected': { title: '已连接', color: 'green' },
|
||
'error': { title: '连接错误', color: 'red' },
|
||
},
|
||
// 海康录像回放
|
||
hikFiles: [],
|
||
hikFilePage: 1,
|
||
hikFileTotal: 0,
|
||
hikFileTotalPages: 1,
|
||
hikStorageUsed: 0,
|
||
hikStorageMax: 0,
|
||
hikStoragePercent: 0,
|
||
previewFile: null,
|
||
previewError: false,
|
||
// 海康任务
|
||
hikTasks: [],
|
||
hikPage: 1,
|
||
hikPageSize: 20,
|
||
hikTotal: 0,
|
||
hikJumpPage: 1,
|
||
hikStatusFilter: '',
|
||
hikSelectAll: false,
|
||
batchRetryMsg: '',
|
||
hikAutoRefresh: false,
|
||
hikAutoRefreshInterval: 5,
|
||
hikAutoRefreshTimer: null,
|
||
// 海康配置
|
||
hikConfig: { downloadDir: '', maxStorageNum: 50, maxStorageUnit: 'GB', circularRecording: true },
|
||
hikConfigSaving: false,
|
||
hikConfigSaved: false,
|
||
// 服务器下发的录制配置(只读)
|
||
recording: {
|
||
isRecording: false,
|
||
maxStorage: '-',
|
||
downloadDir: '-',
|
||
remotePlayUrl: ''
|
||
},
|
||
// frpc 内网穿透状态
|
||
frpcStatus: 'stopped',
|
||
},
|
||
computed: {
|
||
updateProgressPercent() {
|
||
const value = Number(this.updateState.percent || 0);
|
||
if (!Number.isFinite(value)) {
|
||
return 0;
|
||
}
|
||
return Math.max(0, Math.min(100, Math.round(value)));
|
||
},
|
||
updateStatusText() {
|
||
const map = {
|
||
idle: '空闲',
|
||
starting: '准备下载',
|
||
downloading: '下载中',
|
||
downloaded: '下载完成',
|
||
installing: '安装中',
|
||
failed: '失败'
|
||
};
|
||
return map[this.updateState.status] || '空闲';
|
||
},
|
||
frpcStatusText() {
|
||
const map = { stopped: '未启动', starting: '启动中', running: '已连接', error: '异常' };
|
||
return map[this.frpcStatus] || this.frpcStatus;
|
||
},
|
||
frpcStatusColor() {
|
||
const map = { stopped: '#888', starting: '#f59f00', running: '#107c10', error: '#c42b1c' };
|
||
return map[this.frpcStatus] || '#888';
|
||
},
|
||
hikTotalPages() {
|
||
return Math.max(1, Math.ceil(this.hikTotal / this.hikPageSize));
|
||
}
|
||
},
|
||
methods: {
|
||
formatBytes(bytes) {
|
||
const value = Number(bytes || 0);
|
||
if (!Number.isFinite(value) || value <= 0) {
|
||
return '0 B';
|
||
}
|
||
|
||
const units = ['B', 'KB', 'MB', 'GB'];
|
||
let size = value;
|
||
let idx = 0;
|
||
while (size >= 1024 && idx < units.length - 1) {
|
||
size /= 1024;
|
||
idx += 1;
|
||
}
|
||
|
||
return `${size.toFixed(idx === 0 ? 0 : 2)} ${units[idx]}`;
|
||
},
|
||
getFileName(filePath) {
|
||
if (!filePath) return '';
|
||
return filePath.replace(/\\/g, '/').split('/').pop() || filePath;
|
||
},
|
||
// ─── 海康录像回放 ───
|
||
loadHikFiles(page) {
|
||
page = page || 1;
|
||
var self = this;
|
||
window.printServerAPI.callApi('/api/hikvision/files?page=' + page + '&pageSize=20')
|
||
.then(function(res) {
|
||
if (res.success) {
|
||
self.hikFiles = res.data.list || [];
|
||
self.hikFilePage = res.data.page || 1;
|
||
self.hikFileTotal = res.data.total || 0;
|
||
self.hikFileTotalPages = Math.ceil(self.hikFileTotal / (res.data.pageSize || 20)) || 1;
|
||
self.hikStorageUsed = res.data.storage.used || 0;
|
||
self.hikStorageMax = res.data.storage.max || 0;
|
||
self.hikStoragePercent = res.data.storage.percent || 0;
|
||
}
|
||
})
|
||
.catch(function(e) { console.error('加载录像列表失败:', e); });
|
||
},
|
||
loadHikTasks(page) {
|
||
var self = this;
|
||
if (typeof page === 'number') self.hikPage = page;
|
||
else page = self.hikPage;
|
||
self.hikJumpPage = page;
|
||
self.hikSelectAll = false;
|
||
var url = '/api/hikvision/tasks?page=' + page + '&pageSize=' + self.hikPageSize;
|
||
if (self.hikStatusFilter) url += '&status=' + self.hikStatusFilter;
|
||
var p = window.printServerAPI.callApi(url)
|
||
.then(function(res) {
|
||
if (res.success) {
|
||
var list = res.data.list || [];
|
||
list.forEach(function(t) { t._checked = false; });
|
||
self.hikTasks = list;
|
||
self.hikTotal = res.data.total || 0;
|
||
}
|
||
return res;
|
||
})
|
||
.catch(function(e) { console.error('加载任务列表失败:', e); throw e; });
|
||
// 同时刷新存储统计
|
||
window.printServerAPI.callApi('/api/hikvision/files?pageSize=1')
|
||
.then(function(res) {
|
||
if (res.success && res.data) {
|
||
self.hikStorageUsed = res.data.storage.used || 0;
|
||
self.hikStorageMax = res.data.storage.max || 0;
|
||
self.hikStoragePercent = res.data.storage.percent || 0;
|
||
}
|
||
}).catch(function(){});
|
||
return p;
|
||
},
|
||
previewHikTask(t) {
|
||
var result = t.result || {};
|
||
var outputPath = t.output || (result.output || '');
|
||
var downloadUrl = result.downloadUrl || '';
|
||
// 如果没有 downloadUrl(来自 DB 查询),构造一个(用当前页面的 host 而不是 127.0.0.1)
|
||
if (!downloadUrl && outputPath) {
|
||
downloadUrl = location.protocol + '//' + location.host + '/api/hikvision/file?path=' + encodeURIComponent(outputPath);
|
||
}
|
||
this.previewFile = {
|
||
output_path: outputPath,
|
||
downloadUrl: downloadUrl,
|
||
file_size: result.size || 0,
|
||
duration: result.duration || 0
|
||
};
|
||
this.previewError = false;
|
||
},
|
||
retryHikTask(taskId) {
|
||
var self = this;
|
||
window.printServerAPI.callApi('/api/hikvision/retry', { method: 'POST', body: { taskId: taskId } })
|
||
.then(function(res) {
|
||
if (res.success) self.loadHikTasks();
|
||
else alert('重试失败: ' + (res.message || ''));
|
||
});
|
||
},
|
||
toggleSelectAllHikTasks() {
|
||
var val = this.hikSelectAll;
|
||
this.hikTasks.forEach(function(t) { t._checked = val; });
|
||
},
|
||
batchRetryHikTasks() {
|
||
var self = this;
|
||
var ids = this.hikTasks.filter(function(t) { return t._checked; }).map(function(t) { return t.task_id; });
|
||
if (ids.length === 0) return;
|
||
if (!confirm('确定要强制重录选中的 ' + ids.length + ' 个任务吗?已完成的任务会删除旧文件重新录制。')) return;
|
||
self.batchRetryMsg = '处理中...';
|
||
window.printServerAPI.callApi('/api/hikvision/retry', { method: 'POST', body: { taskIds: ids } })
|
||
.then(function(res) {
|
||
self.batchRetryMsg = res.message || ('已处理 ' + ids.length + ' 个');
|
||
setTimeout(function() { self.batchRetryMsg = ''; }, 5000);
|
||
self.loadHikTasks();
|
||
})
|
||
.catch(function(e) {
|
||
self.batchRetryMsg = '批量重录失败';
|
||
console.error(e);
|
||
});
|
||
},
|
||
toggleAutoRefresh() {
|
||
this.hikAutoRefresh = !this.hikAutoRefresh;
|
||
if (this.hikAutoRefresh) {
|
||
this.loadHikTasks(1); // 强制回首页+全部状态
|
||
this.hikStatusFilter = '';
|
||
this._startAutoRefresh();
|
||
} else {
|
||
this._stopAutoRefresh();
|
||
}
|
||
try { localStorage.setItem('hikAutoRefresh', JSON.stringify({ enabled: this.hikAutoRefresh, interval: this.hikAutoRefreshInterval })); } catch(e) {}
|
||
},
|
||
_startAutoRefresh() {
|
||
this._stopAutoRefresh();
|
||
var self = this;
|
||
var ms = Math.max(1, self.hikAutoRefreshInterval || 5) * 1000;
|
||
var run = function() {
|
||
// 非首页或非全部状态时停止
|
||
if (self.hikPage !== 1 || self.hikStatusFilter !== '') {
|
||
self.hikAutoRefresh = false;
|
||
self._stopAutoRefresh();
|
||
try { localStorage.setItem('hikAutoRefresh', JSON.stringify({ enabled: false, interval: self.hikAutoRefreshInterval })); } catch(e) {}
|
||
return;
|
||
}
|
||
if (self.activeTab !== 'playback' || !self.hikAutoRefresh) return;
|
||
self.loadHikTasks(1).then(function() {
|
||
if (self.hikAutoRefresh) self.hikAutoRefreshTimer = setTimeout(run, ms);
|
||
}).catch(function() {
|
||
if (self.hikAutoRefresh) self.hikAutoRefreshTimer = setTimeout(run, ms);
|
||
});
|
||
};
|
||
self.hikAutoRefreshTimer = setTimeout(run, ms);
|
||
},
|
||
_stopAutoRefresh() {
|
||
if (this.hikAutoRefreshTimer) { clearTimeout(this.hikAutoRefreshTimer); this.hikAutoRefreshTimer = null; }
|
||
},
|
||
taskStatusText(status) {
|
||
var map = { pending: '⏳ 等待中', running: '⬇ 下载中', completed: '✅ 完成', done: '✅ 完成', failed: '❌ 失败', timeout: '⏰ 超时', error: '⚠ 异常', starting: '🔄 启动中' };
|
||
return map[status] || ('❓ ' + (status || '未知'));
|
||
},
|
||
taskStatusColor(status) {
|
||
var map = { pending: '#f59f00', running: '#0b69c7', completed: '#107c10', done: '#107c10', failed: '#c42b1c', timeout: '#c42b1c', error: '#e67e22', starting: '#f59f00' };
|
||
return map[status] || '#888';
|
||
},
|
||
fmtDuration(seconds) {
|
||
var s = parseInt(seconds) || 0;
|
||
if (s < 60) return s + 's';
|
||
var m = Math.floor(s / 60);
|
||
var sec = s % 60;
|
||
return m + ':' + (sec < 10 ? '0' : '') + sec;
|
||
},
|
||
previewHikFile(file) {
|
||
this.previewFile = file;
|
||
this.previewError = false;
|
||
},
|
||
// ─── 海康配置 ───
|
||
selectDownloadDir() {
|
||
var self = this;
|
||
window.printServerAPI.selectFolder().then(function(result) {
|
||
if (!result.canceled && result.path) {
|
||
self.hikConfig.downloadDir = result.path;
|
||
}
|
||
});
|
||
},
|
||
loadHikConfig() {
|
||
var self = this;
|
||
window.printServerAPI.callApi('/api/hikvision/config')
|
||
.then(function(res) {
|
||
if (res.success && res.hikvision) {
|
||
var c = res.hikvision;
|
||
self.hikConfig.downloadDir = c.downloadDir || '';
|
||
self.hikConfig.circularRecording = c.circularRecording !== false;
|
||
// 解析 "50GB" → num=50, unit=GB
|
||
var m = String(c.maxStorage || '50GB').match(/^([\d.]+)\s*(TB|GB|MB|KB)$/i);
|
||
if (m) {
|
||
self.hikConfig.maxStorageNum = parseFloat(m[1]) || 50;
|
||
self.hikConfig.maxStorageUnit = m[2].toUpperCase();
|
||
}
|
||
}
|
||
});
|
||
},
|
||
saveHikConfig() {
|
||
var self = this;
|
||
self.hikConfigSaving = true;
|
||
self.hikConfigSaved = false;
|
||
var payload = {
|
||
downloadDir: self.hikConfig.downloadDir,
|
||
maxStorage: String(self.hikConfig.maxStorageNum || 50) + (self.hikConfig.maxStorageUnit || 'GB'),
|
||
circularRecording: self.hikConfig.circularRecording
|
||
};
|
||
window.printServerAPI.callApi('/api/hikvision/config', {
|
||
method: 'POST',
|
||
body: payload
|
||
})
|
||
.then(function(res) {
|
||
self.hikConfigSaving = false;
|
||
if (res.success) {
|
||
self.hikConfigSaved = true;
|
||
// 用服务器返回的实际值更新本地状态
|
||
if (res.hikvision) {
|
||
var c = res.hikvision;
|
||
self.hikConfig.downloadDir = c.downloadDir || '';
|
||
self.hikConfig.circularRecording = c.circularRecording !== false;
|
||
var m2 = String(c.maxStorage || '50GB').match(/^([\d.]+)\s*(TB|GB|MB|KB)$/i);
|
||
if (m2) {
|
||
self.hikConfig.maxStorageNum = parseFloat(m2[1]) || 50;
|
||
self.hikConfig.maxStorageUnit = m2[2].toUpperCase();
|
||
}
|
||
}
|
||
setTimeout(function() { self.hikConfigSaved = false; }, 3000);
|
||
} else {
|
||
alert('保存失败: ' + (res.message || '未知错误'));
|
||
}
|
||
})
|
||
.catch(function(e) {
|
||
self.hikConfigSaving = false;
|
||
alert('保存失败: ' + e.message);
|
||
});
|
||
},
|
||
loadComponents() {
|
||
window.printServerAPI.callService('printerComponent.getAll', {}).then((data) => {
|
||
console.log('获取组件列表:', data);
|
||
if (data.success) {
|
||
this.components = data.result.components || [];
|
||
this.statusList = data.result.status || [];
|
||
} else {
|
||
alert(data.message || '获取打印组件列表失败!');
|
||
}
|
||
});
|
||
},
|
||
getStatus(name) {
|
||
const s = this.statusList.find(x => x.name === name);
|
||
return s ? s.status : '未知';
|
||
},
|
||
isPrinterOffline(printer) {
|
||
const raw = printer && printer.workOffline;
|
||
if (typeof raw === 'boolean') {
|
||
return raw;
|
||
}
|
||
|
||
const normalized = String(raw || '').trim().toLowerCase();
|
||
return normalized === 'true' || normalized === '1' || normalized === 'yes';
|
||
},
|
||
loadPrinters() {
|
||
window.printServerAPI.callService('printer.getWindowsPrinters', {}).then((data) => {
|
||
if (data.success) {
|
||
this.printers = data.result || [];
|
||
if (this.printers.length === 0) {
|
||
this.selectedPrinter = '';
|
||
} else if (!this.selectedPrinter) {
|
||
this.selectedPrinter = this.printers[0].name;
|
||
}
|
||
} else {
|
||
alert(data.message || '获取打印机列表失败!');
|
||
}
|
||
});
|
||
},
|
||
|
||
refreshBindStatus() {
|
||
window.printServerAPI.callService('setting.info', {}).then((data) => {
|
||
if (data.success) {
|
||
this.isBind = data.result.isBind || false;
|
||
this.name = data.result.name || '';
|
||
if (data.result.recording) {
|
||
const r = data.result.recording;
|
||
this.recording = {
|
||
isRecording: !!r.isRecording,
|
||
maxStorage: r.maxStorage || '-',
|
||
downloadDir: r.downloadDir || '-',
|
||
remotePlayUrl: r.remotePlayUrl || ''
|
||
};
|
||
}
|
||
} else {
|
||
alert(data.message || '获取绑定状态失败!');
|
||
}
|
||
});
|
||
},
|
||
onBackendStatusChange(status) {
|
||
this.wsClientStatus = status;
|
||
if (status === 'connected' && this.restartingBackend) {
|
||
this.restartingBackend = false;
|
||
}
|
||
},
|
||
requestBackendRestart() {
|
||
if (this.restartingBackend) {
|
||
return;
|
||
}
|
||
|
||
this.restartingBackend = true;
|
||
|
||
window.printServerAPI.callService('setting.restartBackend', {}).then((data) => {
|
||
if (!data.success || !data.result || !data.result.ok) {
|
||
this.restartingBackend = false;
|
||
alert((data.result && data.result.message) || data.message || '后端重启失败');
|
||
return;
|
||
}
|
||
|
||
this.restartingBackend = false;
|
||
// 重启后刷新数据
|
||
setTimeout(() => {
|
||
this.refreshBindStatus();
|
||
this.loadComponents();
|
||
this.loadPrinters();
|
||
}, 500);
|
||
}).catch(() => {
|
||
this.restartingBackend = false;
|
||
});
|
||
},
|
||
confirmRestartBackend() {
|
||
const confirmed = window.confirm('确认重启后端服务吗?重启过程中可能导致正在执行的打印任务失败。');
|
||
if (!confirmed) {
|
||
return;
|
||
}
|
||
|
||
this.requestBackendRestart();
|
||
},
|
||
checkUpdate(manual = false) {
|
||
if (this.updateChecking) {
|
||
return;
|
||
}
|
||
|
||
this.updateChecking = true;
|
||
window.printServerAPI.callService('update.check', {}).then((data) => {
|
||
this.updateChecking = false;
|
||
|
||
if (!data.success || !data.result || !data.result.ok) {
|
||
if (manual) {
|
||
alert((data.result && data.result.message) || data.message || '检查更新失败');
|
||
}
|
||
return;
|
||
}
|
||
|
||
const result = data.result;
|
||
this.updateState = {
|
||
...this.updateState,
|
||
hasUpdate: !!result.hasUpdate,
|
||
currentVersion: result.currentVersion || this.updateState.currentVersion,
|
||
latestVersion: result.latestVersion || this.updateState.latestVersion,
|
||
downloadUrl: result.downloadUrl || '',
|
||
message: result.hasUpdate
|
||
? `发现新版本 ${result.latestVersion}`
|
||
: `当前已是最新版本(${result.currentVersion})`
|
||
};
|
||
|
||
if (!result.hasUpdate) {
|
||
if (manual) {
|
||
alert(`当前已是最新版本(${result.currentVersion})`);
|
||
}
|
||
return;
|
||
}
|
||
|
||
const prompt = `检测到新版本 ${result.latestVersion}(当前 ${result.currentVersion}),是否在应用内下载并安装?`;
|
||
if (window.confirm(prompt)) {
|
||
this.activeTab = 'extension';
|
||
this.startInAppUpdate();
|
||
}
|
||
});
|
||
},
|
||
startInAppUpdate() {
|
||
if (this.updatingInApp) {
|
||
return;
|
||
}
|
||
|
||
if (!this.updateState.hasUpdate) {
|
||
alert('当前没有可用更新');
|
||
return;
|
||
}
|
||
|
||
if (!this.updateState.downloadUrl) {
|
||
alert('未获取到更新下载地址,请先重新检查更新');
|
||
return;
|
||
}
|
||
|
||
this.activeTab = 'extension';
|
||
|
||
this.updatingInApp = true;
|
||
this.updateState = {
|
||
...this.updateState,
|
||
status: 'starting',
|
||
percent: 0,
|
||
message: '开始下载更新包...'
|
||
};
|
||
|
||
window.printServerAPI.callService('update.downloadAndInstall', {
|
||
downloadUrl: this.updateState.downloadUrl,
|
||
version: this.updateState.latestVersion
|
||
}).then((data) => {
|
||
if (!data.success || !data.result || !data.result.ok) {
|
||
this.updatingInApp = false;
|
||
alert((data.result && data.result.message) || data.message || '启动更新失败');
|
||
return;
|
||
}
|
||
|
||
this.updateState = {
|
||
...this.updateState,
|
||
message: data.result.message || '正在下载更新包...'
|
||
};
|
||
});
|
||
},
|
||
openDownloadedInstaller() {
|
||
if (!this.updateState.filePath) {
|
||
alert('当前没有已下载的安装包');
|
||
return;
|
||
}
|
||
|
||
window.printServerAPI.callService('update.openDownloadedInstaller', {
|
||
filePath: this.updateState.filePath
|
||
}).then((data) => {
|
||
if (!data.success || !data.result || !data.result.ok) {
|
||
alert((data.result && data.result.message) || data.message || '启动安装向导失败');
|
||
return;
|
||
}
|
||
|
||
alert(data.result.message || '安装程序已启动,请在安装向导中完成更新。');
|
||
});
|
||
},
|
||
unbind() {
|
||
window.printServerAPI.callService('setting.unbind', {}).then((data) => {
|
||
if (data.success) {
|
||
this.isBind = false;
|
||
} else {
|
||
alert(data.message || '解绑失败!');
|
||
}
|
||
});
|
||
},
|
||
renderQrcode() {
|
||
console.log('[QR] renderQrcode 被调用, code:', this.code);
|
||
try {
|
||
var el = document.getElementById('qrcode');
|
||
console.log('[QR] qrcode DOM 元素:', el);
|
||
if (!el) { console.log('[QR] 容器未找到'); return; }
|
||
el.innerHTML = '';
|
||
console.log('[QR] typeof QRCode:', typeof QRCode);
|
||
if (typeof QRCode === 'undefined') { console.log('[QR] QRCode 库未加载'); return; }
|
||
this.qrcode = new QRCode(el, { width: 256, height: 256 });
|
||
console.log('[QR] QRCode 实例已创建');
|
||
if (this.code) {
|
||
var url = 'https://ye4s.wms.gztbyc.com/mini/?spm=0.5.' + this.code + '.1.4';
|
||
console.log('[QR] 生成二维码, URL:', url);
|
||
this.qrcode.makeCode(url);
|
||
console.log('[QR] makeCode 完成');
|
||
}
|
||
} catch (e) { console.error('[QR] 渲染失败:', e); }
|
||
},
|
||
installWsListener() {
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('printer.getWindowsPrinters', (data) => {
|
||
if (data.success) {
|
||
this.printers = data.result || [];
|
||
if (this.printers.length === 0) {
|
||
this.selectedPrinter = '';
|
||
} else if (!this.selectedPrinter) {
|
||
this.selectedPrinter = this.printers[0].name;
|
||
}
|
||
}
|
||
})
|
||
);
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('setting.info', (data) => {
|
||
if (data.success) {
|
||
this.isBind = data.result.isBind || false;
|
||
this.name = data.result.name || '';
|
||
if (data.result.recording) {
|
||
const r = data.result.recording;
|
||
this.recording = {
|
||
isRecording: !!r.isRecording,
|
||
maxStorage: r.maxStorage || '-',
|
||
downloadDir: r.downloadDir || '-',
|
||
remotePlayUrl: r.remotePlayUrl || ''
|
||
};
|
||
}
|
||
}
|
||
})
|
||
);
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('printerComponent.getAll', (data) => {
|
||
if (data.success) {
|
||
this.components = data.result.components || [];
|
||
this.statusList = data.result.status || [];
|
||
} else {
|
||
alert(data.message || '获取打印组件列表失败!');
|
||
}
|
||
})
|
||
);
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('printerComponent.statusChange', (data) => {
|
||
if (data.success) {
|
||
this.statusList = [...this.statusList.filter(s => s.name !== data.result.name), { name: data.result.name, status: data.result.status }];
|
||
} else {
|
||
alert(data.message || '获取打印组件列表失败!');
|
||
}
|
||
})
|
||
);
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('wsClient.statusChange', (data) => {
|
||
if (data.success) {
|
||
this.wsServerStatus = data.result.status;
|
||
} else {
|
||
alert(data.message || '获取在线状态失败!');
|
||
}
|
||
})
|
||
);
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('bind.generateCode', (data) => {
|
||
console.log('[QR] 收到 bind.generateCode 事件:', JSON.stringify(data));
|
||
if (data.success) {
|
||
this.code = data.result || '';
|
||
console.log('[QR] code 已设为:', this.code);
|
||
} else {
|
||
alert(data.message || '获取绑定码失败!');
|
||
}
|
||
})
|
||
);
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('update.downloadProgress', (data) => {
|
||
if (!data.success || !data.result) {
|
||
return;
|
||
}
|
||
|
||
this.updateState = {
|
||
...this.updateState,
|
||
...data.result,
|
||
hasUpdate: true,
|
||
latestVersion: data.result.latestVersion || this.updateState.latestVersion,
|
||
currentVersion: data.result.currentVersion || this.updateState.currentVersion,
|
||
downloadUrl: data.result.downloadUrl || this.updateState.downloadUrl
|
||
};
|
||
|
||
if (this.updatingInApp || data.result.status === 'downloading' || data.result.status === 'starting') {
|
||
this.activeTab = 'extension';
|
||
}
|
||
|
||
if (data.result.status === 'installing') {
|
||
this.updatingInApp = false;
|
||
alert('安装程序已启动,请在安装向导中完成更新。');
|
||
}
|
||
|
||
if (data.result.status === 'failed') {
|
||
this.updatingInApp = false;
|
||
alert(data.result.message || '更新失败');
|
||
}
|
||
})
|
||
);
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('setting.infoChanged', (data) => {
|
||
if (data.success && data.result) {
|
||
const r = data.result;
|
||
if (r.name !== undefined) this.name = r.name;
|
||
this.recording = {
|
||
isRecording: !!r.isRecording,
|
||
maxStorage: r.maxStorage || '-',
|
||
downloadDir: r.downloadDir || '-',
|
||
remotePlayUrl: r.remotePlayUrl || ''
|
||
};
|
||
}
|
||
})
|
||
);
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onEvent('frpc.statusChange', (data) => {
|
||
if (data.success && data.result) {
|
||
this.frpcStatus = data.result.status || 'stopped';
|
||
}
|
||
})
|
||
);
|
||
}
|
||
},
|
||
watch: {
|
||
code(val) {
|
||
console.log('[QR] code watcher 触发, 旧值->新值:', val);
|
||
if (val) {
|
||
console.log('[QR] 新的绑定码:', val);
|
||
this.renderQrcode();
|
||
} else {
|
||
console.log('[QR] code 为空, 跳过二维码渲染');
|
||
}
|
||
}
|
||
},
|
||
mounted() {
|
||
this._unsubFns = [];
|
||
|
||
// 注册 IPC 事件监听
|
||
this.installWsListener();
|
||
|
||
// 注册后端连接状态监听
|
||
this._unsubFns.push(
|
||
window.printServerAPI.onBackendStatusChange((status) => {
|
||
this.onBackendStatusChange(status);
|
||
})
|
||
);
|
||
|
||
// 初始数据加载
|
||
this.refreshBindStatus();
|
||
this.loadComponents();
|
||
this.loadPrinters();
|
||
this.loadHikConfig();
|
||
// 拉取 frpc 初始状态
|
||
window.printServerAPI.callService('frpc.getStatus', {}).then((data) => {
|
||
if (data.success && data.result) {
|
||
this.frpcStatus = data.result.status || 'stopped';
|
||
}
|
||
});
|
||
// 主动拉取远端服务器连接状态(弥补 IPC 事件早于监听注册的时序问题)
|
||
window.printServerAPI.callService('wsClient.getStatus', {}).then((data) => {
|
||
if (data.success && data.result) {
|
||
this.wsServerStatus = data.result.status;
|
||
}
|
||
});
|
||
// 弥补 IPC 事件可能早于监听注册的时序问题:主动获取缓存中的绑定码
|
||
window.printServerAPI.callService('bind.getCurrentCode', {}).then((data) => {
|
||
console.log('[QR] bind.getCurrentCode 返回:', JSON.stringify(data));
|
||
if (data.success && data.result) {
|
||
console.log('[QR] 从缓存获取到 code:', data.result);
|
||
this.code = data.result;
|
||
} else {
|
||
console.log('[QR] 缓存无 code,等待 IPC 事件');
|
||
}
|
||
});
|
||
window.printServerAPI.callService('update.getDownloadState', {}).then((data) => {
|
||
if (data.success && data.result && data.result.ok) {
|
||
this.updateState = {
|
||
...this.updateState,
|
||
...data.result,
|
||
hasUpdate: !!(data.result.latestVersion && data.result.currentVersion && data.result.latestVersion !== data.result.currentVersion)
|
||
};
|
||
}
|
||
});
|
||
|
||
// 定期刷新
|
||
// 恢复自动刷新设置
|
||
try {
|
||
var saved = JSON.parse(localStorage.getItem('hikAutoRefresh') || '{}');
|
||
if (saved.interval) this.hikAutoRefreshInterval = saved.interval;
|
||
if (saved.enabled) { this.hikAutoRefresh = true; this._startAutoRefresh(); }
|
||
} catch(e) {}
|
||
|
||
// 定期刷新绑定状态
|
||
this._refreshInterval = setInterval(() => {
|
||
this.refreshBindStatus();
|
||
}, 10000);
|
||
|
||
// 延迟检查更新
|
||
setTimeout(() => {
|
||
this.checkUpdate(false);
|
||
}, 3000);
|
||
|
||
// QRCode 重试:首次加载失败时自动重试
|
||
this._qrTimer = setInterval(function () {
|
||
var self = document.getElementById('app').__vue__;
|
||
if (!self) return;
|
||
var qrEl = document.getElementById('qrcode');
|
||
if (qrEl && qrEl.children.length > 0) { clearInterval(self._qrTimer); self._qrTimer = null; return; }
|
||
if (self.code && typeof QRCode !== 'undefined') {
|
||
self.renderQrcode();
|
||
clearInterval(self._qrTimer);
|
||
self._qrTimer = null;
|
||
}
|
||
}, 2000);
|
||
// 15 秒后停止重试
|
||
setTimeout(function () {
|
||
var self = document.getElementById('app').__vue__;
|
||
if (self && self._qrTimer) { clearInterval(self._qrTimer); self._qrTimer = null; }
|
||
}, 30000);
|
||
},
|
||
beforeDestroy() {
|
||
if (this._refreshInterval) {
|
||
clearInterval(this._refreshInterval);
|
||
this._refreshInterval = null;
|
||
}
|
||
if (this._unsubFns) {
|
||
this._unsubFns.forEach(function (fn) { if (typeof fn === 'function') fn(); });
|
||
this._unsubFns = [];
|
||
}
|
||
if (this._qrTimer) { clearInterval(this._qrTimer); this._qrTimer = null; }
|
||
if (this._hikPollTimer) { clearInterval(this._hikPollTimer); this._hikPollTimer = null; }
|
||
if (this.hikAutoRefreshTimer) { clearInterval(this.hikAutoRefreshTimer); this.hikAutoRefreshTimer = null; }
|
||
}
|
||
});
|
||
})();
|
||
|
||
// ─── 状态栏原生 JS 渲染 ───
|
||
(function renderStatusBar() {
|
||
var statusEl = document.querySelector('.statusbar');
|
||
if (!statusEl) return;
|
||
|
||
function updateSB() {
|
||
var mainApp = document.getElementById('app').__vue__;
|
||
if (!mainApp) return;
|
||
|
||
var ws = mainApp.wsStatus;
|
||
var items = statusEl.querySelectorAll('.status-item');
|
||
|
||
if (items[0]) {
|
||
var c = ws[mainApp.wsClientStatus] || ws.connected;
|
||
items[0].innerHTML = '<span class="status-dot" style="background:' + c.color + '"></span>' +
|
||
'<span>本地服务:<strong style="color:' + c.color + '">' + c.title + '</strong></span>';
|
||
}
|
||
if (items[1]) {
|
||
var s = ws[mainApp.wsServerStatus] || ws.disconnected;
|
||
items[1].innerHTML = '<span class="status-dot" style="background:' + s.color + '"></span>' +
|
||
'<span>服务器连接:<strong style="color:' + s.color + '">' + s.title + '</strong></span>';
|
||
}
|
||
if (items[2]) {
|
||
var bindC = mainApp.isBind ? '#107c10' : '#c42b1c';
|
||
var bindT = mainApp.isBind ? '已绑定' : '未绑定';
|
||
var clickable = mainApp.isBind ? 'cursor:pointer;text-decoration:underline' : '';
|
||
items[2].innerHTML = '<span class="status-dot" style="background:' + bindC + '"></span>' +
|
||
'<span>打印服务绑定:<strong style="color:' + bindC + ';' + clickable + '" id="bindStatusText">' + bindT + '</strong></span>';
|
||
}
|
||
|
||
var btns = statusEl.querySelectorAll('button');
|
||
if (btns[0]) btns[0].textContent = mainApp.updateChecking ? '检查中...' : '检查更新';
|
||
if (btns[1]) { btns[1].textContent = mainApp.restartingBackend ? '重启中...' : '重启服务'; btns[1].disabled = mainApp.restartingBackend; }
|
||
}
|
||
|
||
// 绑定按钮事件
|
||
var btnCheck = document.getElementById('btnCheckUpdate');
|
||
if (btnCheck) {
|
||
btnCheck.addEventListener('click', function () {
|
||
var mainApp = document.getElementById('app').__vue__;
|
||
if (mainApp && mainApp.checkUpdate) mainApp.checkUpdate(true);
|
||
});
|
||
}
|
||
var btnRestart = document.getElementById('btnRestartBackend');
|
||
if (btnRestart) {
|
||
btnRestart.addEventListener('click', function () {
|
||
var mainApp = document.getElementById('app').__vue__;
|
||
if (mainApp && mainApp.confirmRestartBackend) mainApp.confirmRestartBackend();
|
||
});
|
||
}
|
||
|
||
updateSB();
|
||
setInterval(updateSB, 500);
|
||
|
||
// 点击"打印服务绑定"解绑
|
||
statusEl.addEventListener('click', function (e) {
|
||
if (e.target && e.target.id === 'bindStatusText') {
|
||
var mainApp = document.getElementById('app').__vue__;
|
||
if (mainApp && mainApp.isBind && mainApp.unbind) {
|
||
if (window.confirm('确认解除绑定吗?解除后需要重新扫码绑定。')) {
|
||
mainApp.unbind();
|
||
}
|
||
}
|
||
}
|
||
});
|
||
})();
|
||
</script>
|
||
</body>
|
||
|
||
</html> |