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
+10
-17
@@ -34,13 +34,6 @@
|
||||
}).then(function (r) { return r.json(); });
|
||||
}
|
||||
|
||||
function notify(message, type) {
|
||||
if (typeof window.AksrtToast === 'function') { window.AksrtToast(message, type || 'info'); return; }
|
||||
if (typeof window.aksrtToast === 'function') { window.aksrtToast(message, type || 'info'); return; }
|
||||
if (typeof window.showToast === 'function') { window.showToast(message, type || 'info'); return; }
|
||||
if (type === 'error') { window.alert(message); }
|
||||
}
|
||||
|
||||
function getCommentId(el) {
|
||||
return parseInt(el.getAttribute('data-comment-id') || (el.id || '').replace('comment-', ''), 10) || 0;
|
||||
}
|
||||
@@ -77,7 +70,7 @@
|
||||
|
||||
restPost('/comment/like', { comment_id: commentId, active: nextActive })
|
||||
.then(function (result) {
|
||||
if (!result.success) { notify((result.data && result.data.message) || result.message || '操作失败', 'error'); return; }
|
||||
if (!result.success) { notyf((result.data && result.data.message) || result.message || '操作失败', 'danger'); return; }
|
||||
var active = !!(result.data && result.data.active);
|
||||
var count = (result.data && result.data.count) || 0;
|
||||
btn.setAttribute('data-active', active ? '1' : '0');
|
||||
@@ -91,7 +84,7 @@
|
||||
if (count > 0) { countEl.removeAttribute('hidden'); } else { countEl.setAttribute('hidden', ''); }
|
||||
}
|
||||
})
|
||||
.catch(function () { notify('网络错误', 'error'); })
|
||||
.catch(function () { notyf('网络错误', 'danger'); })
|
||||
.finally(function () { btn.dataset.busy = ''; });
|
||||
}
|
||||
|
||||
@@ -120,10 +113,10 @@
|
||||
}
|
||||
}, 300);
|
||||
} else {
|
||||
notify((result.data && result.data.message) || result.message || '删除失败', 'error');
|
||||
notyf((result.data && result.data.message) || result.message || '删除失败', 'danger');
|
||||
}
|
||||
})
|
||||
.catch(function () { notify('网络错误', 'error'); });
|
||||
.catch(function () { notyf('网络错误', 'danger'); });
|
||||
};
|
||||
|
||||
if (window.aksrt && aksrt.confirm) {
|
||||
@@ -138,15 +131,15 @@
|
||||
|
||||
restPost('/comment/pin', { comment_id: commentId, pinned: nextPinned })
|
||||
.then(function (result) {
|
||||
if (!result.success) { notify((result.data && result.data.message) || result.message || '操作失败', 'error'); return; }
|
||||
if (!result.success) { notyf((result.data && result.data.message) || result.message || '操作失败', 'danger'); return; }
|
||||
var pinned = !!(result.data && result.data.pinned);
|
||||
btn.setAttribute('data-pinned', pinned ? '1' : '0');
|
||||
btn.innerHTML = '<i class="fas fa-thumbtack" aria-hidden="true"></i> ' + (pinned ? '取消置顶' : '置顶');
|
||||
commentEl.classList.toggle('aksrt-comment--pinned', pinned);
|
||||
syncPinnedBadge(commentEl, pinned);
|
||||
notify(result.message || (pinned ? '评论已置顶。' : '已取消置顶。'), 'success');
|
||||
notyf(result.message || (pinned ? '评论已置顶。' : '已取消置顶。'), 'success');
|
||||
})
|
||||
.catch(function () { notify('网络错误', 'error'); });
|
||||
.catch(function () { notyf('网络错误', 'danger'); });
|
||||
}
|
||||
|
||||
function syncPinnedBadge(commentEl, pinned) {
|
||||
@@ -175,11 +168,11 @@
|
||||
var note = commentEl.querySelector('.awaiting-moderation');
|
||||
if (note) note.remove();
|
||||
}
|
||||
notify(result.message || '操作成功。', 'success');
|
||||
notyf(result.message || '操作成功。', 'success');
|
||||
} else {
|
||||
notify((result.data && result.data.message) || result.message || '操作失败', 'error');
|
||||
notyf((result.data && result.data.message) || result.message || '操作失败', 'danger');
|
||||
}
|
||||
})
|
||||
.catch(function () { notify('网络错误', 'error'); });
|
||||
.catch(function () { notyf('网络错误', 'danger'); });
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user