fix(frontend): simplify report dialog controls and feedback
Use highlight-only reason choices, show the associated target on one line, and replace inline submission progress with shared toast feedback. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
80aecab586
commit
b2811cc248
4 files changed
+86
-49
No files matched your search
+14
-13
@@ -11,9 +11,9 @@
|
||||
var MAX_IMAGES = 3;
|
||||
var sequence = 0;
|
||||
var TARGETS = {
|
||||
user: { title: '举报用户', label: '用户', icon: 'fa-user' },
|
||||
post: { title: '举报文章', label: '文章', icon: 'fa-file-alt' },
|
||||
comment: { title: '举报评论', label: '评论', icon: 'fa-comment' },
|
||||
user: { title: '举报用户', label: '用户' },
|
||||
post: { title: '举报文章', label: '文章' },
|
||||
comment: { title: '举报评论', label: '评论' },
|
||||
};
|
||||
|
||||
function escapeHtml(value) {
|
||||
@@ -31,13 +31,11 @@
|
||||
var target = TARGETS[data.target_type];
|
||||
var report = config.report || {};
|
||||
var id = 'aksrt-report-' + (++sequence);
|
||||
var html = '<form class="aksrt-report-form" novalidate>';
|
||||
var name = data.target_name || target.label + ' #' + data.target_id;
|
||||
var html = '<form id="' + id + '" class="aksrt-report-form" novalidate>';
|
||||
html += '<div class="aksrt-report-body mini-scrollbar">';
|
||||
html += '<div class="aksrt-report-target">';
|
||||
html += '<span class="aksrt-report-target__icon" aria-hidden="true"><i class="fas ' + target.icon + '"></i></span>';
|
||||
html += '<div><span class="aksrt-report-hint">举报对象 · ' + target.label + '</span>';
|
||||
html += '<strong class="aksrt-report-target__name">' + escapeHtml(data.target_name || target.label + ' #' + data.target_id) + '</strong>';
|
||||
html += '<p class="aksrt-report-hint">已自动关联该' + target.label + ',无需填写链接</p></div></div>';
|
||||
html += '<div class="aksrt-report-target"><span class="aksrt-report-target__label">关联对象:</span>';
|
||||
html += '<strong class="aksrt-report-target__name" title="' + escapeHtml(name) + '">' + escapeHtml(name) + '</strong></div>';
|
||||
html += '<fieldset class="aksrt-report-reasons" aria-describedby="' + id + '-reason-error">';
|
||||
html += '<legend>举报原因<span class="aksrt-report-hint">必选一项</span></legend>';
|
||||
html += '<div class="aksrt-report-reasons__options">';
|
||||
@@ -90,6 +88,7 @@
|
||||
var descInput = form.querySelector('[name="report_desc"]');
|
||||
var fileInput = form.querySelector('[data-aksrt-report-file]');
|
||||
var images = [];
|
||||
var submitAttempts = 0;
|
||||
var submitting = false;
|
||||
var closed = false;
|
||||
|
||||
@@ -100,9 +99,9 @@
|
||||
function syncState() {
|
||||
var uploading = images.some(function (image) { return image.status === 'uploading'; });
|
||||
submit.disabled = submitting || uploading;
|
||||
submit.textContent = submitting ? '正在提交…' : uploading ? '图片上传中…' : '提交举报';
|
||||
submit.textContent = uploading ? '图片上传中…' : '提交举报';
|
||||
form.setAttribute('aria-busy', String(submitting || uploading));
|
||||
status.textContent = submitting ? '正在提交举报,请稍候' : uploading ? '图片正在上传,完成后即可提交' : '';
|
||||
status.textContent = uploading ? '图片正在上传,完成后即可提交' : '';
|
||||
var add = form.querySelector('[data-aksrt-report-add]');
|
||||
if (add) {
|
||||
add.disabled = submitting || images.length >= MAX_IMAGES;
|
||||
@@ -244,6 +243,8 @@
|
||||
if (images.length) reason += '\n图片举证:\n' + images.map(function (image) { return image.url; }).join('\n');
|
||||
submitting = true;
|
||||
syncState();
|
||||
var toastId = form.id + '-submit-' + (++submitAttempts);
|
||||
notyf('正在提交举报…', 'load', '', toastId);
|
||||
form.querySelectorAll('input, textarea, [data-aksrt-report-remove], [data-aksrt-report-retry]').forEach(function (element) { element.disabled = true; });
|
||||
window.fetch(API_ROOT + '/report/submit', {
|
||||
method: 'POST',
|
||||
@@ -258,8 +259,9 @@
|
||||
status.textContent = result.message || '举报已提交,我们会尽快处理';
|
||||
form.querySelector('[data-aksrt-modal-close]').textContent = '关闭';
|
||||
if (isActive()) window.AksrtModalRuntime.close('submit');
|
||||
notyf(result.message || '举报已提交,我们会尽快处理', 'success');
|
||||
notyf(result.message || '举报已提交,我们会尽快处理', 'success', 5, toastId);
|
||||
}).catch(function (failure) {
|
||||
notyf(failure.message || '网络错误,请重试', 'danger', 5, toastId);
|
||||
submitting = false;
|
||||
if (closed) {
|
||||
images.forEach(deletePending);
|
||||
@@ -268,7 +270,6 @@
|
||||
form.querySelectorAll('input, textarea, [data-aksrt-report-remove], [data-aksrt-report-retry]').forEach(function (element) { element.disabled = false; });
|
||||
otherInput.disabled = otherBox.hidden;
|
||||
syncState();
|
||||
showError(error, failure.message || '网络错误,请重试');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user