This commit is contained in:
Zylan
2025-04-03 03:21:34 +08:00
parent 7b3457a7bd
commit 24789cc495
2 changed files with 101 additions and 59 deletions

View File

@@ -1053,18 +1053,36 @@ class SettingsManager {
}
}
// 改用全局UIManager的showToast方法来显示成功消息
if (window.uiManager) {
window.uiManager.showToast('密钥已保存', 'success');
} else {
// 如果UIManager不可用使用自己的方法作为备选
this.createToast('密钥已保存', 'success');
}
} else {
if (window.uiManager) {
window.uiManager.showToast('保存密钥失败: ' + result.message, 'error');
} else {
this.createToast('保存密钥失败: ' + result.message, 'error');
}
}
} else {
if (window.uiManager) {
window.uiManager.showToast('无法连接到服务器', 'error');
} else {
this.createToast('无法连接到服务器', 'error');
}
}
} catch (error) {
console.error('保存密钥出错:', error);
if (window.uiManager) {
window.uiManager.showToast('保存密钥出错: ' + error.message, 'error');
} else {
this.createToast('保存密钥出错: ' + error.message, 'error');
}
}
}
/**
* 创建一个Toast提示消息

View File

@@ -82,19 +82,39 @@ class UIManager {
* @returns {HTMLElement} 返回创建的Toast元素可用于后续移除
*/
showToast(message, type = 'success', displayTime) {
try {
if (!message) {
console.warn('尝试显示空消息');
message = '';
}
if (!this.toastContainer) {
console.error('Toast容器不存在无法显示消息');
console.error('Toast容器不存在正在创建新容器');
this.toastContainer = this.createToastContainer();
if (!this.toastContainer) {
console.error('无法创建Toast容器放弃显示消息');
return null;
}
}
// 检查是否已经存在相同内容的提示
try {
const existingToasts = this.toastContainer.querySelectorAll('.toast');
for (const existingToast of existingToasts) {
const existingMessage = existingToast.querySelector('span').textContent;
if (existingMessage === message) {
try {
const spanElement = existingToast.querySelector('span');
if (spanElement && spanElement.textContent === message) {
// 已经存在相同的提示,不再创建新的
return existingToast;
}
} catch (e) {
console.warn('检查现有toast时出错:', e);
// 继续检查其他toast元素
}
}
} catch (e) {
console.warn('查询现有toast时出错:', e);
// 继续创建新的toast
}
const toast = document.createElement('div');
@@ -140,6 +160,10 @@ class UIManager {
}
return toast;
} catch (error) {
console.error('显示Toast消息时出错:', error);
return null;
}
}
/**