diff --git a/static/js/modules/blacklists.js b/static/js/modules/blacklists.js index 03ac8d7..2f1cfb1 100644 --- a/static/js/modules/blacklists.js +++ b/static/js/modules/blacklists.js @@ -30,6 +30,7 @@ function loadBlacklists() { apiRequest('/api/shield/blacklists') .then(data => { + // 直接渲染返回的blacklists数组 renderBlacklists(data); }) .catch(error => { @@ -125,6 +126,12 @@ function addBlacklist() { apiRequest('/api/shield/blacklists', 'POST', { name: name, url: url }) .then(data => { + // 检查响应中是否有status字段 + if (!data || typeof data === 'undefined') { + window.showNotification('远程黑名单添加失败: 无效的响应', 'error'); + return; + } + if (data.status === 'success') { window.showNotification('远程黑名单添加成功', 'success'); nameInput.value = ''; @@ -144,6 +151,12 @@ function addBlacklist() { function updateBlacklist(id) { apiRequest(`/api/shield/blacklists/${id}/update`, 'POST') .then(data => { + // 检查响应中是否有status字段 + if (!data || typeof data === 'undefined') { + window.showNotification('远程黑名单更新失败: 无效的响应', 'error'); + return; + } + if (data.status === 'success') { window.showNotification('远程黑名单更新成功', 'success'); loadBlacklists(); @@ -164,6 +177,12 @@ function updateAllBlacklists() { () => { apiRequest('/api/shield/blacklists', 'PUT') .then(data => { + // 检查响应中是否有status字段 + if (!data || typeof data === 'undefined') { + window.showNotification('所有远程黑名单更新失败: 无效的响应', 'error'); + return; + } + if (data.status === 'success') { window.showNotification('所有远程黑名单更新成功', 'success'); loadBlacklists(); @@ -183,6 +202,12 @@ function updateAllBlacklists() { function deleteBlacklist(id) { apiRequest(`/api/shield/blacklists/${id}`, 'DELETE') .then(data => { + // 检查响应中是否有status字段 + if (!data || typeof data === 'undefined') { + window.showNotification('远程黑名单删除失败: 无效的响应', 'error'); + return; + } + if (data.status === 'success') { window.showNotification('远程黑名单删除成功', 'success'); loadBlacklists();