fix: 修复管理后台 JS api 变量冲突导致页面加载失败

- common.js 中 const api 改为 var api,避免与 utils.js 的 function api() 重复声明冲突,导致 roleLabel/statusLabel 等未定义
- common.js 新增 api.del() 方法
- comments.js 升级为对象式 api.get/api.del,修复 api('GET') 函数调用失败
- comments.js 修复 csrfToken 未定义导致删除请求 403
- users.js/audit.js catch 块改为输出真实错误信息
This commit is contained in:
2026-06-02 21:13:58 +08:00
parent ee313675ca
commit 983f539268
4 changed files with 40 additions and 22 deletions

View File

@ -6,7 +6,8 @@
// --- AJAX 封装 (管理后台专用对象式 API) ---
// 注意escapeHtml / formatTime / showToast / getCSRFToken 由 shared/utils.js 统一提供
const api = {
// 使用变量赋值覆盖 utils.js 的 function api(),避免 const 重复声明冲突
var api = {
async get(url) {
const res = await fetch(url, {
headers: { 'Accept': 'application/json' }
@ -34,6 +35,13 @@ const api = {
body: body ? JSON.stringify(body) : undefined
});
return res.json();
},
async del(url) {
const res = await fetch(url, {
method: 'DELETE',
headers: { 'X-CSRF-Token': getCSRFToken() }
});
return res.json();
}
};