feat(admin-ui): 引入 Toast 反馈(Ant Design Pro 风格基线)

This commit is contained in:
萝卜
2026-03-15 17:41:45 +08:00
parent 71ad4becb9
commit 3011619ee2
4 changed files with 168 additions and 3 deletions

View File

@@ -43,6 +43,79 @@
});
})();
// 通用:将后端 flash 信息同步到 toast更像 Ant Design Pro 的反馈方式)
// 说明:渐进增强。页面仍保留原本的提示块,不依赖 JS。
(function () {
var container = qs('[data-role="toast-container"]');
if (!container) {
return;
}
var flashNodes = document.querySelectorAll('[data-flash]');
if (!flashNodes || flashNodes.length === 0) {
return;
}
function createToast(type, text) {
var div = document.createElement('div');
div.className = 'toast toast-' + type;
div.setAttribute('role', 'status');
var content = document.createElement('div');
content.className = 'toast-content';
content.textContent = text;
var close = document.createElement('button');
close.type = 'button';
close.className = 'toast-close';
close.textContent = '×';
close.addEventListener('click', function () {
try {
container.removeChild(div);
} catch (e) {}
});
div.appendChild(content);
div.appendChild(close);
return div;
}
flashNodes.forEach(function (node) {
var type = node.getAttribute('data-flash') || 'info';
var text = (node.textContent || '').trim();
if (!text) {
return;
}
container.appendChild(createToast(type, text));
});
// 自动消失success/warningerror 保留更久
setTimeout(function () {
try {
var toasts = container.querySelectorAll('.toast');
toasts.forEach(function (t) {
var cls = t.className || '';
var isError = cls.indexOf('toast-error') >= 0;
if (!isError) {
container.removeChild(t);
}
});
} catch (e) {}
}, 4500);
setTimeout(function () {
try {
var toasts = container.querySelectorAll('.toast');
toasts.forEach(function (t) {
try {
container.removeChild(t);
} catch (e) {}
});
} catch (e) {}
}, 9000);
})();
// 续费缺订阅治理订单详情页“绑定订阅ID”输入框小交互增强
// - 输入后按 Enter 直接提交
// - 自动聚焦,减少点击