refactor(frontend): replace toast system with zibll notyf

This commit is contained in:
2026-08-18 02:38:43 +08:00
parent fb11a7ed0c
commit 86614c4905
33 changed files with 603 additions and 802 deletions
+42 -42
View File
@@ -7,7 +7,7 @@
* @package AKSRT
*/
/* global aksrtUserCenter, showToast */
/* global aksrtUserCenter, notyf */
(function() {
'use strict';
@@ -157,7 +157,7 @@
if (name === 'revenue' && typeof window.AKSRTAffiliateRevenueInit === 'function') window.AKSRTAffiliateRevenueInit();
if (name === 'revenue' && typeof window.AKSRTWithdrawInit === 'function') window.AKSRTWithdrawInit();
}).catch(function() {
if (typeof showToast === 'function') showToast(i18n.networkError || '加载失败,请重试');
notyf(i18n.networkError || '加载失败,请重试', 'danger');
});
}
@@ -220,7 +220,7 @@
if (typeof window.AKSRTAffiliateRevenueInit === 'function') window.AKSRTAffiliateRevenueInit();
if (typeof window.AKSRTWithdrawInit === 'function') window.AKSRTWithdrawInit();
}).catch(function() {
if (typeof showToast === 'function') showToast(i18n.networkError || '加载失败,请重试');
notyf(i18n.networkError || '加载失败,请重试', 'danger');
});
return;
}
@@ -246,7 +246,7 @@
if (window.history.pushState) window.history.pushState({}, '', pageUrl.toString());
if (typeof window.AKSRTRevenueCenterInit === 'function') window.AKSRTRevenueCenterInit(creatorPanel);
}).catch(function() {
if (typeof showToast === 'function') showToast(i18n.networkError || '加载失败,请重试');
notyf(i18n.networkError || '加载失败,请重试', 'danger');
});
});
}
@@ -283,7 +283,7 @@
btn.disabled = false;
btn.textContent = i18n.saveBtn || '保存修改';
if (res.success) {
showToast(i18n.saved || '已保存');
notyf(i18n.saved || '已保存');
} else {
msg.className = 'profile-form__submit-msg is-error';
msg.textContent = res.data.message || (i18n.saveFailed || '保存失败');
@@ -350,17 +350,17 @@
}
}, 220);
}
showToast(i18n.unfavorited || '已取消收藏');
notyf(i18n.unfavorited || '已取消收藏');
} else {
btn.disabled = false;
btn.classList.remove('is-loading');
showToast((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'));
notyf((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'), 'danger');
}
})
.catch(function() {
btn.disabled = false;
btn.classList.remove('is-loading');
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
});
});
}
@@ -383,11 +383,11 @@
if (!response || !response.success) throw new Error('delete-failed');
var item = btn.closest('.profile-list-item');
if (item) item.remove();
if (typeof showToast === 'function') showToast('文章已删除');
notyf('文章已删除');
})
.catch(function() {
btn.disabled = false;
if (typeof showToast === 'function') showToast(i18n.operationFailed || '操作失败');
notyf(i18n.operationFailed || '操作失败', 'danger');
});
});
}
@@ -429,14 +429,14 @@
var row = btn.closest('[data-notification-id]');
if (row) row.classList.add('is-read');
btn.remove();
showToast(i18n.markedRead || '已标记为已读');
notyf(i18n.markedRead || '已标记为已读');
} else {
btn.disabled = false;
showToast((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'));
notyf((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'), 'danger');
}
}).catch(function() {
btn.disabled = false;
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
});
return;
}
@@ -460,14 +460,14 @@
if (res && res.success) {
var delRow = delBtn.closest('[data-notification-id]');
if (delRow) delRow.remove();
showToast(i18n.notificationDeleted || '已删除通知');
notyf(i18n.notificationDeleted || '已删除通知');
} else {
delBtn.disabled = false;
showToast((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'));
notyf((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'), 'danger');
}
}).catch(function() {
delBtn.disabled = false;
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
});
});
@@ -482,14 +482,14 @@
row.classList.add('is-read');
});
list.querySelectorAll('.aksrt-notification-read-btn').forEach(function(b) { b.remove(); });
showToast(i18n.allMarkedRead || '已全部标记为已读');
notyf(i18n.allMarkedRead || '已全部标记为已读');
} else {
markAllBtn.disabled = false;
showToast((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'));
notyf((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'), 'danger');
}
}).catch(function() {
markAllBtn.disabled = false;
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
});
});
}
@@ -501,7 +501,7 @@
return input.value;
});
if (!checked.length) {
showToast(i18n.selectNotifications || '请先选择要标记的通知');
notyf(i18n.selectNotifications || '请先选择要标记的通知', 'warning');
return;
}
markSelectedBtn.disabled = true;
@@ -516,11 +516,11 @@
var b = row ? row.querySelector('.aksrt-notification-read-btn') : null;
if (b) b.remove();
});
showToast(i18n.selectedMarkedRead || '已标记所选通知为已读');
notyf(i18n.selectedMarkedRead || '已标记所选通知为已读');
markSelectedBtn.disabled = false;
}).catch(function() {
markSelectedBtn.disabled = false;
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
});
});
}
@@ -532,7 +532,7 @@
return input.value;
});
if (!checked.length) {
showToast(i18n.selectNotifications || '请先选择要删除的通知');
notyf(i18n.selectNotifications || '请先选择要删除的通知', 'warning');
return;
}
if (!confirm(i18n.confirmBatchDelete || '确定批量删除所选通知?')) return;
@@ -551,15 +551,15 @@
var row = list.querySelector('[data-notification-id="' + id + '"]');
if (row) row.remove();
});
showToast(i18n.batchDeleted || '已删除所选通知');
notyf(i18n.batchDeleted || '已删除所选通知');
} else {
deleteSelectedBtn.disabled = false;
showToast((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'));
notyf((res && res.data && res.data.message) || (i18n.operationFailed || '操作失败'), 'danger');
}
})
.catch(function() {
deleteSelectedBtn.disabled = false;
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
});
});
}
@@ -687,7 +687,7 @@
fetch(ajaxUrl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: data.toString() })
.then(function(r) { return r.json(); }).then(function(res) {
if (res.success) {
showToast(res.data.message || (i18n.codeSent || '验证码已发送'));
notyf(res.data.message || (i18n.codeSent || '验证码已发送'));
var sec = 60;
self.classList.add('is-counting');
self.textContent = sec + 's 后重发';
@@ -703,13 +703,13 @@
}
}, 1000);
} else {
showToast(res.data.message || (i18n.sendFailed || '发送失败'));
notyf(res.data.message || (i18n.sendFailed || '发送失败'), 'danger');
self.disabled = false;
self.textContent = getSendBtnIdleText(btnId);
}
})
.catch(function() {
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
self.disabled = false;
self.textContent = getSendBtnIdleText(btnId);
});
@@ -730,14 +730,14 @@
var orig = btn ? btn.textContent : '';
var reqs = fm.querySelectorAll('[required]');
for (var i = 0; i < reqs.length; i++) {
if (!reqs[i].value.trim()) { reqs[i].focus(); showToast(i18n.fillRequired || '请填写必填项'); return; }
if (!reqs[i].value.trim()) { reqs[i].focus(); notyf(i18n.fillRequired || '请填写必填项', 'warning'); return; }
}
if (fid === 'pwd-form') {
var pwdNew = document.getElementById('pwd-new');
var pwdConfirm = document.getElementById('pwd-new-confirm');
if (pwdNew && pwdConfirm && pwdNew.value !== pwdConfirm.value) {
pwdConfirm.focus();
showToast(i18n.passwordMismatch || '两次输入的新密码不一致');
notyf(i18n.passwordMismatch || '两次输入的新密码不一致', 'warning');
return;
}
}
@@ -750,16 +750,16 @@
.then(function(r) {
if (btn) { btn.disabled = false; btn.textContent = orig; }
if (r.success) {
showToast(r.data.message || '');
notyf(r.data.message || '');
closeModal(fm.closest('.aksrt-modal'));
if (r.data.redirect_to) setTimeout(function() { window.location.href = r.data.redirect_to; }, 2500);
} else {
showToast(r.data.message || (i18n.operationFailed || '操作失败'));
notyf(r.data.message || (i18n.operationFailed || '操作失败'), 'danger');
}
})
.catch(function() {
if (btn) { btn.disabled = false; btn.textContent = orig; }
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
});
});
}
@@ -790,7 +790,7 @@
.then(function(r) { return r.json(); })
.then(function(d) {
if (d.success) {
showToast(i18n.unbindSuccess || '解除成功');
notyf(i18n.unbindSuccess || '解除成功');
setTimeout(function() {
var u = new URL(window.location);
u.searchParams.set('tab', 'settings');
@@ -798,13 +798,13 @@
window.location.href = u.toString();
}, 1000);
} else {
showToast(i18n.unbindFailed || '解除失败');
notyf(i18n.unbindFailed || '解除失败', 'danger');
self.disabled = false;
self.textContent = i18n.unbind || '解除';
}
})
.catch(function() {
showToast(i18n.networkError || '网络错误');
notyf(i18n.networkError || '网络错误', 'danger');
self.disabled = false;
self.textContent = i18n.unbind || '解除';
});
@@ -844,11 +844,11 @@
var phone = phoneEl ? String(phoneEl.value || '').trim() : '';
var code = codeEl ? String(codeEl.value || '').trim() : '';
if (!/^1[3-9]\d{9}$/.test(phone)) {
showToast('请输入正确的手机号');
notyf('请输入正确的手机号', 'warning');
return;
}
if (!code) {
showToast('请输入短信验证码');
notyf('请输入短信验证码', 'warning');
return;
}
var submitBtn = form.querySelector('[type="submit"]');
@@ -892,12 +892,12 @@
.then(function (r) { return r.json().then(function (j) { return { ok: r.ok, json: j }; }); })
.then(function (res) {
if (res.ok && res.json && res.json.success) {
showToast((res.json.message) || '绑定成功');
notyf((res.json.message) || '绑定成功');
setTimeout(function () { window.location.reload(); }, 600);
return;
}
resetCaptcha();
showToast((res.json && (res.json.message || res.json.error)) || '绑定失败');
notyf((res.json && (res.json.message || res.json.error)) || '绑定失败', 'danger');
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.textContent = '确认绑定';
@@ -905,7 +905,7 @@
})
.catch(function () {
resetCaptcha();
showToast('网络错误');
notyf('网络错误', 'danger');
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.textContent = '确认绑定';