modified app chat forum theme
This commit is contained in:
@@ -384,17 +384,20 @@ function renderNotifications() {
|
||||
list.innerHTML = notifData.map(n => {
|
||||
const isContestApp = n.type === 'contest_application';
|
||||
const isTeacherApp = n.type === 'teacher_application';
|
||||
const isFriendReq = n.type === 'friend_request';
|
||||
const isResult = n.type === 'contest_result' || n.type === 'teacher_result';
|
||||
const isNewExam = n.type === 'contest_new_exam';
|
||||
const isGraded = n.type === 'exam_graded';
|
||||
const isSystem = n.type === 'system_announcement';
|
||||
const isPendingContest = isContestApp && n.application_status === 'pending';
|
||||
const isPendingTeacher = isTeacherApp && n.application_status === 'pending';
|
||||
const isPendingFriend = isFriendReq && n.application_status === 'pending';
|
||||
let statusHtml = '';
|
||||
if ((isContestApp || isTeacherApp) && n.application_status === 'approved') statusHtml = '<span class="text-xs text-green-600 font-medium">已批准</span>';
|
||||
else if ((isContestApp || isTeacherApp) && n.application_status === 'rejected') statusHtml = '<span class="text-xs text-red-600 font-medium">已拒绝</span>';
|
||||
const icon = isContestApp ? '📋' : isTeacherApp ? '👨🏫' : isResult ? '📢' : isNewExam ? '📝' : isGraded ? '✅' : isSystem ? '📢' : '🔔';
|
||||
const iconBg = isContestApp ? 'bg-orange-100' : isTeacherApp ? 'bg-purple-100' : isResult ? 'bg-green-100' : isNewExam ? 'bg-indigo-100' : isGraded ? 'bg-emerald-100' : isSystem ? 'bg-amber-100' : 'bg-blue-100';
|
||||
else if (isFriendReq && n.application_status === 'accepted') statusHtml = '<span class="text-xs text-green-600 font-medium">已同意</span>';
|
||||
const icon = isContestApp ? '📋' : isTeacherApp ? '👨🏫' : isFriendReq ? '👤' : isResult ? '📢' : isNewExam ? '📝' : isGraded ? '✅' : isSystem ? '📢' : '🔔';
|
||||
const iconBg = isContestApp ? 'bg-orange-100' : isTeacherApp ? 'bg-purple-100' : isFriendReq ? 'bg-blue-100' : isResult ? 'bg-green-100' : isNewExam ? 'bg-indigo-100' : isGraded ? 'bg-emerald-100' : isSystem ? 'bg-amber-100' : 'bg-blue-100';
|
||||
const clickAction = `showNotifDetail(${n.id})`;
|
||||
let actionsHtml = '';
|
||||
if (isPendingContest && currentUser.role === 'admin') {
|
||||
@@ -409,6 +412,12 @@ function renderNotifications() {
|
||||
<button onclick="event.stopPropagation();rejectTeacher(${n.application_id})" class="px-3 py-1 text-xs bg-red-500 text-white rounded hover:bg-red-600">拒绝</button>
|
||||
</div>`;
|
||||
}
|
||||
if (isPendingFriend && n.friend_request_id) {
|
||||
actionsHtml = `<div class="flex gap-2 mt-2">
|
||||
<button onclick="event.stopPropagation();acceptFriendReq(${n.friend_request_id},${n.id})" class="px-3 py-1 text-xs bg-green-500 text-white rounded hover:bg-green-600">同意</button>
|
||||
<button onclick="event.stopPropagation();rejectFriendReq(${n.friend_request_id},${n.id})" class="px-3 py-1 text-xs bg-red-500 text-white rounded hover:bg-red-600">拒绝</button>
|
||||
</div>`;
|
||||
}
|
||||
return `<div class="px-3 py-3 ${n.read ? '' : 'bg-blue-50'} hover:bg-slate-50 border-b border-slate-100 transition cursor-pointer" onclick="${clickAction}">
|
||||
<div class="flex items-start gap-2">
|
||||
<div class="w-8 h-8 rounded-full ${iconBg} flex items-center justify-center flex-shrink-0 mt-0.5">
|
||||
@@ -479,6 +488,26 @@ async function rejectTeacher(appId) {
|
||||
}
|
||||
}
|
||||
|
||||
async function acceptFriendReq(reqId, notifId) {
|
||||
const res = await fetch(`/api/friend/accept/${reqId}`, { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
loadNotifications();
|
||||
} else {
|
||||
alert(data.message || '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function rejectFriendReq(reqId, notifId) {
|
||||
const res = await fetch(`/api/friend/reject/${reqId}`, { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
loadNotifications();
|
||||
} else {
|
||||
alert(data.message || '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function checkUnreadNotifs() {
|
||||
const res = await fetch('/api/notifications/unread-count');
|
||||
const data = await res.json();
|
||||
@@ -517,13 +546,13 @@ function showNotifDetail(nid) {
|
||||
'teacher_application': '教师申请', 'teacher_result': '教师审核结果',
|
||||
'contest_application': '杯赛申请', 'contest_result': '杯赛通知',
|
||||
'contest_new_exam': '新考试', 'exam_graded': '成绩通知',
|
||||
'system_announcement': '系统通知'
|
||||
'system_announcement': '系统通知', 'friend_request': '好友申请'
|
||||
};
|
||||
const typeIcons = {
|
||||
'teacher_application': '👨🏫', 'teacher_result': '🎓',
|
||||
'contest_application': '📋', 'contest_result': '🏅',
|
||||
'contest_new_exam': '📝', 'exam_graded': '✅',
|
||||
'system_announcement': '📢'
|
||||
'system_announcement': '📢', 'friend_request': '👤'
|
||||
};
|
||||
|
||||
document.getElementById('notifDetailIcon').textContent = typeIcons[n.type] || '🔔';
|
||||
@@ -546,6 +575,13 @@ function showNotifDetail(nid) {
|
||||
</div>`;
|
||||
} else if (n.type === 'contest_new_exam' || n.type === 'exam_graded') {
|
||||
actHtml = `<a href="/exams/${n.post_id}" class="inline-block px-4 py-2 text-sm bg-primary text-white rounded-md hover:bg-blue-700">查看考试</a>`;
|
||||
} else if (n.type === 'friend_request' && n.application_status === 'pending' && n.friend_request_id) {
|
||||
actHtml = `<div class="flex gap-3">
|
||||
<button onclick="acceptFriendReq(${n.friend_request_id},${n.id})" class="px-4 py-2 text-sm bg-green-500 text-white rounded-md hover:bg-green-600">同意</button>
|
||||
<button onclick="rejectFriendReq(${n.friend_request_id},${n.id})" class="px-4 py-2 text-sm bg-red-500 text-white rounded-md hover:bg-red-600">拒绝</button>
|
||||
</div>`;
|
||||
} else if (n.type === 'friend_request' && n.application_status === 'accepted') {
|
||||
actHtml = '<span class="text-sm text-green-600 font-medium">✅ 已同意</span>';
|
||||
} else if ((n.type === 'contest_application' || n.type === 'teacher_application') && n.application_status === 'approved') {
|
||||
actHtml = '<span class="text-sm text-green-600 font-medium">✅ 已批准</span>';
|
||||
} else if ((n.type === 'contest_application' || n.type === 'teacher_application') && n.application_status === 'rejected') {
|
||||
|
||||
Reference in New Issue
Block a user