mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 10:03:54 +08:00
fix:移除拨号按钮防抖,点击拨号后禁用按钮3秒
This commit is contained in:
@@ -13,6 +13,7 @@ class UIController {
|
|||||||
this.audioStatsTimer = null;
|
this.audioStatsTimer = null;
|
||||||
this.currentBackgroundIndex = localStorage.getItem('backgroundIndex') ? parseInt(localStorage.getItem('backgroundIndex')) : 0;
|
this.currentBackgroundIndex = localStorage.getItem('backgroundIndex') ? parseInt(localStorage.getItem('backgroundIndex')) : 0;
|
||||||
this.backgroundImages = ['1.png', '2.png', '3.png'];
|
this.backgroundImages = ['1.png', '2.png', '3.png'];
|
||||||
|
this.dialBtnDisabled = false;
|
||||||
|
|
||||||
// Bind methods
|
// Bind methods
|
||||||
this.init = this.init.bind(this);
|
this.init = this.init.bind(this);
|
||||||
@@ -99,36 +100,36 @@ class UIController {
|
|||||||
|
|
||||||
// Dial button
|
// Dial button
|
||||||
const dialBtn = document.getElementById('dialBtn');
|
const dialBtn = document.getElementById('dialBtn');
|
||||||
let dialTimer = null;
|
|
||||||
if (dialBtn) {
|
if (dialBtn) {
|
||||||
dialBtn.addEventListener('click', () => {
|
dialBtn.addEventListener('click', () => {
|
||||||
if (dialTimer) {
|
dialBtn.disabled = true;
|
||||||
clearTimeout(dialTimer);
|
this.dialBtnDisabled = true;
|
||||||
dialTimer = null;
|
setTimeout(() => {
|
||||||
}
|
dialBtn.disabled = false;
|
||||||
dialTimer = setTimeout(() => {
|
this.dialBtnDisabled = false;
|
||||||
const wsHandler = getWebSocketHandler();
|
}, 3000);
|
||||||
const isConnected = wsHandler.isConnected();
|
|
||||||
|
|
||||||
if (isConnected) {
|
const wsHandler = getWebSocketHandler();
|
||||||
wsHandler.disconnect();
|
const isConnected = wsHandler.isConnected();
|
||||||
this.updateDialButton(false);
|
|
||||||
this.addChatMessage('Disconnected, see you next time~😊', false);
|
|
||||||
} else {
|
|
||||||
// Check if OTA URL is filled
|
|
||||||
const otaUrlInput = document.getElementById('otaUrl');
|
|
||||||
if (!otaUrlInput || !otaUrlInput.value.trim()) {
|
|
||||||
// If OTA URL is not filled, show settings modal and switch to device tab
|
|
||||||
this.showModal('settingsModal');
|
|
||||||
this.switchTab('device');
|
|
||||||
this.addChatMessage('Please fill in OTA server URL', false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start connection process
|
if (isConnected) {
|
||||||
this.handleConnect();
|
wsHandler.disconnect();
|
||||||
|
this.updateDialButton(false);
|
||||||
|
this.addChatMessage('Disconnected, see you next time~😊', false);
|
||||||
|
} else {
|
||||||
|
// Check if OTA URL is filled
|
||||||
|
const otaUrlInput = document.getElementById('otaUrl');
|
||||||
|
if (!otaUrlInput || !otaUrlInput.value.trim()) {
|
||||||
|
// If OTA URL is not filled, show settings modal and switch to device tab
|
||||||
|
this.showModal('settingsModal');
|
||||||
|
this.switchTab('device');
|
||||||
|
this.addChatMessage('Please fill in OTA server URL', false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, 300);
|
|
||||||
|
// Start connection process
|
||||||
|
this.handleConnect();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -618,7 +619,9 @@ class UIController {
|
|||||||
// Update dial button state
|
// Update dial button state
|
||||||
const dialBtn = document.getElementById('dialBtn');
|
const dialBtn = document.getElementById('dialBtn');
|
||||||
if (dialBtn) {
|
if (dialBtn) {
|
||||||
dialBtn.disabled = false;
|
if (!this.dialBtnDisabled) {
|
||||||
|
dialBtn.disabled = false;
|
||||||
|
}
|
||||||
dialBtn.querySelector('.btn-text').textContent = '挂断';
|
dialBtn.querySelector('.btn-text').textContent = '挂断';
|
||||||
dialBtn.classList.add('dial-active');
|
dialBtn.classList.add('dial-active');
|
||||||
}
|
}
|
||||||
@@ -644,7 +647,9 @@ class UIController {
|
|||||||
// Restore dial button state
|
// Restore dial button state
|
||||||
const dialBtn = document.getElementById('dialBtn');
|
const dialBtn = document.getElementById('dialBtn');
|
||||||
if (dialBtn) {
|
if (dialBtn) {
|
||||||
dialBtn.disabled = false;
|
if (!this.dialBtnDisabled) {
|
||||||
|
dialBtn.disabled = false;
|
||||||
|
}
|
||||||
dialBtn.querySelector('.btn-text').textContent = '拨号';
|
dialBtn.querySelector('.btn-text').textContent = '拨号';
|
||||||
dialBtn.classList.remove('dial-active');
|
dialBtn.classList.remove('dial-active');
|
||||||
console.log('Dial button state restored successfully');
|
console.log('Dial button state restored successfully');
|
||||||
|
|||||||
Reference in New Issue
Block a user