2026-05-24 14:00:12 +08:00
|
|
|
|
/**
|
2026-10-04 15:00:52 +08:00
|
|
|
|
* Toast — 统一通知组件(Message.js / Qmsg)
|
|
|
|
|
|
*
|
|
|
|
|
|
* 全站 toast 一律走 Message.js(https://github.com/snwjas/Message.js),
|
|
|
|
|
|
* 库本体已本地化:js/libs/message.min.js + css/libs/message.min.css(随 style.css 打包)。
|
|
|
|
|
|
* 这里只做一层薄适配,保留旧 API,调用点(utils/floating-tools/artalk…)不用改:
|
|
|
|
|
|
* Toast.show(text, { type, duration })
|
|
|
|
|
|
* Toast.success / error / warning / info(text, duration?)
|
|
|
|
|
|
* showToast(text, type) ← 全局快捷方式
|
2026-05-24 14:00:12 +08:00
|
|
|
|
*/
|
2026-10-04 15:00:52 +08:00
|
|
|
|
(function () {
|
|
|
|
|
|
if (window.__yingToastReady) return; // PJAX 重复执行防抖
|
|
|
|
|
|
window.__yingToastReady = true;
|
2026-05-24 14:00:12 +08:00
|
|
|
|
|
2026-10-04 15:00:52 +08:00
|
|
|
|
var Q = window.Qmsg;
|
|
|
|
|
|
if (!Q) {
|
|
|
|
|
|
// Message.js 没加载出来时兜底:不打断业务,仅降级为无样式 console
|
|
|
|
|
|
var fallback = function (text) {
|
|
|
|
|
|
try { console.log('[toast]', text); } catch (e) {}
|
|
|
|
|
|
};
|
|
|
|
|
|
fallback.success = fallback.error = fallback.warning = fallback.info = fallback;
|
|
|
|
|
|
window.Toast = fallback;
|
|
|
|
|
|
window.showToast = function (text) { fallback(text); };
|
|
|
|
|
|
return;
|
2026-05-24 14:00:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-04 15:00:52 +08:00
|
|
|
|
// 全站统一默认值:最多同时 3 条,自动关闭
|
|
|
|
|
|
try { Q.config({ maxNums: 3, timeout: 2500 }); } catch (e) {}
|
|
|
|
|
|
|
|
|
|
|
|
function opt(duration) {
|
|
|
|
|
|
return duration ? { timeout: duration } : undefined;
|
2026-05-24 14:00:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
window.Toast = {
|
2026-10-04 15:00:52 +08:00
|
|
|
|
show: function (text, options) {
|
2026-05-24 14:00:12 +08:00
|
|
|
|
options = options || {};
|
|
|
|
|
|
var type = options.type || 'info';
|
2026-10-04 15:00:52 +08:00
|
|
|
|
if (typeof Q[type] === 'function') return Q[type](text, opt(options.duration));
|
|
|
|
|
|
return Q.info(text, opt(options.duration));
|
2026-05-24 14:00:12 +08:00
|
|
|
|
},
|
2026-10-04 15:00:52 +08:00
|
|
|
|
success: function (text, duration) { return Q.success(text, opt(duration)); },
|
|
|
|
|
|
error: function (text, duration) { return Q.error(text, opt(duration)); },
|
|
|
|
|
|
warning: function (text, duration) { return Q.warning(text, opt(duration)); },
|
|
|
|
|
|
info: function (text, duration) { return Q.info(text, opt(duration)); },
|
|
|
|
|
|
loading: function (text) { return Q.loading(text); },
|
|
|
|
|
|
closeAll: function () { try { Q.closeAll(); } catch (e) {} }
|
|
|
|
|
|
};
|
2026-05-24 14:00:12 +08:00
|
|
|
|
|
2026-10-04 15:00:52 +08:00
|
|
|
|
// 全局快捷方式(utils.js 原实现迁到这里,单一来源)
|
|
|
|
|
|
window.showToast = function (text, type) {
|
|
|
|
|
|
var t = type || 'info';
|
|
|
|
|
|
if (window.Toast && typeof window.Toast[t] === 'function') window.Toast[t](text);
|
|
|
|
|
|
else window.Toast.info(text);
|
2026-05-24 14:00:12 +08:00
|
|
|
|
};
|
|
|
|
|
|
})();
|