Compare commits
2 Commits
72c08f3689
...
983f539268
| Author | SHA1 | Date | |
|---|---|---|---|
| 983f539268 | |||
| ee313675ca |
@ -136,12 +136,11 @@
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
/* 拒绝弹窗 */
|
||||
/* 拒绝弹窗(显示由 JS 控制,此处不设置 display) */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,.4);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 999;
|
||||
|
||||
@ -55,7 +55,10 @@ function loadTableAudits() {
|
||||
showToast(res.message || '加载失败', 'error');
|
||||
}
|
||||
})
|
||||
.catch(() => showToast('网络错误', 'error'));
|
||||
.catch((e) => {
|
||||
console.error('loadTableAudits error:', e);
|
||||
showToast('加载失败: ' + (e.message || '网络错误'), 'error');
|
||||
});
|
||||
}
|
||||
|
||||
function loadAvatarAudits() {
|
||||
@ -69,7 +72,10 @@ function loadAvatarAudits() {
|
||||
showToast(res.message || '加载失败', 'error');
|
||||
}
|
||||
})
|
||||
.catch(() => showToast('网络错误', 'error'));
|
||||
.catch((e) => {
|
||||
console.error('loadAvatarAudits error:', e);
|
||||
showToast('加载失败: ' + (e.message || '网络错误'), 'error');
|
||||
});
|
||||
}
|
||||
|
||||
function loadHistory() {
|
||||
@ -83,7 +89,10 @@ function loadHistory() {
|
||||
showToast(res.message || '加载失败', 'error');
|
||||
}
|
||||
})
|
||||
.catch(() => showToast('网络错误', 'error'));
|
||||
.catch((e) => {
|
||||
console.error('loadHistory error:', e);
|
||||
showToast('加载失败: ' + (e.message || '网络错误'), 'error');
|
||||
});
|
||||
}
|
||||
|
||||
/* =========================================
|
||||
|
||||
@ -11,16 +11,17 @@
|
||||
var pagination = document.getElementById('commentPagination');
|
||||
var loading = document.getElementById('commentLoading');
|
||||
|
||||
// escapeHtml / formatTime / api 由 shared/utils.js 统一提供
|
||||
// escapeHtml / formatTime / showToast / showConfirm / getCSRFToken 由 shared/utils.js 提供
|
||||
// api (对象式) 由 admin/static/js/common.js 提供
|
||||
|
||||
function loadComments(page) {
|
||||
loading.style.display = 'block';
|
||||
var url = '/api/admin/comments?page=' + page + '&page_size=20';
|
||||
if (currentKeyword) url += '&keyword=' + encodeURIComponent(currentKeyword);
|
||||
|
||||
api('GET', url).then(function(d) {
|
||||
api.get(url).then(function(d) {
|
||||
loading.style.display = 'none';
|
||||
if (!d.success) return;
|
||||
if (!d.success) { showToast(d.message || '加载失败', 'error'); return; }
|
||||
totalPages = d.data.total_pages || 1;
|
||||
tbody.innerHTML = '';
|
||||
var items = d.data.items || [];
|
||||
@ -46,6 +47,7 @@
|
||||
bindDeleteBtns();
|
||||
}).catch(function() {
|
||||
loading.style.display = 'none';
|
||||
showToast('加载失败', 'error');
|
||||
tbody.innerHTML = '<tr><td colspan="6" style="text-align:center;padding:40px;color:#dc2626">加载失败</td></tr>';
|
||||
});
|
||||
}
|
||||
@ -55,21 +57,19 @@
|
||||
for (var i = 0; i < btns.length; i++) {
|
||||
if (btns[i]._bound) continue;
|
||||
btns[i]._bound = true;
|
||||
btns[i].addEventListener('click', async function() {
|
||||
btns[i].addEventListener('click', function() {
|
||||
var id = this.dataset.id;
|
||||
var ok = await showConfirm('确认', '确认删除此评论?');
|
||||
if (!ok) return;
|
||||
fetch('/api/admin/comments/' + id, {
|
||||
method: 'DELETE',
|
||||
headers: { 'X-CSRF-Token': csrfToken }
|
||||
}).then(function(r) { return r.json(); })
|
||||
.then(function(d) {
|
||||
if (d.success) {
|
||||
loadComments(currentPage);
|
||||
} else {
|
||||
alert(d.message || '删除失败');
|
||||
}
|
||||
}).catch(function() { alert('请求失败'); });
|
||||
showConfirm('确认', '确认删除此评论?').then(function(ok) {
|
||||
if (!ok) return;
|
||||
api.del('/api/admin/comments/' + id).then(function(d) {
|
||||
if (d.success) {
|
||||
showToast(d.message, 'success');
|
||||
loadComments(currentPage);
|
||||
} else {
|
||||
showToast(d.message || '删除失败', 'error');
|
||||
}
|
||||
}).catch(function() { showToast('请求失败', 'error'); });
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -44,7 +44,8 @@ async function loadUsers() {
|
||||
showToast(res.message || '加载失败', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showToast('网络错误', 'error');
|
||||
console.error('loadUsers error:', e);
|
||||
showToast('加载失败: ' + (e.message || '网络错误'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user