865 lines
32 KiB
Vue
865 lines
32 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onMounted, ref } from 'vue'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import { Bell, Operation } from '@element-plus/icons-vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import http, { apiErrorMessage } from '../api/http'
|
||
import { branding } from '../config/branding'
|
||
import { useAuthStore } from '../stores/auth'
|
||
import { usePluginStore } from '../stores/plugins'
|
||
|
||
const unreadNotifCount = ref(0)
|
||
|
||
async function pollUnread() {
|
||
try {
|
||
const { data } = await http.get('/notifications/unread-count')
|
||
unreadNotifCount.value = data.count
|
||
} catch (_) { /* ignore */ }
|
||
}
|
||
|
||
interface NavigationItem {
|
||
id?: string
|
||
path: string
|
||
label: string
|
||
}
|
||
|
||
interface NavigationGroup {
|
||
key: string
|
||
label: string
|
||
direct?: boolean
|
||
items: NavigationItem[]
|
||
}
|
||
|
||
const stableNavigationIds: Record<string, string> = {
|
||
'/dashboard': 'dashboard',
|
||
'/academic-calendar': 'academic-calendar',
|
||
'/statistics': 'statistics',
|
||
'/experiments': 'experiments',
|
||
'/experiment-grades': 'experiment-grades',
|
||
'/base-data/organization': 'base-data.organization',
|
||
'/base-data/terms': 'base-data.terms',
|
||
'/base-data/facilities': 'base-data.facilities',
|
||
'/teachers': 'teachers',
|
||
'/students': 'students',
|
||
'/users': 'users',
|
||
'/plugins': 'plugins',
|
||
'/operations': 'operations',
|
||
'/base-data/course-categories': 'base-data.course-categories',
|
||
'/courses': 'courses',
|
||
'/teaching-preferences': 'teaching-preferences',
|
||
'/curriculum': 'curriculum',
|
||
'/course-equivalency-rules': 'course-equivalency-rules',
|
||
'/my-curriculum': 'my-curriculum',
|
||
'/teaching-tasks': 'teaching-tasks',
|
||
'/schedules': 'schedules',
|
||
'/my-timetable': 'my-timetable',
|
||
'/free-classrooms': 'free-classrooms',
|
||
'/venue-displays': 'venue-displays',
|
||
'/class-timetable': 'class-timetable',
|
||
'/classroom-reservations': 'classroom-reservations',
|
||
'/campus-registrations': 'campus-registrations',
|
||
'/campus-wallets': 'campus-wallets',
|
||
'/tuition': 'tuition',
|
||
'/classroom-repairs': 'classroom-repairs',
|
||
'/dormitory-services': 'dormitory-services',
|
||
'/dormitory-overview': 'dormitory-overview',
|
||
'/dormitory-buildings': 'dormitory-buildings',
|
||
'/dormitory-allocation': 'dormitory-allocation',
|
||
'/dormitory-applications': 'dormitory-applications',
|
||
'/dormitory-hygiene-scores': 'dormitory-hygiene-scores',
|
||
'/course-selections': 'course-selections',
|
||
'/course-enrollments': 'course-enrollments',
|
||
'/teacher-attendance': 'teacher-attendance',
|
||
'/my-attendance': 'my-attendance',
|
||
'/evaluations': 'evaluations',
|
||
'/teacher-roster': 'teacher-roster',
|
||
'/grades': 'grades',
|
||
'/academic-overview': 'academic-overview',
|
||
'/grade-analytics': 'grade-analytics',
|
||
'/event-analytics': 'event-analytics',
|
||
'/other-exams': 'other-exams',
|
||
'/exams': 'exams',
|
||
'/makeup-exams': 'makeup-exams',
|
||
'/physical-fitness': 'physical-fitness',
|
||
'/comprehensive-assessments': 'comprehensive-assessments',
|
||
'/my-profile': 'my-profile',
|
||
'/student-status-changes': 'student-status-changes',
|
||
'/official-documents': 'official-documents',
|
||
'/approvals': 'approvals',
|
||
'/warnings': 'warnings',
|
||
'/academic-planning': 'academic-planning',
|
||
'/graduation-audits': 'graduation-audits',
|
||
'/degree-awards': 'degree-awards',
|
||
'/graduation-clearance': 'graduation-clearance',
|
||
}
|
||
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
const auth = useAuthStore()
|
||
const plugins = usePluginStore()
|
||
const mobileMenu = ref(false)
|
||
const favoritesDialog = ref(false)
|
||
const savingFavorites = ref(false)
|
||
const draftFavoriteIds = ref<string[]>([])
|
||
const draggedFavoriteId = ref('')
|
||
const favoriteLimit = 12
|
||
|
||
const roles = computed(() => auth.user?.roles ?? [])
|
||
const isStudent = computed(() => roles.value.includes('Student'))
|
||
const isTeacher = computed(() => roles.value.includes('Teacher'))
|
||
const isTeachingAdmin = computed(() =>
|
||
roles.value.some((role) => ['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin'].includes(role)),
|
||
)
|
||
const isTimetableManager = computed(() =>
|
||
roles.value.some((role) =>
|
||
['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Leader'].includes(role),
|
||
),
|
||
)
|
||
|
||
const isStatisticsViewer = computed(() =>
|
||
roles.value.some((role) =>
|
||
['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Leader'].includes(role),
|
||
),
|
||
)
|
||
|
||
const canUseExperiments = computed(() =>
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher', 'Student']),
|
||
)
|
||
|
||
function hasAnyRole(allowedRoles: string[]) {
|
||
return roles.value.some((role) => allowedRoles.includes(role))
|
||
}
|
||
|
||
function whenVisible(visible: boolean, item: NavigationItem) {
|
||
return visible ? [item] : []
|
||
}
|
||
|
||
function isNavigationItemEnabled(item: NavigationItem) {
|
||
const owner = plugins.items.find((plugin) =>
|
||
plugin.navigationPaths.includes(item.path),
|
||
)
|
||
return !owner || owner.isEnabled
|
||
}
|
||
|
||
function navigationItemId(item: NavigationItem) {
|
||
return item.id ?? stableNavigationIds[item.path]
|
||
?? item.path.replace(/^\//, '').replaceAll('/', '.')
|
||
}
|
||
|
||
const availableNavigationGroups = computed<NavigationGroup[]>(() => [
|
||
{
|
||
key: 'overview',
|
||
label: '教务总览',
|
||
items: [
|
||
{ path: '/dashboard', label: '教务总览' },
|
||
{ path: '/academic-calendar', label: '学期校历与日程' },
|
||
],
|
||
},
|
||
...(isStatisticsViewer.value
|
||
? [{
|
||
key: 'statistics',
|
||
label: '统计报表',
|
||
direct: true,
|
||
items: [{ path: '/statistics', label: '统计报表' }],
|
||
} as NavigationGroup]
|
||
: []),
|
||
...(canUseExperiments.value
|
||
? [{
|
||
key: 'experiments',
|
||
label: isStudent.value ? '我的实验' : '实验管理',
|
||
items: [
|
||
{
|
||
path: '/experiments',
|
||
label: isStudent.value ? '实验安排' : '项目与场次',
|
||
},
|
||
{
|
||
path: '/experiment-grades',
|
||
label: '实验成绩',
|
||
},
|
||
],
|
||
} as NavigationGroup]
|
||
: []),
|
||
{
|
||
key: 'organization',
|
||
label: '组织与权限',
|
||
items: [
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin']),
|
||
{ path: '/base-data/organization', label: '组织机构' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin']),
|
||
{ path: '/base-data/terms', label: '学年学期' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin']),
|
||
{ path: '/base-data/facilities', label: '教学场所' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Counselor']),
|
||
{ path: '/teachers', label: '教师档案' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Counselor']),
|
||
{ path: '/students', label: '学生档案' },
|
||
),
|
||
...whenVisible(auth.isSuperAdmin, { path: '/users', label: '用户与权限' }),
|
||
...whenVisible(auth.isSuperAdmin, { path: '/plugins', label: '插件中心' }),
|
||
...whenVisible(auth.isSuperAdmin, { path: '/operations', label: '运维与审计' }),
|
||
],
|
||
},
|
||
{
|
||
key: 'teaching-construction',
|
||
label: '教学建设',
|
||
items: [
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin']),
|
||
{ path: '/base-data/course-categories', label: '课程分类' },
|
||
),
|
||
{ path: '/courses', label: '课程库' },
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher']),
|
||
{
|
||
path: '/teaching-preferences',
|
||
label: isTeacher.value ? '授课科目申报' : '授课资格审核',
|
||
},
|
||
),
|
||
...whenVisible(isTeachingAdmin.value, { path: '/curriculum', label: '培养方案' }),
|
||
...whenVisible(isTeachingAdmin.value, { path: '/course-equivalency-rules', label: '等价课程规则' }),
|
||
...whenVisible(isStudent.value, { path: '/my-curriculum', label: '我的培养方案' }),
|
||
...whenVisible(isTeachingAdmin.value, { path: '/teaching-tasks', label: '教学任务' }),
|
||
],
|
||
},
|
||
{
|
||
key: 'teaching-operation',
|
||
label: '教学运行',
|
||
items: [
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin']),
|
||
{ path: '/schedules', label: '排课与课表' },
|
||
),
|
||
...whenVisible(isStudent.value || isTeacher.value, { path: '/my-timetable', label: isTeacher.value ? '我的授课课表' : '我的课表' }),
|
||
...whenVisible(isStudent.value, { path: '/free-classrooms', label: '空闲教室' }),
|
||
...whenVisible(hasAnyRole(['SuperAdmin', 'AcademicAdmin']), { path: '/venue-displays', label: '场地信息展牌' }),
|
||
{
|
||
path: '/class-timetable',
|
||
label: isTimetableManager.value ? '课表查询中心' : '班级课表查询',
|
||
},
|
||
{
|
||
path: '/classroom-reservations',
|
||
label: hasAnyRole(['CollegeAdmin']) ? '教室借用审核' : '教室借用',
|
||
},
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Student']),
|
||
{ path: '/campus-registrations', label: isStudent.value ? '校园报名与缴费' : '校园支付与报名' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin']),
|
||
{ path: '/campus-wallets', label: '学生余额管理' },
|
||
),
|
||
...whenVisible(hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'Student']), { path: '/tuition', label: isStudent.value ? '我的学费' : '学费管理' }),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'MaintenanceAdmin', 'MaintenanceStaff']),
|
||
{ path: '/classroom-repairs', label: '教室报修与维修' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Student']),
|
||
{
|
||
path: '/course-selections',
|
||
label: isTeachingAdmin.value ? '选课管理' : '学生选课',
|
||
},
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin']),
|
||
{ path: '/course-enrollments', label: '修读课程管理' },
|
||
),
|
||
],
|
||
},
|
||
{
|
||
key: 'dormitory-management',
|
||
label: isStudent.value ? '住宿服务' : '宿舍管理',
|
||
items: [
|
||
...whenVisible(isStudent.value, { path: '/dormitory-services', label: '我的住宿服务' }),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'DormitoryAdmin', 'CollegeAdmin', 'Counselor']),
|
||
{ path: '/dormitory-overview', label: '宿舍数据总览' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'DormitoryAdmin', 'CollegeAdmin', 'Counselor']),
|
||
{ path: '/dormitory-buildings', label: '楼栋与床位管理' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'DormitoryAdmin']),
|
||
{ path: '/dormitory-allocation', label: '宿舍分配与调宿' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'DormitoryAdmin', 'CollegeAdmin', 'Counselor']),
|
||
{ path: '/dormitory-applications', label: '住宿申请审批' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'DormitoryAdmin', 'CollegeAdmin', 'Counselor']),
|
||
{ path: '/dormitory-hygiene-scores', label: '宿舍卫生成绩' },
|
||
),
|
||
],
|
||
},
|
||
{
|
||
key: 'teaching-assessment',
|
||
label: '教学考核',
|
||
items: [
|
||
...whenVisible(isTeacher.value || isTeachingAdmin.value || hasAnyRole(['Counselor']), { path: '/teacher-attendance', label: '教学点名' }),
|
||
...whenVisible(isStudent.value, { path: '/my-attendance', label: '我的考勤' }),
|
||
{
|
||
path: '/evaluations',
|
||
label: isStudent.value ? '学生评教' : isTeacher.value ? '评教结果' : '教学评价',
|
||
},
|
||
...whenVisible(isTeacher.value, { path: '/teacher-roster', label: '选课名单' }),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher', 'Student', 'Counselor']),
|
||
{ path: '/grades', label: isStudent.value ? '本学期成绩' : isTeacher.value ? '成绩录入' : '成绩管理' },
|
||
),
|
||
...whenVisible(
|
||
isStudent.value,
|
||
{ path: '/academic-overview', label: '学业成绩总览' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Leader', 'Teacher']),
|
||
{ path: '/grade-analytics', label: isTeacher.value ? '教学班成绩分析' : '成绩分析中心' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Leader']),
|
||
{ path: '/event-analytics', label: '运行数据分析' },
|
||
),
|
||
],
|
||
},
|
||
{
|
||
key: 'examinations',
|
||
label: '考试管理',
|
||
items: [
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'Student']),
|
||
{ path: '/other-exams', label: '其他考试成绩' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'Teacher', 'Student']),
|
||
{
|
||
path: '/exams',
|
||
label: isStudent.value ? '我的考试' : isTeacher.value ? '我的监考' : '考试管理',
|
||
},
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'Teacher', 'Student']),
|
||
{
|
||
path: '/makeup-exams',
|
||
label: isStudent.value ? '我的补考' : isTeacher.value ? '补考监考' : '补考安排',
|
||
},
|
||
),
|
||
],
|
||
},
|
||
{
|
||
key: 'physical-health',
|
||
label: '体育健康',
|
||
items: [
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'PhysicalEducationAdmin', 'CollegeAdmin', 'Counselor', 'Student']),
|
||
{ path: '/physical-fitness', label: isStudent.value ? '我的体测' : '体测管理' },
|
||
),
|
||
],
|
||
},
|
||
{
|
||
key: 'student-development',
|
||
label: '学生发展',
|
||
items: [
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'StudentAffairsAdmin', 'CollegeAdmin', 'Counselor', 'Leader', 'Student']),
|
||
{ path: '/comprehensive-assessments', label: isStudent.value ? '我的综合测评' : '综合测评' },
|
||
),
|
||
],
|
||
},
|
||
{
|
||
key: 'student-status',
|
||
label: '学籍与服务',
|
||
items: [
|
||
...whenVisible(
|
||
isStudent.value,
|
||
{ path: '/my-profile', label: '个人信息' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Counselor', 'Student']),
|
||
{ path: '/student-status-changes', label: isStudent.value ? '学籍异动' : '异动审核' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Student']),
|
||
{ path: '/official-documents', label: isStudent.value ? '电子成绩单与证明' : '官方凭证签发' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Counselor', 'Teacher', 'Student']),
|
||
{ path: '/approvals', label: '审批工作台' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'Counselor', 'Student']),
|
||
{ path: '/warnings', label: '学业预警' },
|
||
),
|
||
],
|
||
},
|
||
{
|
||
key: 'graduation',
|
||
label: '毕业管理',
|
||
items: [
|
||
...whenVisible(
|
||
isStudent.value,
|
||
{ path: '/academic-planning', label: '学业规划与毕业模拟' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Student']),
|
||
{ path: '/graduation-audits', label: isStudent.value ? '毕业资格' : '毕业审核' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Student']),
|
||
{ path: '/degree-awards', label: isStudent.value ? '学位结果' : '学位授予' },
|
||
),
|
||
...whenVisible(
|
||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Counselor', 'Student']),
|
||
{ path: '/graduation-clearance', label: isStudent.value ? '毕业离校' : '离校办理' },
|
||
),
|
||
],
|
||
},
|
||
]
|
||
.map((group) => ({
|
||
...group,
|
||
items: group.items.filter(isNavigationItemEnabled),
|
||
}))
|
||
.filter((group) => group.items.length > 0))
|
||
|
||
const allNavigationItems = computed(() =>
|
||
availableNavigationGroups.value.flatMap((group) => group.items),
|
||
)
|
||
|
||
const defaultFavoriteIds = computed(() => {
|
||
if (isStudent.value) return ['my-timetable', 'grades', 'exams', 'approvals']
|
||
if (isTeacher.value) return ['my-timetable', 'teacher-attendance', 'grades', 'exams']
|
||
if (isTeachingAdmin.value) return ['dashboard', 'teaching-tasks', 'schedules', 'grades']
|
||
return ['dashboard', 'notifications']
|
||
})
|
||
|
||
const configuredFavoriteIds = computed(() => {
|
||
const preference = auth.user?.navigationPreference
|
||
return preference?.isCustomized
|
||
? preference.favoriteItemIds
|
||
: defaultFavoriteIds.value
|
||
})
|
||
|
||
const favoriteItems = computed(() => {
|
||
const byId = new Map(
|
||
allNavigationItems.value.map((item) => [navigationItemId(item), item]),
|
||
)
|
||
return configuredFavoriteIds.value
|
||
.map((id) => byId.get(id))
|
||
.filter((item): item is NavigationItem => Boolean(item))
|
||
})
|
||
|
||
const navigationGroups = computed<NavigationGroup[]>(() => [
|
||
...(favoriteItems.value.length
|
||
? [{ key: 'favorites', label: '常用', items: favoriteItems.value }]
|
||
: []),
|
||
...availableNavigationGroups.value,
|
||
])
|
||
|
||
const activeGroupKey = computed(
|
||
() => availableNavigationGroups.value.find((group) =>
|
||
group.items.some((item) => item.path === route.path),
|
||
)?.key ?? '',
|
||
)
|
||
|
||
const currentNavigationItem = computed(() =>
|
||
allNavigationItems.value.find((item) => item.path === route.path),
|
||
)
|
||
|
||
const isCurrentFavorite = computed(() => {
|
||
const item = currentNavigationItem.value
|
||
return Boolean(item && configuredFavoriteIds.value.includes(navigationItemId(item)))
|
||
})
|
||
|
||
const workspaceLabel = computed(() => {
|
||
if (roles.value.includes('SuperAdmin')) return '系统全域管理'
|
||
if (roles.value.includes('AcademicAdmin')) return '校级教务管理'
|
||
if (roles.value.includes('CollegeAdmin')) return '学院教务管理'
|
||
if (roles.value.includes('DormitoryAdmin')) return '宿舍管理工作台'
|
||
if (roles.value.includes('StudentAffairsAdmin')) return '学生工作管理台'
|
||
if (roles.value.includes('Counselor')) return '辅导员班级工作'
|
||
if (roles.value.includes('Teacher')) return '教师教学工作'
|
||
if (roles.value.includes('Student')) return '学生学业服务'
|
||
return '教务工作台'
|
||
})
|
||
|
||
const pageTitle = computed(() => {
|
||
if (route.path === '/account') return '个人账户'
|
||
const matchedItem = navigationGroups.value
|
||
.flatMap((group) => group.items)
|
||
.find((item) => item.path === route.path)
|
||
return matchedItem?.label ?? '教务管理'
|
||
})
|
||
|
||
function signOut() {
|
||
plugins.reset()
|
||
auth.logout()
|
||
router.push('/login')
|
||
}
|
||
|
||
function handleNavigationSelect(index: string) {
|
||
const path = index.startsWith('favorite:') ? index.slice('favorite:'.length) : index
|
||
mobileMenu.value = false
|
||
if (path !== route.path) router.push(path)
|
||
}
|
||
|
||
function openFavoritesDialog() {
|
||
draftFavoriteIds.value = favoriteItems.value.map(navigationItemId)
|
||
favoritesDialog.value = true
|
||
}
|
||
|
||
function toggleDraftFavorite(item: NavigationItem) {
|
||
const id = navigationItemId(item)
|
||
const index = draftFavoriteIds.value.indexOf(id)
|
||
if (index >= 0) {
|
||
draftFavoriteIds.value.splice(index, 1)
|
||
return
|
||
}
|
||
if (draftFavoriteIds.value.length >= favoriteLimit) {
|
||
ElMessage.warning(`常用功能最多添加 ${favoriteLimit} 项。`)
|
||
return
|
||
}
|
||
draftFavoriteIds.value.push(id)
|
||
}
|
||
|
||
function moveDraftFavorite(id: string, offset: number) {
|
||
const index = draftFavoriteIds.value.indexOf(id)
|
||
const target = index + offset
|
||
if (index < 0 || target < 0 || target >= draftFavoriteIds.value.length) return
|
||
const next = [...draftFavoriteIds.value]
|
||
;[next[index], next[target]] = [next[target], next[index]]
|
||
draftFavoriteIds.value = next
|
||
}
|
||
|
||
function dropDraftFavorite(targetId: string) {
|
||
const sourceId = draggedFavoriteId.value
|
||
draggedFavoriteId.value = ''
|
||
if (!sourceId || sourceId === targetId) return
|
||
const next = [...draftFavoriteIds.value]
|
||
const sourceIndex = next.indexOf(sourceId)
|
||
const targetIndex = next.indexOf(targetId)
|
||
if (sourceIndex < 0 || targetIndex < 0) return
|
||
next.splice(sourceIndex, 1)
|
||
next.splice(targetIndex, 0, sourceId)
|
||
draftFavoriteIds.value = next
|
||
}
|
||
|
||
async function saveFavorites(ids = draftFavoriteIds.value, closeDialog = true) {
|
||
savingFavorites.value = true
|
||
try {
|
||
await auth.updateNavigationPreference(ids)
|
||
if (closeDialog) favoritesDialog.value = false
|
||
ElMessage.success('常用功能已保存。')
|
||
} catch (error) {
|
||
ElMessage.error(apiErrorMessage(error))
|
||
} finally {
|
||
savingFavorites.value = false
|
||
}
|
||
}
|
||
|
||
async function toggleCurrentFavorite() {
|
||
const item = currentNavigationItem.value
|
||
if (!item || savingFavorites.value) return
|
||
const id = navigationItemId(item)
|
||
const next = favoriteItems.value.map(navigationItemId)
|
||
const index = next.indexOf(id)
|
||
if (index >= 0) next.splice(index, 1)
|
||
else {
|
||
if (next.length >= favoriteLimit) {
|
||
ElMessage.warning(`常用功能最多添加 ${favoriteLimit} 项。`)
|
||
return
|
||
}
|
||
next.push(id)
|
||
}
|
||
await saveFavorites(next, false)
|
||
}
|
||
|
||
async function resetFavorites() {
|
||
savingFavorites.value = true
|
||
try {
|
||
await auth.resetNavigationPreference()
|
||
draftFavoriteIds.value = favoriteItems.value.map(navigationItemId)
|
||
favoritesDialog.value = false
|
||
ElMessage.success('已恢复当前角色的默认常用功能。')
|
||
} catch (error) {
|
||
ElMessage.error(apiErrorMessage(error))
|
||
} finally {
|
||
savingFavorites.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
auth.refresh().catch(() => undefined)
|
||
plugins.load().catch(() => undefined)
|
||
pollUnread()
|
||
setInterval(pollUnread, 60000)
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div class="shell">
|
||
<header class="app-header">
|
||
<div class="topbar">
|
||
<button
|
||
class="menu-toggle mobile-only"
|
||
type="button"
|
||
aria-label="打开导航菜单"
|
||
@click="mobileMenu = true"
|
||
>
|
||
<el-icon><Operation /></el-icon>
|
||
</button>
|
||
|
||
<div class="brand top-brand">
|
||
<div class="brand-mark" aria-hidden="true">
|
||
<span v-for="index in 9" :key="index" />
|
||
</div>
|
||
<div>
|
||
<strong>{{ branding.shortName }}</strong>
|
||
<small>{{ branding.tagline }}</small>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="workspace-context">
|
||
<span>{{ workspaceLabel }}</span>
|
||
<div class="page-title-row">
|
||
<b>{{ pageTitle }}</b>
|
||
<button
|
||
v-if="currentNavigationItem"
|
||
type="button"
|
||
class="favorite-page-button"
|
||
:class="{ 'is-favorite': isCurrentFavorite }"
|
||
:title="isCurrentFavorite ? '从常用中移除' : '添加到常用'"
|
||
:aria-label="isCurrentFavorite ? '从常用中移除' : '添加到常用'"
|
||
:disabled="savingFavorites"
|
||
@click="toggleCurrentFavorite"
|
||
>
|
||
{{ isCurrentFavorite ? '★' : '☆' }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="user-block">
|
||
<el-badge :value="unreadNotifCount" :hidden="!unreadNotifCount" :max="99">
|
||
<el-button :icon="Bell" circle text @click="router.push('/notifications')" title="消息中心" />
|
||
</el-badge>
|
||
<div class="avatar">{{ auth.user?.displayName?.slice(0, 1) ?? '管' }}</div>
|
||
<div class="user-copy">
|
||
<b>{{ auth.user?.displayName ?? '系统管理员' }}</b>
|
||
<span>{{ auth.user?.roles?.[0] ?? '教务人员' }}</span>
|
||
</div>
|
||
<el-button class="desktop-account-action" text @click="openFavoritesDialog">管理常用</el-button>
|
||
<el-button class="desktop-account-action" text @click="router.push('/account')">个人账户</el-button>
|
||
<el-button class="desktop-account-action" text @click="signOut">退出</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<nav class="desktop-navigation desktop-only" aria-label="主导航">
|
||
<el-menu
|
||
mode="horizontal"
|
||
menu-trigger="hover"
|
||
unique-opened
|
||
:default-active="route.path"
|
||
:ellipsis="false"
|
||
class="horizontal-menu"
|
||
@select="handleNavigationSelect"
|
||
>
|
||
<template v-for="group in navigationGroups" :key="group.key">
|
||
<el-menu-item v-if="group.direct" :index="group.items[0].path">
|
||
{{ group.label }}
|
||
</el-menu-item>
|
||
<el-sub-menu
|
||
v-else
|
||
:index="group.key"
|
||
:show-timeout="80"
|
||
:hide-timeout="180"
|
||
>
|
||
<template #title>{{ group.label }}</template>
|
||
<el-menu-item
|
||
v-for="item in group.items"
|
||
:key="item.path"
|
||
:index="group.key === 'favorites' ? `favorite:${item.path}` : item.path"
|
||
>
|
||
{{ item.label }}
|
||
</el-menu-item>
|
||
</el-sub-menu>
|
||
</template>
|
||
</el-menu>
|
||
</nav>
|
||
</header>
|
||
|
||
<aside class="mobile-navigation" :class="{ 'is-mobile-open': mobileMenu }">
|
||
<div class="mobile-navigation-head">
|
||
<div class="brand">
|
||
<div class="brand-mark" aria-hidden="true">
|
||
<span v-for="index in 9" :key="index" />
|
||
</div>
|
||
<div>
|
||
<strong>{{ branding.shortName }}</strong>
|
||
<small>{{ branding.tagline }}</small>
|
||
</div>
|
||
</div>
|
||
<button type="button" aria-label="关闭导航菜单" @click="mobileMenu = false">×</button>
|
||
</div>
|
||
|
||
<div class="term-stamp">
|
||
<span>当前工作区</span>
|
||
<b>{{ workspaceLabel }}</b>
|
||
</div>
|
||
|
||
<el-menu
|
||
:default-active="route.path"
|
||
:default-openeds="activeGroupKey ? [activeGroupKey] : []"
|
||
unique-opened
|
||
class="mobile-nav-menu"
|
||
@select="handleNavigationSelect"
|
||
>
|
||
<template v-for="group in navigationGroups" :key="group.key">
|
||
<el-menu-item v-if="group.direct" :index="group.items[0].path">
|
||
{{ group.label }}
|
||
</el-menu-item>
|
||
<el-sub-menu v-else :index="group.key">
|
||
<template #title>{{ group.label }}</template>
|
||
<el-menu-item
|
||
v-for="item in group.items"
|
||
:key="item.path"
|
||
:index="group.key === 'favorites' ? `favorite:${item.path}` : item.path"
|
||
>
|
||
{{ item.label }}
|
||
</el-menu-item>
|
||
</el-sub-menu>
|
||
</template>
|
||
</el-menu>
|
||
|
||
<div class="mobile-account-actions">
|
||
<button type="button" @click="openFavoritesDialog(); mobileMenu = false">
|
||
<span>管理常用</span>
|
||
<small>收藏与调整常用功能顺序</small>
|
||
</button>
|
||
<button type="button" @click="router.push('/account'); mobileMenu = false">
|
||
<span>个人账户</span>
|
||
<small>{{ auth.user?.displayName ?? '当前用户' }}</small>
|
||
</button>
|
||
<button type="button" class="mobile-sign-out" @click="signOut">
|
||
退出登录
|
||
</button>
|
||
</div>
|
||
|
||
</aside>
|
||
|
||
<div v-if="mobileMenu" class="mobile-mask" @click="mobileMenu = false" />
|
||
|
||
<main class="main-area">
|
||
<section class="content">
|
||
<RouterView />
|
||
</section>
|
||
</main>
|
||
|
||
<el-dialog
|
||
v-model="favoritesDialog"
|
||
title="管理常用功能"
|
||
width="min(880px, calc(100vw - 24px))"
|
||
class="favorites-dialog"
|
||
:close-on-click-modal="!savingFavorites"
|
||
:close-on-press-escape="!savingFavorites"
|
||
>
|
||
<p class="favorites-intro">
|
||
最多添加 {{ favoriteLimit }} 项。左侧可拖动排序,右侧选择你有权限使用的功能。
|
||
</p>
|
||
<div class="favorites-editor">
|
||
<section class="selected-favorites" aria-label="已选择的常用功能">
|
||
<header>
|
||
<b>已选择</b>
|
||
<span>{{ draftFavoriteIds.length }}/{{ favoriteLimit }}</span>
|
||
</header>
|
||
<div v-if="!draftFavoriteIds.length" class="favorites-empty">
|
||
暂未添加常用功能,可以从右侧选择。
|
||
</div>
|
||
<div
|
||
v-for="(id, index) in draftFavoriteIds"
|
||
:key="id"
|
||
class="favorite-sort-row"
|
||
draggable="true"
|
||
@dragstart="draggedFavoriteId = id"
|
||
@dragend="draggedFavoriteId = ''"
|
||
@dragover.prevent
|
||
@drop.prevent="dropDraftFavorite(id)"
|
||
>
|
||
<span class="drag-handle" aria-hidden="true">⋮⋮</span>
|
||
<span>{{ allNavigationItems.find(item => navigationItemId(item) === id)?.label ?? id }}</span>
|
||
<div class="favorite-row-actions">
|
||
<button type="button" :disabled="index === 0" aria-label="上移" @click="moveDraftFavorite(id, -1)">↑</button>
|
||
<button type="button" :disabled="index === draftFavoriteIds.length - 1" aria-label="下移" @click="moveDraftFavorite(id, 1)">↓</button>
|
||
<button type="button" aria-label="移除" @click="draftFavoriteIds.splice(index, 1)">×</button>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="available-favorites" aria-label="可添加的功能">
|
||
<header><b>全部可用功能</b><span>按业务分组</span></header>
|
||
<div v-for="group in availableNavigationGroups" :key="group.key" class="favorite-option-group">
|
||
<strong>{{ group.label }}</strong>
|
||
<div>
|
||
<button
|
||
v-for="item in group.items"
|
||
:key="navigationItemId(item)"
|
||
type="button"
|
||
class="favorite-option"
|
||
:class="{ 'is-selected': draftFavoriteIds.includes(navigationItemId(item)) }"
|
||
@click="toggleDraftFavorite(item)"
|
||
>
|
||
<span>{{ draftFavoriteIds.includes(navigationItemId(item)) ? '★' : '☆' }}</span>
|
||
{{ item.label }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
<template #footer>
|
||
<el-button :disabled="savingFavorites" @click="resetFavorites">恢复角色默认</el-button>
|
||
<el-button :disabled="savingFavorites" @click="favoritesDialog = false">取消</el-button>
|
||
<el-button type="primary" :loading="savingFavorites" @click="saveFavorites()">保存常用</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.page-title-row { display: flex; align-items: center; gap: 7px; }
|
||
.favorite-page-button { border: 0; background: transparent; color: rgba(255, 255, 255, .7); cursor: pointer; font-size: 19px; line-height: 1; padding: 2px; }
|
||
.favorite-page-button:hover, .favorite-page-button.is-favorite { color: #ffd36a; }
|
||
.favorite-page-button:disabled { cursor: wait; opacity: .55; }
|
||
.favorites-intro { margin: -4px 0 16px; color: #64748b; font-size: 13px; }
|
||
.favorites-editor { display: grid; grid-template-columns: minmax(260px, .85fr) minmax(360px, 1.35fr); gap: 18px; min-height: 390px; }
|
||
.selected-favorites, .available-favorites { border: 1px solid #dfe6ee; border-radius: 12px; padding: 14px; min-width: 0; }
|
||
.selected-favorites > header, .available-favorites > header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
|
||
.selected-favorites > header span, .available-favorites > header span { color: #8492a6; font-size: 12px; }
|
||
.favorites-empty { border: 1px dashed #ccd6e0; border-radius: 9px; color: #8492a6; padding: 28px 14px; text-align: center; }
|
||
.favorite-sort-row { align-items: center; background: #f7f9fc; border: 1px solid transparent; border-radius: 8px; cursor: grab; display: grid; gap: 8px; grid-template-columns: 20px 1fr auto; margin-bottom: 7px; padding: 8px 9px; }
|
||
.favorite-sort-row:hover { border-color: #a8b9d8; }
|
||
.drag-handle { color: #8a99aa; letter-spacing: -3px; }
|
||
.favorite-row-actions { display: flex; gap: 3px; }
|
||
.favorite-row-actions button { background: white; border: 1px solid #d6dee8; border-radius: 5px; cursor: pointer; height: 25px; min-width: 25px; }
|
||
.favorite-row-actions button:disabled { cursor: default; opacity: .35; }
|
||
.favorite-option-group { border-top: 1px solid #edf0f4; padding: 11px 0; }
|
||
.favorite-option-group:first-of-type { border-top: 0; padding-top: 0; }
|
||
.favorite-option-group > strong { color: #526174; display: block; font-size: 12px; margin-bottom: 7px; }
|
||
.favorite-option-group > div { display: flex; flex-wrap: wrap; gap: 6px; }
|
||
.favorite-option { background: #f7f9fc; border: 1px solid #dfe6ee; border-radius: 999px; color: #344054; cursor: pointer; padding: 6px 10px; }
|
||
.favorite-option span { color: #9aa6b2; margin-right: 3px; }
|
||
.favorite-option.is-selected { background: #edf4ff; border-color: #8fb2e8; color: #234b86; }
|
||
.favorite-option.is-selected span { color: #e5a629; }
|
||
.available-favorites { max-height: 520px; overflow-y: auto; }
|
||
@media (max-width: 720px) {
|
||
.favorites-editor { grid-template-columns: 1fr; }
|
||
.available-favorites { max-height: none; }
|
||
}
|
||
</style>
|