fix(ota): 版本信息升级流对齐全自动代码逻辑 (下载->校验->写入->自动重启无需二次点击)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>版本信息 - Master-Detail Inset Station (OTA 下载进度与状态联动版)</title>
|
||||
<title>版本信息 - Master-Detail Inset Station (全自动 OTA 升级流)</title>
|
||||
<style>
|
||||
/* =========================================================================
|
||||
全局统一色彩与 Design Tokens (严格对齐 #2563EB 体系)
|
||||
@@ -103,7 +103,7 @@ body {
|
||||
font-family: ui-monospace, monospace;
|
||||
}
|
||||
|
||||
/* OTA 系统更新卡片 (内嵌高质感动态进度条) */
|
||||
/* OTA 系统更新卡片 (内嵌全自动进度展开) */
|
||||
.ota-update-card {
|
||||
background: var(--color-primary-light); border: 1.5px solid var(--color-primary-border); border-radius: 12px;
|
||||
padding: 16px; display: flex; flex-direction: column; gap: 12px; transition: all 0.3s ease;
|
||||
@@ -121,7 +121,7 @@ body {
|
||||
}
|
||||
.ota-version-code { font-size: 16px; font-weight: 800; color: var(--color-primary); font-family: ui-monospace, monospace; }
|
||||
|
||||
/* 动态进度条区域 (下载时平滑展示) */
|
||||
/* 动态全自动进度条区域 */
|
||||
.download-progress-block {
|
||||
display: none; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px dashed var(--color-primary-border);
|
||||
}
|
||||
@@ -144,7 +144,7 @@ body {
|
||||
display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-dim); font-family: ui-monospace, monospace;
|
||||
}
|
||||
|
||||
/* 底部贯穿式升级按钮组 */
|
||||
/* 底部贯穿式按钮 (全自动运行态) */
|
||||
.btn-dynamic-full {
|
||||
width: 100%; height: 46px; border-radius: 10px; font-size: 14px; font-weight: 700; cursor: pointer;
|
||||
display: flex; align-items: center; justify-content: center; gap: 8px; transition: all 0.2s ease;
|
||||
@@ -156,16 +156,14 @@ body {
|
||||
}
|
||||
.btn-primary-gradient:hover { transform: translateY(-1px); box-shadow: 0 6px 16px var(--color-primary-glow); }
|
||||
|
||||
.btn-success-gradient {
|
||||
background: var(--color-success-gradient); color: white;
|
||||
box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
|
||||
.btn-running-state {
|
||||
background: #F1F5F9; color: var(--text-sub); border: 1.5px solid #CBD5E1; cursor: not-allowed;
|
||||
box-shadow: none; pointer-events: none;
|
||||
}
|
||||
.btn-success-gradient:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(5, 150, 105, 0.35); }
|
||||
|
||||
.btn-downloading-ghost {
|
||||
background: #FFFFFF; color: var(--text-main); border: 1.5px solid #CBD5E1;
|
||||
.btn-reboot-state {
|
||||
background: var(--color-success-gradient); color: white; border: none; cursor: not-allowed;
|
||||
box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3); pointer-events: none;
|
||||
}
|
||||
.btn-downloading-ghost:hover { background: #F1F5F9; border-color: var(--text-sub); }
|
||||
|
||||
/* 右侧 1fr 设备与底层系统信息矩阵 */
|
||||
.right-details-panel {
|
||||
@@ -224,7 +222,7 @@ body {
|
||||
<div class="app-version-badge">版本号 1.00.0000</div>
|
||||
</div>
|
||||
|
||||
<!-- 系统更新卡片 (内嵌动态展开进度条) -->
|
||||
<!-- 系统更新卡片 (全自动下载与安装重启流) -->
|
||||
<div class="ota-update-card" id="otaCard">
|
||||
<div class="ota-card-title">
|
||||
<span>系统更新</span>
|
||||
@@ -252,9 +250,9 @@ body {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部贯穿式升级与多态操作按钮 -->
|
||||
<!-- 底部贯穿式升级操作按钮 -->
|
||||
<div>
|
||||
<button class="btn-dynamic-full btn-primary-gradient" id="btnUpdateAction" onclick="handleUpdateActionClick()">
|
||||
<button class="btn-dynamic-full btn-primary-gradient" id="btnUpdateAction" onclick="handleStartAutoOTA()">
|
||||
<svg style="width: 17px; height: 17px; fill: currentColor;" id="btnActionIcon" viewBox="0 0 24 24"><path d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM17 13l-5 5-5-5h3V9h4v4h3z"/></svg>
|
||||
<span id="btnActionText">下载更新 (1.00.0001)</span>
|
||||
</button>
|
||||
@@ -309,68 +307,69 @@ body {
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let downloadState = 'IDLE'; // IDLE | DOWNLOADING | PAUSED | COMPLETED
|
||||
let isRunning = false;
|
||||
let progress = 0;
|
||||
let timer = null;
|
||||
const totalSize = 38.4; // MB
|
||||
|
||||
function handleUpdateActionClick() {
|
||||
function handleStartAutoOTA() {
|
||||
if (isRunning) return;
|
||||
isRunning = true;
|
||||
|
||||
const btn = document.getElementById('btnUpdateAction');
|
||||
const btnText = document.getElementById('btnActionText');
|
||||
const badge = document.getElementById('otaBadge');
|
||||
const progressBlock = document.getElementById('progressBlock');
|
||||
const fill = document.getElementById('progressFill');
|
||||
const percentText = document.getElementById('progressPercent');
|
||||
const stateText = document.getElementById('progressStateText');
|
||||
const mbStats = document.getElementById('progressMbStats');
|
||||
const speedStats = document.getElementById('progressSpeedStats');
|
||||
|
||||
if (downloadState === 'IDLE') {
|
||||
// 开始下载
|
||||
downloadState = 'DOWNLOADING';
|
||||
progressBlock.style.display = 'flex';
|
||||
badge.innerText = '下载中';
|
||||
badge.style.background = '#FFFBEB';
|
||||
badge.style.color = '#D97706';
|
||||
btn.className = 'btn-dynamic-full btn-downloading-ghost';
|
||||
btnText.innerText = '暂停下载';
|
||||
// 1. 触发下载
|
||||
progressBlock.style.display = 'flex';
|
||||
badge.innerText = '正在自动下载';
|
||||
badge.style.background = '#FFFBEB';
|
||||
badge.style.color = '#D97706';
|
||||
btn.className = 'btn-dynamic-full btn-running-state';
|
||||
btnText.innerText = '⚡ 正在自动升级中 (不可断电)...';
|
||||
|
||||
timer = setInterval(() => {
|
||||
if (progress < 100) {
|
||||
progress += Math.floor(Math.random() * 8) + 4;
|
||||
if (progress > 100) progress = 100;
|
||||
fill.style.width = `${progress}%`;
|
||||
percentText.innerText = `${progress}%`;
|
||||
const currentMb = ((progress / 100) * totalSize).toFixed(1);
|
||||
mbStats.innerText = `${currentMb} MB / ${totalSize} MB`;
|
||||
speedStats.innerText = `${(Math.random() * 0.8 + 2.2).toFixed(1)} MB/s`;
|
||||
const timer = setInterval(() => {
|
||||
if (progress < 100) {
|
||||
progress += Math.floor(Math.random() * 8) + 4;
|
||||
if (progress > 100) progress = 100;
|
||||
fill.style.width = `${progress}%`;
|
||||
percentText.innerText = `${progress}%`;
|
||||
const currentMb = ((progress / 100) * totalSize).toFixed(1);
|
||||
mbStats.innerText = `${currentMb} MB / ${totalSize} MB`;
|
||||
speedStats.innerText = `${(Math.random() * 0.8 + 2.2).toFixed(1)} MB/s`;
|
||||
|
||||
if (progress === 100) {
|
||||
clearInterval(timer);
|
||||
downloadState = 'COMPLETED';
|
||||
badge.innerText = '验证通过';
|
||||
badge.style.background = '#ECFDF5';
|
||||
badge.style.color = '#059669';
|
||||
document.getElementById('progressStateText').innerText = '固件包下载完成 (SHA256 校验通过)';
|
||||
btn.className = 'btn-dynamic-full btn-success-gradient';
|
||||
btnText.innerText = '⚡ 立即安装并重启';
|
||||
}
|
||||
// 2. 达到 100% 后自动无缝进入校验与重启倒计时,无需用户再次点击
|
||||
if (progress === 100) {
|
||||
clearInterval(timer);
|
||||
stateText.innerText = '固件包下载完成,正在自动校验 SHA256 与写入系统分区...';
|
||||
badge.innerText = '校验与安装中';
|
||||
badge.style.background = '#ECFDF5';
|
||||
badge.style.color = '#059669';
|
||||
|
||||
setTimeout(() => {
|
||||
stateText.innerText = '✅ 固件更新就绪!系统将在 3 秒后自动重启生效...';
|
||||
btn.className = 'btn-dynamic-full btn-reboot-state';
|
||||
btnText.innerText = '🔄 正在自动重启系统...';
|
||||
|
||||
let countdown = 3;
|
||||
const cdTimer = setInterval(() => {
|
||||
countdown--;
|
||||
if (countdown > 0) {
|
||||
stateText.innerText = `✅ 固件更新就绪!系统将在 ${countdown} 秒后自动重启生效...`;
|
||||
} else {
|
||||
clearInterval(cdTimer);
|
||||
stateText.innerText = '🔄 系统重启中...';
|
||||
}
|
||||
}, 1000);
|
||||
}, 1200);
|
||||
}
|
||||
}, 300);
|
||||
} else if (downloadState === 'DOWNLOADING') {
|
||||
// 暂停
|
||||
clearInterval(timer);
|
||||
downloadState = 'PAUSED';
|
||||
badge.innerText = '已暂停';
|
||||
btnText.innerText = '继续下载';
|
||||
} else if (downloadState === 'PAUSED') {
|
||||
// 继续
|
||||
downloadState = 'DOWNLOADING';
|
||||
badge.innerText = '下载中';
|
||||
btnText.innerText = '暂停下载';
|
||||
handleUpdateActionClick();
|
||||
} else if (downloadState === 'COMPLETED') {
|
||||
alert('正在触发系统 OTA 升级安装... 系统将自动重启并更新至 v1.00.0001');
|
||||
}
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user