refactor(frontend): replace toast system with zibll notyf
This commit is contained in:
@@ -347,9 +347,7 @@
|
||||
container.querySelectorAll(".ajax-item.is-fading").forEach(function (n) {
|
||||
n.classList.remove("is-fading");
|
||||
});
|
||||
if (typeof window.aksrtToast === "function") {
|
||||
window.aksrtToast((err && err.message) || "加载失败");
|
||||
}
|
||||
notyf((err && err.message) || "加载失败", "danger");
|
||||
dispatch(container, "post_ajax.error", { link: link, error: err });
|
||||
throw err;
|
||||
});
|
||||
|
||||
@@ -58,14 +58,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function showToast(msg, type) {
|
||||
if (window.aksrt && aksrt.notyf) {
|
||||
aksrt.notyf(msg, { type: type || "info", duration: 2200 });
|
||||
} else {
|
||||
console.log("[AKSRT Toast]", type, msg);
|
||||
}
|
||||
}
|
||||
|
||||
function initArticleTools() {
|
||||
var buttons = document.querySelectorAll("[data-article-tool]");
|
||||
if (!buttons.length) return;
|
||||
@@ -80,9 +72,7 @@
|
||||
|
||||
if (tool === "pdf") {
|
||||
window.print();
|
||||
if (typeof showToast === "function") {
|
||||
showToast("请在打印对话框中选择“另存为 PDF”", "info");
|
||||
}
|
||||
notyf("请在打印对话框中选择“另存为 PDF”", "info");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -232,9 +222,9 @@
|
||||
setButtonBusy(likeBtn, true);
|
||||
requestInteraction("aksrt_toggle_like", postId, nextState).then(function (data) {
|
||||
applyLikeState(!!data.active, parseInt(data.count, 10) || 0);
|
||||
showToast(data.active ? "感谢你的点赞" : "已取消点赞", "success");
|
||||
notyf(data.active ? "感谢你的点赞" : "已取消点赞", "success");
|
||||
}).catch(function (error) {
|
||||
showToast(error && error.message ? error.message : "点赞失败", "error");
|
||||
notyf(error && error.message ? error.message : "点赞失败", "danger");
|
||||
}).finally(function () {
|
||||
setButtonBusy(likeBtn, false);
|
||||
});
|
||||
@@ -257,9 +247,9 @@
|
||||
setButtonBusy(favBtn, true);
|
||||
requestInteraction("aksrt_toggle_favorite", postId, nextState).then(function (data) {
|
||||
applyFavoriteState(!!data.active, parseInt(data.count, 10) || 0);
|
||||
showToast(data.active ? "收藏成功" : "已取消收藏", "success");
|
||||
notyf(data.active ? "收藏成功" : "已取消收藏", "success");
|
||||
}).catch(function (error) {
|
||||
showToast(error && error.message ? error.message : "收藏失败", "error");
|
||||
notyf(error && error.message ? error.message : "收藏失败", "danger");
|
||||
}).finally(function () {
|
||||
setButtonBusy(favBtn, false);
|
||||
});
|
||||
|
||||
@@ -22,16 +22,6 @@
|
||||
return d.restNonce || d.nonce || '';
|
||||
}
|
||||
|
||||
function notify(msg, type) {
|
||||
if (window.aksrt && typeof window.aksrt.toast === 'function') {
|
||||
window.aksrt.toast(msg, type || 'info');
|
||||
return;
|
||||
}
|
||||
if (window.notyf) {
|
||||
try { window.notyf[type === 'error' ? 'error' : 'success'](msg); } catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
function setActionText(text) {
|
||||
var el = document.querySelector('#' + respondId + ' .action-text');
|
||||
if (!el) return;
|
||||
@@ -147,7 +137,7 @@
|
||||
if (submit) submit.disabled = false;
|
||||
})
|
||||
.catch(function () {
|
||||
notify('加载评论失败', 'error');
|
||||
notyf('加载评论失败', 'danger');
|
||||
if (textarea) {
|
||||
textarea.disabled = false;
|
||||
textarea.value = '';
|
||||
|
||||
+15
-23
@@ -4,14 +4,6 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function showToast(msg, type) {
|
||||
if (window.aksrt && aksrt.notyf) {
|
||||
aksrt.notyf(msg, { type: type || "info", duration: 2200 });
|
||||
} else {
|
||||
console.log("[AKSRT Toast]", type, msg);
|
||||
}
|
||||
}
|
||||
|
||||
function initCommentSystem() {
|
||||
var form = document.querySelector("#commentform");
|
||||
if (!form) return;
|
||||
@@ -125,9 +117,9 @@
|
||||
if (responseText.indexOf('审核') !== -1 ||
|
||||
responseText.indexOf('moderation') !== -1 ||
|
||||
responseText.includes('awaiting-moderation')) {
|
||||
showToast('评论已提交,等待管理员审核', 'info');
|
||||
notyf('评论已提交,等待管理员审核', 'info');
|
||||
} else {
|
||||
showToast('评论发布成功', 'success');
|
||||
notyf('评论发布成功', 'success');
|
||||
}
|
||||
|
||||
// 清空文本框
|
||||
@@ -153,7 +145,7 @@
|
||||
var errorMsg = extractErrorMessage(responseText);
|
||||
var waitSeconds = extractWaitTime(errorMsg);
|
||||
|
||||
showToast(errorMsg, 'warning');
|
||||
notyf(errorMsg, 'warning');
|
||||
|
||||
if (waitSeconds > 0) {
|
||||
startCountdown(waitSeconds);
|
||||
@@ -167,7 +159,7 @@
|
||||
// 情况3: HTTP 403 权限不足(地区/IP/关键词等)
|
||||
if (statusCode === 403) {
|
||||
var forbiddenMsg = extractErrorMessage(responseText);
|
||||
showToast(forbiddenMsg, 'error');
|
||||
notyf(forbiddenMsg, 'danger');
|
||||
setLoading(false);
|
||||
return false;
|
||||
}
|
||||
@@ -175,12 +167,12 @@
|
||||
// 情况4: 包含WordPress错误信息
|
||||
var errorMatch = responseText.match(/<p[^>]*>([^<]*(?:错误|失败|error|Error)[^<]*)<\/p>/i);
|
||||
if (errorMatch) {
|
||||
showToast(errorMatch[1].trim(), 'error');
|
||||
notyf(errorMatch[1].trim(), 'danger');
|
||||
setLoading(false);
|
||||
return false;
|
||||
}
|
||||
// 默认情况:可能是成功或其他
|
||||
showToast('评论已提交', 'success');
|
||||
notyf('评论已提交', 'success');
|
||||
var textarea2 = form.querySelector('#comment');
|
||||
if (textarea2) textarea2.value = '';
|
||||
|
||||
@@ -194,7 +186,7 @@
|
||||
|
||||
} catch (e) {
|
||||
console.error('[AKSRT Comment] 解析响应失败:', e);
|
||||
showToast('响应解析异常,请重试', 'error');
|
||||
notyf('响应解析异常,请重试', 'danger');
|
||||
setLoading(false);
|
||||
return false;
|
||||
}
|
||||
@@ -239,7 +231,7 @@
|
||||
if (editId) editId.remove();
|
||||
restoreRespondPosition();
|
||||
setLoading(false);
|
||||
showToast(json.message || '评论已更新', 'success');
|
||||
notyf(json.message || '评论已更新', 'success');
|
||||
var respondEl = document.getElementById('respond');
|
||||
if (respondEl && window.AksrtFixedInput) window.AksrtFixedInput(respondEl, 'hide');
|
||||
return;
|
||||
@@ -289,7 +281,7 @@
|
||||
}
|
||||
|
||||
if (json && json.code) {
|
||||
showToast(json.message || '评论提交失败', 'error');
|
||||
notyf(json.message || '评论提交失败', 'danger');
|
||||
try {
|
||||
var failScene = window.AKSRTCaptchaState &&
|
||||
window.AKSRTCaptchaState.scenes &&
|
||||
@@ -303,7 +295,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
showToast('评论已提交', 'success');
|
||||
notyf('评论已提交', 'success');
|
||||
setLoading(false);
|
||||
setTimeout(function () { reloadCommentList(); }, 500);
|
||||
})
|
||||
@@ -352,9 +344,9 @@
|
||||
});
|
||||
|
||||
if (needsModeration) {
|
||||
showToast('评论已提交,等待管理员审核', 'info');
|
||||
notyf('评论已提交,等待管理员审核', 'info');
|
||||
} else {
|
||||
showToast('评论发布成功', 'success');
|
||||
notyf('评论发布成功', 'success');
|
||||
}
|
||||
|
||||
if (window.AksrtFrontend) AksrtFrontend.rehydrate(newComment, 'ajax');
|
||||
@@ -397,9 +389,9 @@
|
||||
console.error('[AKSRT Comment] 提交失败:', error);
|
||||
|
||||
if (error.message === 'Failed to fetch' || error.name === 'TypeError') {
|
||||
showToast('网络连接失败,请检查网络后重试', 'error');
|
||||
notyf('网络连接失败,请检查网络后重试', 'danger');
|
||||
} else {
|
||||
showToast(error.message || '评论提交失败,请重试', 'error');
|
||||
notyf(error.message || '评论提交失败,请重试', 'danger');
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
@@ -439,7 +431,7 @@
|
||||
performSubmit();
|
||||
} else {
|
||||
// 验证失败
|
||||
showToast('人机验证未通过,请重试', 'warning');
|
||||
notyf('人机验证未通过,请重试', 'warning');
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user