244 lines
5.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="admin-dashboard">
<!-- 顶部图片 -->
<div class="top-image-container">
<img src="https://picsum.photos/500/200" alt="顶部图片" class="top-image">
</div>
<div class="main-content">
<!-- 侧边栏 -->
<div class="sidebar-container">
<!-- 头像 -->
<div class="avatar-container">
<img src="https://picsum.photos/200/200" alt="头像" class="avatar">
<div class="avatar-text">
用户昵称~
</div>
</div>
<!-- 导航栏 -->
<div class="nav-container">
<router-link to="/teacher/course-management" class="nav-item" :class="{ active: activeNavItem === 0 }" @click="setActiveNavItem(0)">
<img src="/images/teacher/路径 1.png" alt="">
<span>课程管理</span>
</router-link>
<router-link to="/teacher/student-management" class="nav-item" :class="{ active: activeNavItem === 1 }" @click="setActiveNavItem(1)">
<img src="https://picsum.photos/200/200" alt="">
<span>学员管理</span>
</router-link>
<router-link to="/teacher/my-resources" class="nav-item" :class="{ active: activeNavItem === 2 }" @click="setActiveNavItem(2)">
<img src="https://picsum.photos/200/200" alt="">
<span>我的资源</span>
</router-link>
<router-link to="/teacher/personal-center" class="nav-item" :class="{ active: activeNavItem === 3 }" @click="setActiveNavItem(3)">
<img src="https://picsum.photos/200/200" alt="">
<span>个人中心</span>
</router-link>
</div>
</div>
<!-- 右侧路由视图 -->
<div class="router-view-container">
<!-- 面包屑 -->
<div class="breadcrumb">
<span class="breadcrumb-separator">|</span>
<n-breadcrumb>
<n-breadcrumb-item v-for="(item, index) in breadcrumbItems" :key="index" :to="item.path">
{{ item.title }}
</n-breadcrumb-item>
</n-breadcrumb>
</div>
<router-view></router-view>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, computed, watch } from 'vue'
import { useRoute } from 'vue-router'
const width = window.innerWidth;
const height = window.innerHeight;
console.log(`当前屏幕宽度: ${width}px, 高度: ${height}px`);
// 添加导航项激活状态管理
const activeNavItem = ref(0);
const route = useRoute();
const setActiveNavItem = (index: number) => {
activeNavItem.value = index;
}
// 动态生成面包屑
const breadcrumbItems = computed(() => {
// 获取当前路由的matched数组
const matchedRoutes = route.matched;
// 处理matchedRoutes过滤掉'管理后台'并生成面包屑项
return matchedRoutes
.filter(item => item.meta.title !== '管理后台')
.map(item => ({
title: item.meta.title || '未知页面',
path: item.path
}));
});
// 监听路由变化,更新激活的导航项
onMounted(() => {
// 初始设置
updateActiveNavItem();
});
// 使用watch监听路由变化
watch(route, () => {
updateActiveNavItem();
});
// 更新激活的导航项
const updateActiveNavItem = () => {
const path = route.path;
if (path.includes('course-management')) {
activeNavItem.value = 0;
} else if (path.includes('student-management')) {
activeNavItem.value = 1;
} else if (path.includes('my-resources')) {
activeNavItem.value = 2;
} else if (path.includes('personal-center')) {
activeNavItem.value = 3;
}
}
</script>
<style scoped>
.top-image-container {
position: relative;
width: 100%;
height: 130px;
overflow: hidden;
}
.top-image {
width: 1920px;
height: 130px;
position: absolute;
left: 0px;
top: 70px;
opacity: 100%;
object-fit: cover;
}
.main-content {
display: flex;
}
.sidebar-container{
width: 294px;
height: calc(100vh - 130px);
background: #FFFFFF;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.avatar-container{
height: 230px;
position: relative;
/* 移除原来的边框 */
}
/* 添加带间距的横线 */
.avatar-container::after {
content: '';
position: absolute;
bottom: 0;
left: 20px;
right: 20px;
height: 1px;
background-color: #E6E6E6;
}
.avatar-container img{
width: 95px;
height: 95px;
/* 圆角 */
border-radius: 50%;
margin-top: 55px;
margin-left: 100px;
margin-right: 99;
}
.avatar-text{
margin-left: 98px;
height: 31px;
font-family: AppleSystemUIFont;
font-size: 22px;
color: #000000;
line-height: 26px;
text-align: left;
font-style: normal;
text-transform: none;
}
.nav-container{
margin-top: 30px;
/* 鼠标变小手 */
cursor: pointer;
}
.nav-container .nav-item{
margin-left: 20px;
width: 254px;
height: 54px;
margin-bottom: 20px;
/* 圆角 */
border-radius: 10px;
display: flex;
align-items: center;
transition: all 0.3s ease;
}
.nav-container .nav-item:hover {
background: rgba(102,183,227,0.05);
}
/* 添加激活状态样式 */
.nav-container .nav-item.active{
background: rgba(102,183,227,0.1);
}
.nav-container .nav-item img{
width: 17px;
height: 20px;
margin-left: 50px;
margin-top: 0;
margin-right: 5px;
}
.nav-container .nav-item span{
width: 80px;
height: 28px;
font-family: AppleSystemUIFont;
font-size: 20px;
color: #0C99DA;
line-height: 23px;
text-align: left;
font-style: normal;
text-transform: none;
}
.router-view-container {
flex: 1;
padding: 20px;
background: #F5F7FA;
height: calc(100vh - 130px);
overflow-y: auto;
}
.breadcrumb {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.breadcrumb-separator {
margin-right: 10px;
color: #0C99DA;
font-size: 16px;
}
</style>