refactor(frontend): replace toast system with zibll notyf
This commit is contained in:
1 parent
fb11a7ed0c
commit
86614c4905
33 files changed
+603
-802
No files matched your search
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* AKSRT Enhancements — 全局 UI 增强
|
||||
*
|
||||
* 包含:Toast 通知、图片灯箱、滚动方向感知
|
||||
* 包含:图片灯箱、滚动方向感知
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
@@ -10,90 +10,7 @@
|
||||
'use strict';
|
||||
|
||||
/* ============================================================
|
||||
* 1. Toast 通知系统
|
||||
* ============================================================ */
|
||||
var toastContainer = null;
|
||||
|
||||
function ensureToastContainer() {
|
||||
if (!toastContainer || !document.body.contains(toastContainer)) {
|
||||
toastContainer = document.createElement('div');
|
||||
toastContainer.className = 'aksrt-toast-container';
|
||||
document.body.appendChild(toastContainer);
|
||||
}
|
||||
return toastContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示 Toast 通知
|
||||
*
|
||||
* @param {string} message 消息文本
|
||||
* @param {string} type 类型: success, info, warning, danger/error, loading
|
||||
* @param {number} duration 显示时长(ms),0 表示不自动关闭
|
||||
* @returns {Object} { dismiss: Function, update: Function }
|
||||
*/
|
||||
function showToast(message, type, duration) {
|
||||
type = type || 'success';
|
||||
if (type === 'error') type = 'danger';
|
||||
duration = duration !== undefined ? duration : 3500;
|
||||
if (duration > 0 && duration < 100) duration = duration * 1000;
|
||||
|
||||
var container = ensureToastContainer();
|
||||
|
||||
var icons = {
|
||||
success: 'fas fa-check-circle',
|
||||
info: 'fas fa-bell',
|
||||
warning: 'fas fa-exclamation-circle',
|
||||
danger: 'fas fa-times-circle',
|
||||
loading: 'fas fa-spinner',
|
||||
};
|
||||
|
||||
var el = document.createElement('div');
|
||||
el.className = 'aksrt-toast aksrt-toast--' + type;
|
||||
el.innerHTML =
|
||||
'<span class="aksrt-toast__icon"><i class="' + (icons[type] || icons.info) + '"></i></span>' +
|
||||
'<span class="aksrt-toast__text">' + message + '</span>';
|
||||
|
||||
container.appendChild(el);
|
||||
|
||||
var timer = null;
|
||||
|
||||
function dismiss() {
|
||||
if (timer) clearTimeout(timer);
|
||||
el.classList.add('is-dismissing');
|
||||
setTimeout(function () {
|
||||
if (el.parentNode) el.remove();
|
||||
}, 300);
|
||||
}
|
||||
|
||||
function update(newMessage, newType) {
|
||||
if (newType) {
|
||||
el.className = 'aksrt-toast aksrt-toast--' + newType;
|
||||
var iconEl = el.querySelector('.aksrt-toast__icon i');
|
||||
if (iconEl) iconEl.className = icons[newType] || icons.info;
|
||||
}
|
||||
var textEl = el.querySelector('.aksrt-toast__text');
|
||||
if (textEl) textEl.textContent = newMessage;
|
||||
|
||||
if (newType !== 'loading' && duration > 0) {
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(dismiss, duration);
|
||||
}
|
||||
}
|
||||
|
||||
el.addEventListener('click', dismiss);
|
||||
|
||||
if (type !== 'loading' && duration > 0) {
|
||||
timer = setTimeout(dismiss, duration);
|
||||
}
|
||||
|
||||
return { dismiss: dismiss, update: update };
|
||||
}
|
||||
|
||||
// 暴露到全局
|
||||
window.AksrtToast = showToast;
|
||||
|
||||
/* ============================================================
|
||||
* 2. 图片灯箱 — zoom / thumbnails / slideshow / fullscreen /
|
||||
* 1. 图片灯箱 — zoom / thumbnails / slideshow / fullscreen /
|
||||
* mousewheel / origin animation / smart download
|
||||
* ============================================================ */
|
||||
var lightboxEl = null;
|
||||
@@ -493,7 +410,7 @@
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* 3. 滚动方向感知
|
||||
* 2. 滚动方向感知
|
||||
* ============================================================ */
|
||||
// Scroll direction is now handled by aksrt-runtime.js body scroll bus
|
||||
// (body.scroll-down / body.scroll-up / body.body-scroll).
|
||||
@@ -521,7 +438,7 @@
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* 4. 导航溢出折叠
|
||||
* 3. 导航溢出折叠
|
||||
* 由 assets/js/core/nav.js(zibll 1:1 navFolding)负责。
|
||||
* 此处不再重复实现,避免两套逻辑争抢 .aksrt-nav-more 节点
|
||||
* 触发 NotFoundError: insertBefore (moreLi 已被对方 remove)。
|
||||
|
||||
Reference in new issue
Block a user