Files
EAP_Interface_html/设置页面UI优化/DFU固件升级/baseline_ui.html
T
zhy200308 3d7be0e326 feat(ui): 升级DFU取消升级按钮为整卡贯穿动态操作条
1. 【手环升级 / DFU固件升级】:
   - 将【取消升级】由原先角落单一小按钮优化为整卡宽度 100% 贯穿式动态操作条(Full-width Dynamic Action Banner);
   - 配备内嵌取消警告图标、悬浮微动效与微发光交互;
   - 保持 360px 1fr 经典双栏比例与全局主色蓝规范 #2563EB;
   - 重新无头渲染生成官方定妆照 image.png。
2026-08-17 17:38:29 +08:00

926 lines
27 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EAPManageUI - 手环升级 (DFU固件升级 UI 重构基准)</title>
<style>
/* =========================================================================
:root 全量 Design Tokens 声明 (严格遵循全局核心主色蓝 #2563EB 标准)
========================================================================= */
:root {
/* ── 核心主题色 (Global Primary Blue Standard) ── */
--color-primary: #2563EB;
--color-primary-dark: #1D4ED8;
--color-on-primary-container: #1E40AF;
--color-primary-light: #EFF6FF;
--color-primary-container: #EFF6FF;
--color-primary-border: #DBEAFE;
--color-primary-glow: rgba(37, 99, 235, 0.25);
--color-primary-gradient: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
/* ── 表面与背景 ── */
--color-surface: #FFFFFF;
--color-surface-variant: #F8FAFC;
--color-background: #EEF2F6;
/* ── 文本语义色 ── */
--text-main: #0F172A;
--text-sub: #64748B;
--text-dim: #94A3B8;
/* ── 边框与分割线 ── */
--divider: #E2E8F0;
--border-card: #E2E8F0;
--border-light: rgba(0, 0, 0, 0.05);
/* ── 语义警示与成功 ── */
--warning: #F59E0B;
--warning-light: #FEF3C7;
--warning-border: #FDE68A;
--warning-text: #D97706;
--success: #10B981;
--success-light: #ECFDF5;
--terminal-bg: #0F172A;
/* ── 圆角与阴影 ── */
--corner-card: 16px;
--corner-item: 10px;
--shadow-card: 0 4px 16px rgba(15, 23, 42, 0.03);
--shadow-hover: 0 8px 24px rgba(15, 23, 42, 0.05);
/* ── 尺寸与栅格 ── */
--content-max-width: 1160px;
--content-gutter: clamp(16px, 2.5vw, 32px);
--appbar-height: 60px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Segoe UI", Roboto, sans-serif;
background: var(--color-background);
color: var(--text-main);
min-height: 100vh;
padding: var(--content-gutter);
display: flex;
flex-direction: column;
}
/* 视口模拟器容器 (大屏动态自适应) */
.device-wrapper {
width: 100%;
max-width: var(--content-max-width);
margin: 0 auto;
background: var(--color-surface);
border-radius: 20px;
border: 1px solid var(--divider);
box-shadow: 0 16px 40px -10px rgba(15, 23, 42, 0.08);
overflow: hidden;
position: relative;
min-height: 640px;
display: flex;
flex-direction: column;
}
/* =========================================================================
1. AppBar 顶部导航栏统一规范 (40dp 纯净透明触控槽 + Hover 微圆底)
========================================================================= */
.appbar {
height: var(--appbar-height);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
border-bottom: 1px solid var(--divider);
background: var(--color-surface);
flex-shrink: 0;
}
.appbar-left { display: flex; align-items: center; }
.appbar-nav, .appbar-more {
width: 40px;
height: 40px;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
background: transparent;
border: none;
transition: all 0.15s ease;
}
.appbar-nav:hover, .appbar-more:hover {
background: rgba(15, 23, 42, 0.06);
transform: scale(0.96);
}
.appbar-nav svg, .appbar-more svg {
width: 22px;
height: 22px;
fill: var(--text-main);
}
.appbar-title {
font-size: 19px;
font-weight: 700;
margin-left: 10px;
letter-spacing: -0.01em;
}
/* =========================================================================
2. 主体流体双栏仪表盘 (360px 1fr 经典比例,严格对齐语言设置与版型切换规范)
========================================================================= */
.main-dashboard {
padding: clamp(20px, 2.5vw, 30px);
display: grid;
grid-template-columns: 360px 1fr;
gap: clamp(16px, 2vw, 24px);
background: var(--color-surface-variant);
flex: 1;
overflow-y: auto;
max-height: calc(100vh - 120px);
align-items: stretch;
}
.dash-column {
display: flex;
flex-direction: column;
gap: 16px;
}
.card-box {
background: var(--color-surface);
border: 1.5px solid var(--border-card);
border-radius: var(--corner-card);
padding: 20px 22px;
display: flex;
flex-direction: column;
gap: 14px;
box-shadow: var(--shadow-card);
transition: all 0.2s ease;
}
.card-box:hover {
box-shadow: var(--shadow-hover);
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--divider);
padding-bottom: 10px;
}
.card-title {
font-size: 15.5px;
font-weight: 700;
color: var(--color-primary);
display: flex;
align-items: center;
gap: 8px;
}
.conn-badge {
font-size: 12px;
font-weight: 700;
padding: 3px 9px;
border-radius: 100px;
background: #F1F5F9;
color: var(--text-sub);
}
.conn-badge.online {
background: var(--success-light);
color: var(--success);
}
/* 2.1 方案5 Inset 经典属性胶囊条 */
.prop-pill-grid {
display: flex;
flex-direction: column;
gap: 8px;
}
.prop-pill-row {
background: #F8FAFC;
border: 1px solid var(--divider);
border-radius: 8px;
padding: 9px 14px;
display: flex;
align-items: center;
justify-content: space-between;
transition: all 0.15s ease;
}
.prop-pill-row:hover {
background: #FFFFFF;
border-color: #CBD5E1;
}
.prop-pill-k {
font-size: 12.5px;
color: var(--text-sub);
font-weight: 600;
}
.prop-pill-v {
font-size: 13.5px;
font-weight: 700;
color: var(--text-main);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.btn-cancel-upgrade {
width: 100%;
height: 42px;
background: var(--warning-light);
color: var(--warning-text);
border: 1.5px solid var(--warning-border);
border-radius: var(--corner-item);
font-size: 13.5px;
font-weight: 700;
cursor: pointer;
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin-top: 2px;
}
.btn-cancel-upgrade svg {
width: 16px;
height: 16px;
fill: currentColor;
transition: transform 0.2s ease;
}
.btn-cancel-upgrade:hover {
background: #FDE68A;
border-color: #F59E0B;
transform: translateY(-1px);
box-shadow: 0 4px 14px rgba(245, 158, 11, 0.18);
}
.btn-cancel-upgrade:hover svg {
transform: scale(1.15) rotate(90deg);
}
.btn-cancel-upgrade:active {
transform: translateY(0);
}
/* 2.2 固件包信息卡片 */
.firmware-meta-card {
background: #F8FAFC;
border: 1px solid var(--divider);
border-radius: 10px;
padding: 12px 14px;
display: flex;
flex-direction: column;
gap: 6px;
}
.fw-name-text {
font-size: 13px;
font-weight: 700;
color: var(--text-main);
font-family: ui-monospace, monospace;
word-break: break-all;
line-height: 1.4;
}
.fw-source-tag {
font-size: 11.5px;
font-weight: 700;
color: var(--color-primary);
}
.fw-action-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.btn-fw-action {
background: #FFFFFF;
border: 1.5px solid var(--divider);
border-radius: 8px;
padding: 9px 12px;
font-size: 13px;
font-weight: 700;
color: var(--color-primary);
cursor: pointer;
transition: all 0.15s ease;
text-align: center;
}
.btn-fw-action:hover {
border-color: var(--color-primary);
background: var(--color-primary-light);
}
/* 2.3 升级进度与控制台 */
.progress-track-box {
display: flex;
flex-direction: column;
gap: 8px;
background: #F8FAFC;
border: 1px solid var(--divider);
border-radius: 10px;
padding: 12px 14px;
}
.progress-info-row {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 13px;
font-weight: 700;
}
.progress-bar-bg {
width: 100%;
height: 9px;
background: #E2E8F0;
border-radius: 100px;
overflow: hidden;
}
.progress-bar-fill {
width: 0%;
height: 100%;
background: var(--color-primary-gradient);
border-radius: 100px;
transition: width 0.3s ease;
}
.btn-start-upgrade {
width: 100%;
background: var(--color-primary-gradient);
color: white;
border: none;
padding: 12px;
border-radius: 10px;
font-size: 14.5px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 4px 14px var(--color-primary-glow);
transition: all 0.2s ease;
}
.btn-start-upgrade:hover {
transform: translateY(-1px);
box-shadow: 0 6px 18px var(--color-primary-glow);
}
.terminal-hud {
background: var(--terminal-bg);
border-radius: 10px;
border: 1px solid #334155;
padding: 12px 14px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11.5px;
color: #94A3B8;
height: 150px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 4px;
flex: 1;
}
.term-line { line-height: 1.5; }
.term-line.info { color: #38BDF8; }
.term-line.success { color: #4ADE80; }
.term-line.warn { color: #FBBF24; }
/* =========================================================================
3. 右下角悬浮蓝牙按钮 (FAB)
========================================================================= */
.bluetooth-fab {
position: absolute;
bottom: 24px;
right: 24px;
width: 52px;
height: 52px;
border-radius: 16px;
background: var(--color-surface);
border: 1.5px solid var(--divider);
box-shadow: 0 10px 25px rgba(15, 23, 42, 0.15);
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
z-index: 50;
}
.bluetooth-fab:hover {
transform: scale(1.08) translateY(-2px);
border-color: var(--color-primary);
box-shadow: 0 14px 30px var(--color-primary-glow);
}
.bluetooth-fab svg {
width: 24px;
height: 24px;
fill: var(--color-primary);
}
/* =========================================================================
4. 居中底部抽拉式 Sheet (Centered Bottom Drawer)
========================================================================= */
.bottom-sheet-mask {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(15, 23, 42, 0.45);
backdrop-filter: blur(4px);
z-index: 100;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s ease;
}
.bottom-sheet-mask.open {
opacity: 1;
pointer-events: auto;
}
.bottom-sheet {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%) translateY(100%);
width: min(92%, 560px);
background: var(--color-surface);
border-radius: 24px 24px 0 0;
border: 1.5px solid var(--divider);
border-bottom: none;
box-shadow: 0 -16px 45px rgba(15, 23, 42, 0.2);
transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
display: flex;
flex-direction: column;
max-height: 490px;
z-index: 101;
}
.bottom-sheet-mask.open .bottom-sheet {
transform: translateX(-50%) translateY(0);
}
.sheet-handle-bar {
width: 44px;
height: 5px;
border-radius: 10px;
background: #CBD5E1;
margin: 10px auto 4px;
cursor: grab;
}
.sheet-head {
padding: 12px 24px 14px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--divider);
}
.sheet-title-box {
display: flex;
align-items: center;
gap: 10px;
}
.radar-scanner {
position: relative;
width: 34px;
height: 34px;
border-radius: 50%;
background: var(--color-primary-light);
display: flex;
align-items: center;
justify-content: center;
}
.radar-ring {
position: absolute;
width: 100%;
height: 100%;
border-radius: 50%;
border: 2px solid var(--color-primary);
animation: radarWave 1.8s infinite ease-out;
}
@keyframes radarWave {
0% { transform: scale(0.6); opacity: 1; }
100% { transform: scale(1.6); opacity: 0; }
}
.radar-scanner svg {
width: 18px;
height: 18px;
fill: var(--color-primary);
z-index: 2;
}
.sheet-close-btn {
width: 32px;
height: 32px;
border-radius: 50%;
border: none;
background: #F1F5F9;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
color: var(--text-sub);
font-size: 16px;
font-weight: 700;
transition: all 0.15s;
}
.sheet-close-btn:hover {
background: #E2E8F0;
color: var(--text-main);
}
.sheet-chips-line {
padding: 10px 24px;
background: #F8FAFC;
display: flex;
gap: 8px;
border-bottom: 1px solid var(--divider);
overflow-x: auto;
}
.filter-chip {
padding: 5px 14px;
border-radius: 100px;
font-size: 12px;
font-weight: 600;
border: 1px solid var(--divider);
background: white;
cursor: pointer;
white-space: nowrap;
transition: all 0.15s ease;
}
.filter-chip.active {
background: var(--color-primary-light);
color: var(--color-primary);
border-color: var(--color-primary-border);
}
.sheet-device-list {
padding: 14px 24px;
display: flex;
flex-direction: column;
gap: 10px;
overflow-y: auto;
max-height: 220px;
}
.device-item-card {
border: 1.5px solid var(--divider);
border-radius: 14px;
padding: 12px 16px;
display: flex;
align-items: center;
justify-content: space-between;
background: white;
transition: all 0.15s ease;
cursor: pointer;
}
.device-item-card:hover {
border-color: var(--color-primary);
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
}
.dev-badge-ble-right {
background: var(--color-primary-light);
color: var(--color-primary);
font-size: 12px;
font-weight: 800;
padding: 4px 10px;
border-radius: 6px;
border: 1px solid var(--color-primary-border);
letter-spacing: 0.5px;
}
.sheet-foot {
padding: 14px 24px 20px;
border-top: 1px solid var(--divider);
background: #F8FAFC;
}
.btn-pause-scan {
width: 100%;
background: #DCFCE7;
color: #15803D;
border: 1px solid #BBF7D0;
padding: 10px;
border-radius: 12px;
font-size: 13.5px;
font-weight: 700;
cursor: pointer;
transition: all 0.15s;
}
@media (max-width: 768px) {
.main-dashboard {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="device-wrapper">
<!-- 1. AppBar 顶部导航栏 -->
<header class="appbar">
<div class="appbar-left">
<button class="appbar-nav" title="返回"><svg viewBox="0 0 24 24"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></svg></button>
<h1 class="appbar-title">手环升级</h1>
</div>
<button class="appbar-more"><svg viewBox="0 0 24 24"><path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/></svg></button>
</header>
<!-- 2. 主体双栏仪表盘布局 (1:1 均分占比,严格对齐手环配置与系统设置规范) -->
<main class="main-dashboard">
<!-- 左列:待升级手环与固件包配置 -->
<div class="dash-column">
<!-- 待升级手环状态卡片 (方案5 Inset 经典属性胶囊) -->
<section class="card-box">
<div class="card-header">
<span class="card-title">待升级手环状态</span>
<span class="conn-badge" id="targetConnBadge">状态:未连接</span>
</div>
<div class="prop-pill-grid">
<div class="prop-pill-row">
<span class="prop-pill-k">手环 ID</span>
<span class="prop-pill-v" id="devIdVal">未连接</span>
</div>
<div class="prop-pill-row">
<span class="prop-pill-k">当前版本</span>
<span class="prop-pill-v" id="devVerVal">未知</span>
</div>
<div class="prop-pill-row">
<span class="prop-pill-k">剩余电量</span>
<span class="prop-pill-v" id="devBatVal">未知</span>
</div>
</div>
<button class="btn-cancel-upgrade" id="btnCancelUpgrade" onclick="cancelUpgrade()">
<svg viewBox="0 0 24 24"><path d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z"/></svg>
<span>取消升级</span>
</button>
</section>
<!-- 固件包信息与源卡片 -->
<section class="card-box">
<div class="card-header">
<span class="card-title">固件包与版本源</span>
</div>
<div class="firmware-meta-card">
<div class="fw-name-text" id="fwFileName">SC106_FW1.00.0036_HW0.1_20260720_DFU.zip (内置 v1.00.0036)</div>
<div class="fw-source-tag">固件来源: 内置 (优先)</div>
</div>
<div class="fw-action-grid">
<button class="btn-fw-action" onclick="checkServerFw()">检查服务端版本</button>
<button class="btn-fw-action" onclick="useBuiltinFw()">使用内置固件</button>
</div>
</section>
</div>
<!-- 右列:升级进度与日志控制台 -->
<div class="dash-column">
<section class="card-box" style="flex: 1;">
<div class="card-header">
<span class="card-title">升级进度与控制</span>
<span id="stageBadge" style="font-size: 12px; font-weight: 700; color: var(--color-primary);">等待就绪</span>
</div>
<div class="progress-track-box">
<div class="progress-info-row">
<span>升级进度</span>
<span id="progressPercent" style="color: var(--color-primary);">0%</span>
</div>
<div class="progress-bar-bg">
<div class="progress-bar-fill" id="progressBar"></div>
</div>
<div style="font-size: 12px; color: var(--text-sub); display: flex; justify-content: space-between;">
<span id="progressStatus">状态: 待开始</span>
<span id="speedTxt">传输速率: -- KB/s</span>
</div>
</div>
<button class="btn-start-upgrade" id="btnStartDfu" onclick="startDfuProcess()">开始升级</button>
<!-- 同步日志控制台 -->
<div style="display: flex; flex-direction: column; gap: 6px; flex: 1; margin-top: 4px;">
<span style="font-size: 13px; font-weight: 700; color: var(--text-main);">升级日志控制台</span>
<div class="terminal-hud" id="dfuTerminal">
<div class="term-line info">[DFU-Core] 固件升级引导服务已就绪...</div>
<div class="term-line">等待配对手环并下发 DFU 引导指令...</div>
</div>
</div>
</section>
</div>
</main>
<!-- 右下角悬浮蓝牙按钮 (FAB) -->
<button class="bluetooth-fab" onclick="openBottomSheet()" title="扫描并选择待升级手环">
<svg viewBox="0 0 24 24"><path d="M17.71 7.71L12 2h-1v7.59L6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 11 14.41V22h1l5.71-5.71-4.3-4.29 4.3-4.29zM13 5.83l1.88 1.88L13 9.59V5.83zm1.88 10.46L13 18.17v-3.76l1.88 1.88z"/></svg>
</button>
<!-- 居中底部抽拉式 Sheet (560px 居中) -->
<div class="bottom-sheet-mask" id="sheetMask" onclick="if(event.target===this) closeBottomSheet()">
<div class="bottom-sheet">
<div class="sheet-handle-bar"></div>
<div class="sheet-head">
<div class="sheet-title-box">
<div class="radar-scanner">
<div class="radar-ring"></div>
<svg viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>
</div>
<h2 style="font-size: 16px; font-weight: 700;">选择设备</h2>
</div>
<button class="sheet-close-btn" onclick="closeBottomSheet()">✕</button>
</div>
<div class="sheet-chips-line">
<span class="filter-chip active" onclick="toggleChip(this)">✓ 扫描顺序</span>
<span class="filter-chip" onclick="toggleChip(this)">名称</span>
<span class="filter-chip" onclick="toggleChip(this)">信号强度</span>
<span class="filter-chip" onclick="toggleChip(this)">类型</span>
</div>
<div class="sheet-device-list">
<div class="device-item-card" onclick="connectTarget('CL831-62200026', 'v1.00.0035', '88%')">
<div>
<div style="font-weight: 700; font-size: 14.5px; font-family: monospace;">CL831-62200026</div>
<div style="font-size: 11.5px; color: var(--text-sub); margin-top: 3px;">D9:24:0F:1C:55:FA · 信号: -89 dBm</div>
</div>
<span class="dev-badge-ble-right">BLE</span>
</div>
<div class="device-item-card" onclick="connectTarget('CL831-2200006', 'v1.00.0032', '95%')">
<div>
<div style="font-weight: 700; font-size: 14.5px; font-family: monospace;">CL831-2200006</div>
<div style="font-size: 11.5px; color: var(--text-sub); margin-top: 3px;">DF:16:BC:22:2E:5B · 信号: -98 dBm</div>
</div>
<span class="dev-badge-ble-right">BLE</span>
</div>
</div>
<div class="sheet-foot">
<button class="btn-pause-scan" id="btnScan" onclick="toggleScan()">暂停扫描</button>
</div>
</div>
</div>
</div>
<script>
let isConnected = false;
let isUpgrading = false;
let upgradeTimer = null;
function appendLog(t, type = '') {
const b = document.getElementById('dfuTerminal');
const d = document.createElement('div');
d.className = `term-line ${type}`;
d.innerText = `[${new Date().toTimeString().split(' ')[0]}] ${t}`;
b.appendChild(d);
b.scrollTop = b.scrollHeight;
}
function openBottomSheet() {
document.getElementById('sheetMask').classList.add('open');
appendLog("展开【选择设备】面板,正在侦听周围待升级 BLE 广播...", "info");
}
function closeBottomSheet() {
document.getElementById('sheetMask').classList.remove('open');
}
function toggleChip(el) {
document.querySelectorAll('.filter-chip').forEach(c => {
c.classList.remove('active');
c.innerText = c.innerText.replace('✓ ', '');
});
el.classList.add('active');
el.innerText = '✓ ' + el.innerText;
appendLog(`切换设备扫描排序: ${el.innerText}`, "info");
}
function connectTarget(name, ver, bat) {
closeBottomSheet();
appendLog(`正在连接待升级手环 [${name}]...`, "info");
setTimeout(() => {
isConnected = true;
document.getElementById('devIdVal').innerText = name;
document.getElementById('devVerVal').innerText = ver;
document.getElementById('devBatVal').innerText = bat;
document.getElementById('targetConnBadge').innerText = "状态:已就绪";
document.getElementById('targetConnBadge').classList.add('online');
document.getElementById('stageBadge').innerText = "可开始升级";
appendLog(`已成功与 [${name}] 建立 DFU 控制信道,当前版本: ${ver},电量充足 (${bat})。`, "success");
}, 600);
}
function startDfuProcess() {
if (!isConnected) {
alert("请先点击右下角蓝牙按钮选择待升级手环!");
openBottomSheet();
return;
}
if (isUpgrading) return;
isUpgrading = true;
let progress = 0;
document.getElementById('btnStartDfu').disabled = true;
document.getElementById('btnStartDfu').innerText = "正在传输固件...";
document.getElementById('progressStatus').innerText = "状态: 固件分包传输中 (GATT Write No Response)";
document.getElementById('stageBadge').innerText = "传输中 (0%)";
appendLog("启动 DFU 传输协议,握手 Secure Bootloader 校验公钥...", "info");
upgradeTimer = setInterval(() => {
progress += Math.floor(Math.random() * 8) + 5;
if (progress > 100) progress = 100;
document.getElementById('progressBar').style.width = progress + '%';
document.getElementById('progressPercent').innerText = progress + '%';
document.getElementById('stageBadge').innerText = `传输中 (${progress}%)`;
document.getElementById('speedTxt').innerText = `传输速率: ${(Math.random()*4 + 18).toFixed(1)} KB/s`;
if (progress >= 100) {
clearInterval(upgradeTimer);
document.getElementById('progressStatus').innerText = "状态: CRC 校验成功,手环正在重启应用新固件...";
document.getElementById('stageBadge').innerText = "升级完成";
document.getElementById('devVerVal').innerText = "v1.00.0036 (已最新)";
document.getElementById('btnStartDfu').innerText = "升级完成";
appendLog("固件数据包 100% 写入完成,CRC32 校验通过!手环正在重启生效...", "success");
setTimeout(() => {
alert("手环固件升级成功!新版本已生效。");
document.getElementById('btnStartDfu').disabled = false;
document.getElementById('btnStartDfu').innerText = "开始升级";
isUpgrading = false;
}, 1000);
}
}, 400);
}
function cancelUpgrade() {
if (isUpgrading) {
clearInterval(upgradeTimer);
isUpgrading = false;
document.getElementById('btnStartDfu').disabled = false;
document.getElementById('btnStartDfu').innerText = "开始升级";
document.getElementById('progressBar').style.width = '0%';
document.getElementById('progressPercent').innerText = '0%';
document.getElementById('progressStatus').innerText = "状态: 升级已取消";
document.getElementById('stageBadge').innerText = "已中断";
appendLog("用户手动触发 [取消升级],已终止固件传输。", "warn");
alert("已取消手环固件升级。");
} else {
appendLog("当前未处于升级传输过程中。", "info");
}
}
function checkServerFw() {
appendLog("正在请求服务端云端固件库 API...", "info");
setTimeout(() => {
appendLog("检查完成:当前内置固件 v1.00.0036 已为官方最新稳定版。", "success");
alert("服务端版本检查:当前内置固件已是最新版!");
}, 800);
}
function useBuiltinFw() {
appendLog("已切换为本地内置固件源:SC106_FW1.00.0036_HW0.1_20260720_DFU.zip", "info");
alert("已切换并锁定为本地内置固件!");
}
function toggleScan() {
const b = document.getElementById('btnScan');
if (b.innerText === "暂停扫描") {
b.innerText = "继续扫描";
b.style.background = "#FEF3C7";
b.style.color = "#D97706";
appendLog("已暂停 BLE 设备广播扫描。", "warn");
} else {
b.innerText = "暂停扫描";
b.style.background = "#DCFCE7";
b.style.color = "#15803D";
appendLog("已恢复 BLE 广播扫描...", "info");
}
}
</script>
</body>
</html>