163 lines
6.1 KiB
JavaScript
163 lines
6.1 KiB
JavaScript
/**
|
|
* 泡沫轴交互控制逻辑 (无弹窗纯净版)
|
|
* 支持:已连接/未连接动态双态流转、真实倒计时启停与时长调节、动作/肌群/力量多维参数切换与保存。
|
|
*/
|
|
|
|
let isConnected = true;
|
|
let isRunning = false;
|
|
let totalSeconds = 178; // 默认 02:58
|
|
let timerInterval = null;
|
|
let currentMode = 'auto';
|
|
let currentAction = '游泳';
|
|
let currentMuscle = '前臂';
|
|
let currentStrength = 4;
|
|
|
|
const SVG_DISCONNECTED = `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="140" height="60" viewBox="0 0 140 60"><ellipse cx="22" cy="30" rx="12" ry="20" fill="%23F1F5F9" stroke="%2394A3B8" stroke-width="2"/><rect x="22" y="10" width="96" height="40" rx="4" fill="%23F8FAFC" stroke="%23CBD5E1" stroke-width="2"/><ellipse cx="118" cy="30" rx="12" ry="20" fill="%23E2E8F0" stroke="%2394A3B8" stroke-width="2"/><line x1="38" y1="10" x2="38" y2="50" stroke="%23CBD5E1" stroke-width="1.5" stroke-dasharray="3 3"/><line x1="56" y1="10" x2="56" y2="50" stroke="%23CBD5E1" stroke-width="1.5" stroke-dasharray="3 3"/><line x1="74" y1="10" x2="74" y2="50" stroke="%23CBD5E1" stroke-width="1.5" stroke-dasharray="3 3"/><line x1="92" y1="10" x2="92" y2="50" stroke="%23CBD5E1" stroke-width="1.5" stroke-dasharray="3 3"/><circle cx="70" cy="30" r="8" fill="%2394A3B8"/></svg>`;
|
|
|
|
function formatTime(sec) {
|
|
const m = Math.floor(sec / 60).toString().padStart(2, '0');
|
|
const s = (sec % 60).toString().padStart(2, '0');
|
|
return `${m}:${s}`;
|
|
}
|
|
|
|
function handleNavBack() {
|
|
// 无弹窗直接返回
|
|
}
|
|
|
|
function handleScanRefresh() {
|
|
const statusEl = document.getElementById('scanStatusText');
|
|
statusEl.innerText = '正在重新扫描周边设备...';
|
|
setTimeout(() => {
|
|
statusEl.innerText = '自动扫描中';
|
|
}, 1200);
|
|
}
|
|
|
|
function toggleConnectState() {
|
|
isConnected = !isConnected;
|
|
const img = document.getElementById('productImg');
|
|
const valId = document.getElementById('valId');
|
|
const valVer = document.getElementById('valVer');
|
|
const valBat = document.getElementById('valBat');
|
|
const btnToggle = document.getElementById('btnToggleConn');
|
|
const timer = document.getElementById('dispTimer');
|
|
const centerPanel = document.getElementById('centerTimerPanel');
|
|
const rightPanel = document.getElementById('rightConfigPanel');
|
|
|
|
if (isConnected) {
|
|
// 切换为已连接态 (显示真实 3D 渲染图)
|
|
img.src = 'fr100_setup_200.png';
|
|
img.className = 'fr100-product-img';
|
|
valId.innerText = '12EC';
|
|
valVer.innerText = 'V1.2.8';
|
|
valBat.className = 'battery-pill';
|
|
valBat.innerHTML = '<svg style="width:12px;height:12px;fill:currentColor;" viewBox="0 0 24 24"><path d="M15.67 4H14V2h-4v2H8.33C7.6 4 7 4.6 7 5.33v15.33C7 21.4 7.6 22 8.33 22h7.33c.74 0 1.34-.6 1.34-1.33V5.33C17 4.6 16.4 4 15.67 4z"/></svg> <span id="batText">100%</span>';
|
|
btnToggle.innerText = '断开连接';
|
|
btnToggle.className = 'btn-mini btn-danger-outline';
|
|
totalSeconds = 178;
|
|
timer.innerText = formatTime(totalSeconds);
|
|
timer.classList.remove('dim-state');
|
|
centerPanel.classList.remove('disabled-panel-state');
|
|
rightPanel.classList.remove('disabled-panel-state');
|
|
} else {
|
|
// 切换为未连接态 (显示专属线框待连接图)
|
|
if (isRunning) handlePauseTimer();
|
|
img.src = SVG_DISCONNECTED;
|
|
img.className = 'fr100-disconnected-img';
|
|
valId.innerText = '--';
|
|
valVer.innerText = '--';
|
|
valBat.className = 'battery-pill dim';
|
|
valBat.innerHTML = '<span>未连接</span>';
|
|
btnToggle.innerText = '连接设备';
|
|
btnToggle.className = 'btn-mini btn-primary-blue';
|
|
timer.innerText = '00:00';
|
|
timer.classList.add('dim-state');
|
|
centerPanel.classList.add('disabled-panel-state');
|
|
rightPanel.classList.add('disabled-panel-state');
|
|
}
|
|
}
|
|
|
|
function connectDeviceItem(deviceName) {
|
|
if (!isConnected) {
|
|
toggleConnectState();
|
|
}
|
|
}
|
|
|
|
function handleStartTimer() {
|
|
if (!isConnected) return;
|
|
if (isRunning) return;
|
|
isRunning = true;
|
|
timerInterval = setInterval(() => {
|
|
if (totalSeconds > 0) {
|
|
totalSeconds--;
|
|
document.getElementById('dispTimer').innerText = formatTime(totalSeconds);
|
|
} else {
|
|
clearInterval(timerInterval);
|
|
isRunning = false;
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
function handlePauseTimer() {
|
|
if (!isRunning) return;
|
|
clearInterval(timerInterval);
|
|
isRunning = false;
|
|
}
|
|
|
|
function selectDurationItem(el, seconds) {
|
|
if (!isConnected) return;
|
|
document.querySelectorAll('#wheelPickerBox .wheel-item').forEach(item => item.classList.remove('selected'));
|
|
el.classList.add('selected');
|
|
if (!isRunning) {
|
|
totalSeconds = seconds;
|
|
document.getElementById('dispTimer').innerText = formatTime(totalSeconds);
|
|
}
|
|
}
|
|
|
|
function setWorkMode(mode) {
|
|
if (!isConnected) return;
|
|
currentMode = mode;
|
|
const btnA = document.getElementById('btnModeAuto');
|
|
const btnM = document.getElementById('btnModeManual');
|
|
if (mode === 'auto') {
|
|
btnA.className = 'mode-cap-btn active-blue';
|
|
btnM.className = 'mode-cap-btn';
|
|
} else {
|
|
btnA.className = 'mode-cap-btn';
|
|
btnM.className = 'mode-cap-btn active-red';
|
|
}
|
|
}
|
|
|
|
function selectActionMatrix(el, actionName) {
|
|
if (!isConnected) return;
|
|
currentAction = actionName;
|
|
el.parentElement.querySelectorAll('.matrix-item').forEach(i => i.classList.remove('selected'));
|
|
el.classList.add('selected');
|
|
}
|
|
|
|
function selectMuscleMatrix(el, muscleName) {
|
|
if (!isConnected) return;
|
|
currentMuscle = muscleName;
|
|
el.parentElement.querySelectorAll('.matrix-item').forEach(i => i.classList.remove('selected'));
|
|
el.classList.add('selected');
|
|
}
|
|
|
|
function setStrengthLevel(level, btn) {
|
|
if (!isConnected) return;
|
|
currentStrength = level;
|
|
document.querySelectorAll('.strength-grid .strength-btn').forEach(b => b.classList.remove('active'));
|
|
btn.classList.add('active');
|
|
const tag = document.getElementById('dispStrengthTag');
|
|
if (tag) tag.innerText = level + ' 档';
|
|
}
|
|
|
|
function handleSaveConfig() {
|
|
if (!isConnected) return;
|
|
// 保存配置静默完成,按钮呈现短暂保存确认态
|
|
const btn = document.getElementById('btnSaveConfig');
|
|
const originText = btn.innerText;
|
|
btn.innerText = '已保存';
|
|
setTimeout(() => {
|
|
btn.innerText = originText;
|
|
}, 1200);
|
|
}
|