update: 关闭设置框时保存配置, 阻止按钮事件冒泡, 调整配置获取方式

This commit is contained in:
lww155
2026-01-22 17:23:27 +08:00
parent 3e7bc0606a
commit e1dd272708
4 changed files with 16 additions and 34 deletions
+9 -26
View File
@@ -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);