Files
wordpress-theme-aksrt/assets/js/report.js
T
kate522 5fd7c212ed fix(runtime): 按参考主题硬切换为 loader/main/auto_fun 单一 DOM 生命周期
- 删除 AksrtFrontend registry/rehydrate 双路架构及 build/public.js 拼包入口,
  前台唯一初始路径为 PHP 本地栈(jQuery 1.9.1 → Bootstrap 3.4.1)
  → loader_js(_win/aksrtData 唯一注入)→ tbquire(['main']) → runtime/main.min.js
- window.auto_fun = debounce(z_auto_fun, 100) 为唯一重扫入口;所有模块改为
  执行一次 + off/on('auto_fun.aksrt-*') 命名空间重扫,data/class 标记幂等
- 局部更新协议统一:HTML 注入 → post_ajax.ed → auto_fun();
  远程 modal → loaded.bs.modal → auto_fun();JSON 成功 → zib_ajax.success
- 灯箱恢复 Miniimgbox/imgbox 唯一 owner(imgbox-container、a[data-imgbox]、
  imgbox_data),删除 AksrtLightbox/data-aksrt-lightbox 第二实现及 CSS/overlay,
  _win.imgbox* 重新接上 post-display 设置
- 死代码清理:runtime 下 11 组被自有实现替代的旧模块副本、无消费 vendored 库、
  顶层 grade.min.js、revenue.js、无调用方的 aksrt_get_win_runtime_config(),
  以及 loader 中 16 条死 mapping
- PHP 入队改为本地栈 + loader_js,routed/widget/submit 依赖统一换绑;
  用户卡片发布按钮恢复 nav_user_newposts_btn 设置门控
- 测试对齐:新增 frontend-lifecycle-contract,重写 navigation/lazyload/toast/
  auth-source/comment/page-display/post-visual 等断言为目标架构契约

验证:node --test widget-system+navigation 223 通过 0 失败;
构建脚本重建 main/imgbox min 与 CSS bundles;改动 PHP php -l、JS node --check
全部通过;git diff --check 干净;credits 重入 harness 通过。
2026-09-03 12:44:31 +08:00

164 lines
5.8 KiB
JavaScript

/**
* AKSRT Report — 前台举报提交
*
* 监听 [data-aksrt-report] 按钮点击,弹出举报表单并提交。
*
* @package AKSRT
*/
(function () {
'use strict';
var API_ROOT = (function () {
var d = window.aksrtData || {};
var raw = d.apiUrl || d.restUrl || d.rest_url || '/index.php?rest_route=/aksrt/v1';
return String(raw).replace(/\/$/, '');
})();
var NONCE = (window.aksrtData && window.aksrtData.restNonce) || '';
function getReportCategories() {
// Default categories; can be overridden by server-rendered config
if (window.aksrtReportCategories && Array.isArray(window.aksrtReportCategories)) {
return window.aksrtReportCategories;
}
return [
{ value: 'spam', label: '垃圾信息' },
{ value: 'abuse', label: '人身攻击' },
{ value: 'copyright', label: '版权投诉' },
{ value: 'other', label: '其他' },
];
}
function createReportModal(data) {
// Remove existing modal if any
var existing = document.getElementById('aksrt-report-modal');
if (existing) existing.remove();
var categories = getReportCategories();
var overlay = document.createElement('div');
overlay.id = 'aksrt-report-modal';
overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:9999;display:flex;align-items:center;justify-content:center;';
var modal = document.createElement('div');
modal.style.cssText = 'background:#fff;border-radius:8px;padding:24px;max-width:420px;width:90%;box-shadow:0 4px 20px rgba(0,0,0,0.15);';
var title = document.createElement('h3');
title.textContent = '提交举报';
title.style.cssText = 'margin:0 0 16px;font-size:16px;font-weight:600;';
modal.appendChild(title);
// Category select
var catLabel = document.createElement('label');
catLabel.textContent = '举报分类';
catLabel.style.cssText = 'display:block;margin-bottom:4px;font-size:13px;color:#555;';
modal.appendChild(catLabel);
var catSelect = document.createElement('select');
catSelect.style.cssText = 'width:100%;padding:8px;border:1px solid #ddd;border-radius:4px;margin-bottom:12px;';
categories.forEach(function (cat) {
var opt = document.createElement('option');
opt.value = cat.value;
opt.textContent = cat.label;
catSelect.appendChild(opt);
});
modal.appendChild(catSelect);
// Reason textarea
var reasonLabel = document.createElement('label');
reasonLabel.textContent = '举报原因';
reasonLabel.style.cssText = 'display:block;margin-bottom:4px;font-size:13px;color:#555;';
modal.appendChild(reasonLabel);
var reasonInput = document.createElement('textarea');
reasonInput.placeholder = '请详细描述举报原因…';
reasonInput.style.cssText = 'width:100%;height:80px;padding:8px;border:1px solid #ddd;border-radius:4px;resize:vertical;margin-bottom:16px;box-sizing:border-box;';
modal.appendChild(reasonInput);
// Buttons
var btnRow = document.createElement('div');
btnRow.style.cssText = 'display:flex;gap:8px;justify-content:flex-end;';
var cancelBtn = document.createElement('button');
cancelBtn.type = 'button';
cancelBtn.textContent = '取消';
cancelBtn.style.cssText = 'padding:8px 16px;border:1px solid #ddd;border-radius:4px;background:#fff;cursor:pointer;';
cancelBtn.onclick = function () { overlay.remove(); };
btnRow.appendChild(cancelBtn);
var submitBtn = document.createElement('button');
submitBtn.type = 'button';
submitBtn.textContent = '提交举报';
submitBtn.style.cssText = 'padding:8px 16px;border:none;border-radius:4px;background:#e74c3c;color:#fff;cursor:pointer;';
submitBtn.onclick = function () {
var reason = reasonInput.value.trim();
if (!reason) {
reasonInput.style.borderColor = '#e74c3c';
reasonInput.focus();
return;
}
submitBtn.disabled = true;
submitBtn.textContent = '提交中…';
fetch(API_ROOT + '/report/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': NONCE,
},
body: JSON.stringify({
target_type: data.target_type,
target_id: data.target_id,
category: catSelect.value,
reason: reason,
}),
})
.then(function (res) { return res.json(); })
.then(function (result) {
overlay.remove();
if (result.success) {
notyf(result.message || '举报已提交');
} else {
notyf(result.message || '提交失败', 'danger');
}
})
.catch(function () {
submitBtn.disabled = false;
submitBtn.textContent = '提交举报';
notyf('网络错误,请重试', 'danger');
});
};
btnRow.appendChild(submitBtn);
modal.appendChild(btnRow);
overlay.appendChild(modal);
overlay.addEventListener('click', function (e) {
if (e.target === overlay) overlay.remove();
});
document.body.appendChild(overlay);
reasonInput.focus();
}
function initReportButtons() {
if (document.documentElement.dataset.aksrtReportInitialized === '1') return;
document.documentElement.dataset.aksrtReportInitialized = '1';
document.addEventListener('click', function (e) {
var btn = e.target.closest('[data-aksrt-report]');
if (!btn) return;
e.preventDefault();
try {
var data = JSON.parse(btn.getAttribute('data-aksrt-report'));
if (data && data.target_type && data.target_id) {
createReportModal(data);
}
} catch {
// invalid data attribute
}
});
}
jQuery(document).off('auto_fun.aksrt-report').on('auto_fun.aksrt-report', initReportButtons);
})();