refactor(frontend): replace toast system with zibll notyf
This commit is contained in:
+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