mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
update: 关闭设置框时保存配置, 阻止按钮事件冒泡, 调整配置获取方式
This commit is contained in:
@@ -58,10 +58,9 @@ export function saveConfig() {
|
||||
|
||||
// 获取配置值
|
||||
export function getConfig() {
|
||||
// 从DOM获取值
|
||||
const deviceMac = document.getElementById('deviceMac')?.value.trim() || '';
|
||||
const deviceName = document.getElementById('deviceName')?.value.trim() || '';
|
||||
const clientId = document.getElementById('clientId')?.value.trim() || '';
|
||||
const deviceMac = localStorage.getItem('xz_tester_deviceMac');
|
||||
const deviceName = localStorage.getItem('xz_tester_deviceName');
|
||||
const clientId = localStorage.getItem('xz_tester_clientId');
|
||||
|
||||
return {
|
||||
deviceId: deviceMac, // 使用MAC地址作为deviceId
|
||||
|
||||
@@ -83,7 +83,7 @@ async function sendOTA(otaUrl, config) {
|
||||
},
|
||||
ota: { label: 'xiaozhi-web-test' },
|
||||
board: {
|
||||
type: 'xiaozhi-web-test',
|
||||
type: config.deviceName,
|
||||
ssid: 'xiaozhi-web-test',
|
||||
rssi: 0,
|
||||
channel: 0,
|
||||
|
||||
@@ -152,8 +152,12 @@ class UIController {
|
||||
const closeButtons = document.querySelectorAll('.close-btn');
|
||||
closeButtons.forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
const modal = e.target.closest('.modal');
|
||||
if (modal) {
|
||||
if (modal.id === 'settingsModal') {
|
||||
saveConfig();
|
||||
}
|
||||
this.hideModal(modal.id);
|
||||
}
|
||||
});
|
||||
@@ -172,23 +176,19 @@ class UIController {
|
||||
modals.forEach(modal => {
|
||||
modal.addEventListener('click', (e) => {
|
||||
if (e.target === modal) {
|
||||
if (modal.id === 'settingsModal') {
|
||||
saveConfig();
|
||||
}
|
||||
this.hideModal(modal.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 保存配置按钮
|
||||
const saveConfigBtn = document.getElementById('saveConfigBtn');
|
||||
if (saveConfigBtn) {
|
||||
saveConfigBtn.addEventListener('click', () => {
|
||||
this.saveConfig();
|
||||
});
|
||||
}
|
||||
|
||||
// 添加MCP工具按钮
|
||||
const addMCPToolBtn = document.getElementById('addMCPToolBtn');
|
||||
if (addMCPToolBtn) {
|
||||
addMCPToolBtn.addEventListener('click', () => {
|
||||
addMCPToolBtn.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
this.addMCPTool();
|
||||
});
|
||||
}
|
||||
@@ -330,23 +330,6 @@ class UIController {
|
||||
}
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
saveConfig() {
|
||||
const config = {
|
||||
serverUrl: document.getElementById('serverUrl').value,
|
||||
serverPort: document.getElementById('serverPort').value,
|
||||
audioDevice: document.getElementById('audioDevice').value,
|
||||
audioSampleRate: document.getElementById('audioSampleRate').value,
|
||||
audioChannels: document.getElementById('audioChannels').value
|
||||
};
|
||||
|
||||
saveConfig(config);
|
||||
this.hideModal('settingsModal');
|
||||
|
||||
// 显示保存成功消息
|
||||
this.addChatMessage('配置已保存', false);
|
||||
}
|
||||
|
||||
// 连接成功后开始对话
|
||||
startAIChatSession() {
|
||||
this.addChatMessage('连接成功,开始聊天吧~🙂', false);
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
<div class="config-row">
|
||||
<div class="config-item">
|
||||
<label for="deviceMac">设备MAC:</label>
|
||||
<input type="text" id="deviceMac" placeholder="device-id" readonly>
|
||||
<input type="text" id="deviceMac" placeholder="device-id">
|
||||
</div>
|
||||
</div>
|
||||
<div class="config-row">
|
||||
@@ -143,7 +143,7 @@
|
||||
</div>
|
||||
<div class="config-item">
|
||||
<label for="deviceName">设备名称:</label>
|
||||
<input type="text" id="deviceName" value="Web测试设备" placeholder="deviceName">
|
||||
<input type="text" id="deviceName" value="Web测试设备" maxlength="50" placeholder="deviceName">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -237,7 +237,7 @@
|
||||
</div>
|
||||
|
||||
<!-- 背景加载 -->
|
||||
<script src="js/ui/backgroundLoad.js"></script>
|
||||
<script src="js/ui/background-load.js"></script>
|
||||
|
||||
<!-- PIXI.js 2D渲染引擎 -->
|
||||
<script src="js/live2d/pixi.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user