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
+6
-23
@@ -12,23 +12,6 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function notify(message, type) {
|
||||
if (!message) return;
|
||||
if (typeof window.AksrtToast === 'function') {
|
||||
window.AksrtToast(message, type || 'info');
|
||||
return;
|
||||
}
|
||||
if (typeof window.showToast === 'function') {
|
||||
window.showToast(message, type || 'info');
|
||||
return;
|
||||
}
|
||||
if (typeof window.aksrtToast === 'function') {
|
||||
window.aksrtToast(message, type || 'info');
|
||||
return;
|
||||
}
|
||||
window.alert(message);
|
||||
}
|
||||
|
||||
function updateTabUrl(root, name, defaultTab) {
|
||||
if (!window.history || typeof window.history.replaceState !== 'function') return;
|
||||
var url = new URL(window.location.href);
|
||||
@@ -149,7 +132,7 @@
|
||||
if (!file) return;
|
||||
|
||||
if (upload.maxSize && file.size > upload.maxSize) {
|
||||
notify(upload.tooLargeText || '图片大小不能超过 2MB', 'warning');
|
||||
notyf(upload.tooLargeText || '图片大小不能超过 2MB', 'warning');
|
||||
input.value = '';
|
||||
return;
|
||||
}
|
||||
@@ -180,7 +163,7 @@
|
||||
.then(function (payload) {
|
||||
if (payload && payload.success && payload.url) {
|
||||
applyImage(payload.url);
|
||||
notify(upload.successText || '背景图已更新', 'success');
|
||||
notyf(upload.successText || '背景图已更新', 'success');
|
||||
return;
|
||||
}
|
||||
throw payload || { message: upload.errorText || '上传失败' };
|
||||
@@ -190,7 +173,7 @@
|
||||
? error.data.previous_url
|
||||
: '';
|
||||
resetImage(previousUrl);
|
||||
notify((error && error.message) || upload.networkErrorText || '网络错误,请重试', 'error');
|
||||
notyf((error && error.message) || upload.networkErrorText || '网络错误,请重试', 'danger');
|
||||
})
|
||||
.finally(function () {
|
||||
setBusy(false);
|
||||
@@ -222,7 +205,7 @@
|
||||
var file = input.files && input.files[0];
|
||||
if (!file) return;
|
||||
if (upload.maxSize && file.size > upload.maxSize) {
|
||||
notify(upload.tooLargeText || '图片大小不能超过 2MB', 'warning');
|
||||
notyf(upload.tooLargeText || '图片大小不能超过 2MB', 'warning');
|
||||
input.value = '';
|
||||
return;
|
||||
}
|
||||
@@ -246,10 +229,10 @@
|
||||
var url = payload.url || (payload.data && payload.data.url) || '';
|
||||
if (!url) throw payload;
|
||||
if (image) image.src = url;
|
||||
notify(payload.message || upload.successText || '头像已更新', 'success');
|
||||
notyf(payload.message || upload.successText || '头像已更新', 'success');
|
||||
})
|
||||
.catch(function (error) {
|
||||
notify((error && error.message) || upload.errorText || '上传失败', 'error');
|
||||
notyf((error && error.message) || upload.errorText || '上传失败', 'danger');
|
||||
})
|
||||
.finally(function () {
|
||||
setBusy(false);
|
||||
|
||||
Reference in new issue
Block a user