Book_system/app/static/js/announcement-manage.js
2025-05-12 19:44:22 +08:00

70 lines
2.0 KiB
JavaScript

// 公告管理页面的Javascript
document.addEventListener('DOMContentLoaded', function() {
// 提示框自动关闭
setTimeout(function() {
const alerts = document.querySelectorAll('.alert-success, .alert-info');
alerts.forEach(alert => {
const bsAlert = new bootstrap.Alert(alert);
bsAlert.close();
});
}, 5000);
});
// 更改公告状态(发布/撤销)
function changeStatus(announcementId, status) {
if (!confirm('确定要' + (status === 1 ? '发布' : '撤销') + '这条公告吗?')) {
return;
}
fetch(`/announcement/status/${announcementId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify({ status: status })
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert(data.message);
location.reload();
} else {
alert('操作失败: ' + data.message);
}
})
.catch(error => {
console.error('Error:', error);
alert('发生错误,请重试');
});
}
// 更改公告置顶状态
function changeTopStatus(announcementId, isTop) {
if (!confirm('确定要' + (isTop ? '置顶' : '取消置顶') + '这条公告吗?')) {
return;
}
fetch(`/announcement/top/${announcementId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify({ is_top: isTop })
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert(data.message);
location.reload();
} else {
alert('操作失败: ' + data.message);
}
})
.catch(error => {
console.error('Error:', error);
alert('发生错误,请重试');
});
}