fixed 弹窗逻辑

This commit is contained in:
Vaica committed 2026-01-31 22:06:19 +08:00
1 parent ecd33a4880
commit b9546c669a
3 files changed
+112 -11

No files matched your search

+24 -8
View File
@@ -8,9 +8,15 @@ window.isMobile = function() {
};
// Toast Message Helper
window.showToast = function(text) {
window.showToast = function(text, type) {
type = type || 'info'; // default to info
if (typeof Qmsg !== 'undefined') {
Qmsg.info(text);
// Map common types to Qmsg methods
if (typeof Qmsg[type] === 'function') {
Qmsg[type](text);
} else {
Qmsg.info(text);
}
} else {
// Fallback custom toast
let toast = document.querySelector('.custom-toast');
@@ -31,16 +37,26 @@ window.showToast = function(text) {
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
display: flex;
align-items: center;
gap: 8px;
`;
document.body.appendChild(toast);
}
toast.innerText = text;
// Simple icon mapping for fallback
let icon = '';
if (type === 'success') icon = '✅ ';
else if (type === 'error') icon = '❌ ';
else if (type === 'warning') icon = '⚠️ ';
toast.innerText = icon + text;
toast.style.opacity = '1';
if (window.toastTimeout) clearTimeout(window.toastTimeout);
window.toastTimeout = setTimeout(() => {
toast.style.opacity = '0';
}, 2000);
}, 2500);
}
};
@@ -64,7 +80,7 @@ window.initThemeToggle = function() {
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
window.showToast('已切换至 ' + (newTheme === 'dark' ? '深色' : '浅色') + '模式');
window.showToast('已切换至 ' + (newTheme === 'dark' ? '深色' : '浅色') + '模式', 'success');
// Trigger generic resize event to force charts/etc to redraw if needed
window.dispatchEvent(new Event('resize'));
@@ -149,12 +165,12 @@ window.initCodeCopy = function() {
if (navigator.clipboard) {
navigator.clipboard.writeText(code).then(() => {
window.showToast('代码已复制 / Copied!');
window.showToast('代码已复制 / Copied!', 'success');
btn.innerHTML = '<i class="ri-check-line"></i>';
setTimeout(() => btn.innerHTML = '<i class="ri-file-copy-line"></i>', 2000);
}).catch(err => {
console.error('Copy failed', err);
window.showToast('复制失败 / Failed');
window.showToast('复制失败 / Failed', 'error');
});
} else {
// Fallback
@@ -164,7 +180,7 @@ window.initCodeCopy = function() {
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
window.showToast('代码已复制 / Copied!');
window.showToast('代码已复制 / Copied!', 'success');
}
});