✍️ 发布通知 API 文档
POST http://localhost:48081/admin-api/test/notification/api/publish-database
{
"Authorization": "Bearer {JWT_TOKEN}",
"Content-Type": "application/json",
"tenant-id": "1"
}
{
"title": "通知标题",
"content": "通知内容详情",
"level": 2,
"summary": "可选的通知摘要",
"targetScope": "SCHOOL_WIDE"
}
{
"code": 0,
"data": {
"notificationId": 123,
"title": "通知标题",
"level": 2,
"status": "PUBLISHED",
"publisherName": "发布者姓名",
"publisherRole": "PRINCIPAL",
"approvalRequired": false,
"securityValidated": true,
"timestamp": 1723456789123
},
"msg": ""
}
const response = await fetch('http://localhost:48081/admin-api/test/notification/api/publish-database', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'tenant-id': '1'
},
body: JSON.stringify({
title: '新学期开学通知',
content: '请全体师生做好开学准备工作',
level: 2,
targetScope: 'SCHOOL_WIDE'
})
});
🗑️ 删除通知 API 文档
DELETE http://localhost:48081/admin-api/test/notification/api/delete/{id}
{
"Authorization": "Bearer {JWT_TOKEN}",
"Content-Type": "application/json",
"tenant-id": "1"
}
{
"code": 0,
"data": {
"deletedId": 123,
"success": true,
"timestamp": 1723456789123
},
"msg": "通知删除成功"
}
const response = await fetch(`http://localhost:48081/admin-api/test/notification/api/delete/${notificationId}`, {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'tenant-id': '1'
}
});
🏗️ Vue 3 实现代码
const notificationList = ref([]);
const currentUser = ref(null);
const loading = ref(false);
const fetchNotifications = async () => {
try {
loading.value = true;
const response = await axios.get('/admin-api/test/notification/api/list', {
headers: {
'Authorization': `Bearer ${token.value}`,
'tenant-id': '1'
}
});
notificationList.value = response.data.data.notifications;
} catch (error) {
ElMessage.error('加载通知列表失败');
} finally {
loading.value = false;
}
};
const publishNotification = async (data) => {
try {
const response = await axios.post('/admin-api/test/notification/api/publish-database', data, {
headers: {
'Authorization': `Bearer ${token.value}`,
'tenant-id': '1'
}
});
if (response.data.code === 0) {
ElMessage.success('通知发布成功');
await fetchNotifications();
}
} catch (error) {
ElMessage.error('发布通知失败');
}
};
const deleteNotification = async (id) => {
try {
const response = await axios.delete(`/admin-api/test/notification/api/delete/${id}`, {
headers: {
'Authorization': `Bearer ${token.value}`,
'tenant-id': '1'
}
});
if (response.data.code === 0) {
ElMessage.success('通知删除成功');
await fetchNotifications();
}
} catch (error) {
ElMessage.error('删除通知失败');
}
};