| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- <template>
- <div class="home-container">
- <div class="box-1">
- <div class="inner-box left-box">
- <span>{{ platformTitle }}</span>
- <div class="dropdown-box">
- <!-- 下拉菜单 -->
- <el-dropdown v-model="selectedGrade" @command="handleGradeSelect" @visible-change="handleVisibleChange" popper-class="no-arrow-dropdown">
- <el-button type="primary">
- {{ selectedGrade }}
- <!-- 根据下拉框状态显示不同的箭头图标 -->
- <el-icon class="el-icon--right" v-if="!dropdownVisible"><ArrowDownBold /></el-icon>
- <el-icon class="el-icon--right" v-else><ArrowUpBold /></el-icon>
- </el-button>
- <template #dropdown>
- <el-dropdown-menu class="dropdown-menu">
- <el-dropdown-item
- v-for="item in classData"
- :key="item.id"
- :command="item.ctType"
- >{{ item.ctType }}</el-dropdown-item
- >
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- </div>
- </div>
- <div class="inner-box right-box">
- <div class="top-right-box">
- <!-- 动态渲染按钮 -->
- <el-button
- v-for="button in buttonConfigs"
- :key="button.name"
- round
- class="top-right-btn"
- :class="{ 'is-active': selectedButton === button.name }"
- @click="handleButtonClick(button)"
- >{{ button.name }}</el-button
- >
- <!-- 用户名显示 -->
- <UserInfoPopover />
- </div>
- </div>
- </div>
- <div class="box-2">
- <div
- class="left-box-in-box2"
- @click="goToAIGeneralCourse('AI智能课')"
- :style="{ backgroundImage: `url(${indexImages[0]})` }"
- >
- <span>通识课</span>
- </div>
- <div
- class="center-box-in-box2"
- @click="goToAILab()"
- :style="{ backgroundImage: `url(${indexImages[1]})` }"
- >
- <span>AI实验室</span>
- </div>
- <div class="right-box-in-box2">
- <div
- class="top-sub-box"
- :style="{ backgroundImage: `url(${indexImages[2]})` }"
- @click="goToEvaluation"
- >
- <span>能力测评</span>
- </div>
- <div
- class="bottom-sub-box"
- :style="{ backgroundImage: `url(${indexImages[3]})` }"
- @click="goToPersonalized"
- >
- <span>评估报告</span>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, onMounted, watch } from 'vue'
- import { useRouter } from 'vue-router'
- import { ClassList } from '@/api/class.js'
- import {ArrowUpBold, ArrowDownBold} from '@element-plus/icons-vue'
- import { ElMessage } from 'element-plus'
- import UserInfoPopover from '@/components/user/UserInfoPopover.vue'
- // 导入图片
- import intelligenceImg from '@/assets/images/intelligence.png'
- import roomImg from '@/assets/images/room.png'
- import testImg from '@/assets/images/test.png'
- import studyImg from '@/assets/images/study.png'
- // 退出登录图标
- import logoutIcon from '@/assets/icon/logout.png'
- // 退出登录
- import {logoutLogic, removeLocalStorageKey} from '@/utils/loginUtils.js'
- import {aiCourseRoutes, blocklyRoutes, homeRoutes} from "@/router/index.js";
- // 平台标题响应式变量
- const platformTitle = ref(import.meta.env.VITE_APP_TITLE)
- // 更新平台标题
- const updatePlatformTitle = () => {
- platformTitle.value = localStorage.getItem('tenantName') || import.meta.env.VITE_APP_DEFAULT_LOGIN_TENANT
- }
- // 获取当前路由对象
- const router = useRouter()
- // 处理按钮点击事件
- const handleButtonClick = (button) => {
- selectedButton.value = button.name
- router.push(button.route)
- }
- // 按钮配置数组
- const buttonConfigs = ref([
- { name: 'AI编程课', route: blocklyRoutes.home },
- { name: 'AI实验课', route: aiCourseRoutes.home }
- ])
- // 取消默认选中状态
- const selectedButton = ref('')
- // 图片路径
- const indexImages = ref([intelligenceImg, roomImg, testImg, studyImg])
- // 智能课
- const goToAIGeneralCourse = title => {
- router.push({ path: '/ai-general-course', state: { title } })
- }
- //AI实验室
- const goToAILab = () => {
- router.push({
- path: '/ai-laboratory',
- // 跳转页面携带下拉菜单选中项的值
- state: { grade: selectedGrade.value }
- })
- }
- // 能力测评
- const goToEvaluation = () =>{
- router.push({
- path:'/evaluation'
- })
- }
- // 评估报告
- const goToPersonalized = () =>{
- router.push({
- path:'/personalized'
- })
- }
- // 下拉菜单选中项
- const selectedGrade = ref(localStorage.getItem('selectedGrade') || '')
- // 年级ID存储变量
- const selectedGradeId = ref(localStorage.getItem('selectedGradeId') || '')
- // 下拉框可见性状态
- const dropdownVisible = ref(false)
- // 获取年级
- const classData = ref([])
- // 处理下拉框显示/隐藏事件
- const handleVisibleChange = (visible) => {
- dropdownVisible.value = visible
- }
- const fetchCtTypes = async () => {
- try {
- const response = await ClassList()
- if (response.code === 0) {
- classData.value = response.data
- // 获取到数据,将第一个选项的值作为默认选中值
- if (classData.value.length > 0 && !selectedGrade.value) {
- selectedGrade.value = classData.value[0].ctType
- selectedGradeId.value = classData.value[0].id
- localStorage.setItem('selectedGrade', selectedGrade.value)
- localStorage.setItem('selectedGradeId', selectedGradeId.value)
- }
- }
- } catch (error) {
- console.error('获取 ctType 数据失败:', error)
- }
- }
- // 监听 selectedGrade 变化,保存到 localStorage
- watch(selectedGrade, (newValue) => {
- if (newValue) {
- localStorage.setItem('selectedGrade', newValue)
- // 当年级名称变化时,查找对应的ID
- const selectedItem = classData.value.find(item => item.ctType === newValue)
- if (selectedItem) {
- selectedGradeId.value = selectedItem.id
- localStorage.setItem('selectedGradeId', selectedGradeId.value)
- }
- }
- })
- // 监听 selectedGradeId 变化,保存到 localStorage
- watch(selectedGradeId, (newValue) => {
- if (newValue) {
- localStorage.setItem('selectedGradeId', newValue)
- }
- })
- // 处理下拉菜单选择
- const handleGradeSelect = (command) => {
- selectedGrade.value = command
- // 查找对应的ID
- const selectedItem = classData.value.find(item => item.ctType === command)
- if (selectedItem) {
- selectedGradeId.value = selectedItem.id
- }
- }
- onMounted(() => {
- fetchCtTypes()
- // 初始化平台标题
- updatePlatformTitle()
- // storage事件监听器,监听其他标签页对localStorage的修改
- window.addEventListener('storage', (e) => {
- if (e.key === 'tenantName') {
- updatePlatformTitle()
- }
- })
- //删除所有以token开头的键值对
- removeLocalStorageKey(localStorage.getItem("token") + "_ai_")//AI实验室
- removeLocalStorageKey(localStorage.getItem('token') + "_course_")//通识课、实操课
- removeLocalStorageKey(localStorage.getItem("token") + "_blockly_")//编程课
- removeLocalStorageKey(localStorage.getItem("token") + "_aiCourse_")//AI实验课
- })
- // 全局:更新租户名称
- window.updateTenantName = (newName) => {
- localStorage.setItem('tenantName', newName)
- updatePlatformTitle()
- }
- </script>
- <style scoped lang="scss">
- @use 'sass:math';
- // 定义rpx转换函数
- @function rpx($px) {
- @return math.div($px, 750) * 100vw;
- }
- .home-container {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: linear-gradient(to bottom, #001169, #8a78d0);
- display: flex;
- flex-direction: column;
- gap: rpx(0);
- }
- .box-1 {
- width: 100%;
- min-height: rpx(50);
- display: flex;
- justify-content: space-between;
- align-items: center;
- flex-wrap: wrap;
- box-sizing: border-box;
- font-size: rpx(16); // 默认字体大小
- }
- .box-2 {
- width: 90%;
- margin: auto;
- flex: 1;
- display: flex;
- justify-content: space-between;
- align-items: center;
- box-shadow: 0 4px 8px rgba(202, 52, 52, 0.1);
- box-sizing: border-box;
- // padding: 0 rpx(20); // 添加左右内边距
- cursor: pointer; // 添加鼠标指针样式
- }
- .box-2 span {
- // 添加 padding,使文字距上边和左边留有间距
- padding: rpx(10) 0 0 rpx(10);
- font-size: rpx(12); // 默认字体大小
- color: white;
- }
- .left-box-in-box2,
- .center-box-in-box2 {
- background-color: rgba(133, 135, 176, 0.5);
- border-radius: rpx(20);
- flex: 1; // 让三个盒子平均分配空间
- margin: 0 rpx(10); // 添加左右间距
- height: 85%; // 高度占满容器
- display: flex;
- justify-content: flex-start;
- align-items: flex-start;
- background-origin: border-box; // 确保背景图从边框开始显示
- background-clip: padding-box; // 确保背景图不会延伸到边框外
- }
- .left-box-in-box2:hover,
- .left-box-in-box2:active,
- .center-box-in-box2:hover,
- .center-box-in-box2:active {
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
- }
- .left-box-in-box2,
- .center-box-in-box2,
- .top-sub-box,
- .bottom-sub-box {
- background-repeat: no-repeat;
- background-size: cover;
- background-position: center;
- }
- .right-box-in-box2 {
- flex: 1; // 让三个盒子平均分配空间
- margin: 0 rpx(10); // 添加左右间距
- height: 85%; // 高度占满容器
- display: flex;
- // 确保两个子盒子上下排列
- flex-direction: column;
- justify-content: flex-start;
- align-items: flex-start;
- gap: rpx(10);
- }
- .top-sub-box,
- .bottom-sub-box {
- background-color: rgba(133, 135, 176, 0.5);
- flex: 1; // 让两个子盒子平均分配空间;
- display: flex;
- border-radius: rpx(20);
- width: 100%; // 宽度占满容器;
- }
- .top-sub-box:hover,
- .top-sub-box:active,
- .bottom-sub-box:hover,
- .bottom-sub-box:active {
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
- }
- .inner-box {
- height: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: rpx(16); // 默认字体大小
- }
- .left-box {
- position: relative;
- justify-content: flex-start;
- align-items: center;
- display: flex;
- flex: 1;
- padding-left: rpx(30);
- cursor: pointer;
- }
- .left-box span {
- position: static;
- margin-top: 0;
- margin-left: 0;
- margin-right: rpx(10); // 与下拉菜单之间的间距
- font-size: rpx(11);
- color: white;
- max-width: rpx(200); // 最大宽度限制
- white-space: normal; // 允许换行
- line-height: rpx(16); // 行高
- text-align: left;
- }
- .right-box {
- flex: 1;
- display: flex;
- justify-content: flex-end;
- align-items: center;
- margin-right: rpx(60);
- }
- .top-right-box {
- width: 100%;
- display: flex;
- justify-content: flex-end;
- align-items: center;
- flex-wrap: wrap;
- cursor: pointer; // 添加鼠标指针样式
- }
- .top-right-btn {
- width: rpx(50); // 使用 rpx 函数设置按钮宽度
- height: rpx(15); // 使用 rpx 函数设置按钮高度
- margin: rpx(10) rpx(5) 0 0; // 使用 rpx 函数设置外边距
- background-color: transparent;
- color: white;
- border: none; // 移除默认边框
- font-size: rpx(8); // 使用 rpx 函数设置字体大小
- outline: none; // 移除默认的外边框
- }
- .top-right-btn:hover {
- background-color: rgb(255, 255, 255, 0.7);
- border: 1px white solid;
- color: black;
- outline: none;
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
- }
- .dropdown-box {
- align-items: center; // 垂直居中;
- margin-top: 0;
- display: flex;
- }
- .dropdown-box .el-button {
- width: rpx(60); // 设置按钮宽度;
- height: rpx(15); // 设置按钮高度;
- background-color: rgb(255, 255, 255, 0.7);
- border: 1px white solid;
- box-shadow: 0 4px 8px rgb(0, 0, 0, 0.3);
- color: black;
- border-radius: rpx(12);
- font-size: rpx(8); // 设置字体大小;
- }
- .dropdown-box .el-button:hover,
- .dropdown-box .el-button:focus,
- .dropdown-box .el-button:active {
- border: none; /* 移除悬停、聚焦、点击状态下的边框 */
- outline: none; /* 移除悬停、聚焦、点击状态下的轮廓线 el-scrollbar__view el-dropdown__list */
- }
- .dropdown-menu {
- width: rpx(100);
- // height: rpx(60);
- border-radius: rpx(5);
- border: 1px white solid;
- background-color: rgb(255, 255, 255,0.5);
- backdrop-filter: blur(rpx(5));
- box-shadow: 0 4px 8px rgba(202, 52, 52, 0.1);
- margin-left: rpx(40);
- }
- .el-scrollbar__view .el-dropdown__list{
- background-color: transparent;
- }
- .dropdown-menu ::v-deep(.el-dropdown-menu__item) {
- font-size: rpx(8);
- color: black;
- border-radius: rpx(5);
- width: rpx(78);
- height: rpx(20);
- margin-left: rpx(4);
- margin-bottom: rpx(8);
- }
- .dropdown-menu ::v-deep(.el-dropdown-menu__item:hover),
- .dropdown-menu ::v-deep(.el-dropdown-menu__item:focus),
- .dropdown-menu ::v-deep(.el-dropdown-menu__item:active) {
- background: linear-gradient(
- to bottom,
- #fee78a,
- #ffce1b
- );
- box-shadow: 0 4px 8px rgba(202, 52, 52, 0.1);
- }
- </style>
- <style lang="scss">
- /* 只消除非user-name-box的小三角 */
- .no-arrow-dropdown .el-popper__arrow{
- display: none;
- }
- .el-popper.is-light,
- .el-dropdown__popper.el-popper{
- background: transparent;
- border: none;
- box-shadow: none;
- }
- .el-dropdown__popper{
- --el-dropdown-menuItem-hover-color: none;
- }
- /* 移除用户名下拉菜单的焦点边框 */
- .user-name-box:focus,
- .user-name-box:focus-within,
- .user-name-box:hover{
- outline: none;
- box-shadow: none;
- }
- /* 确保Element Plus下拉菜单触发元素没有焦点边框 */
- .el-dropdown .el-dropdown__trigger:focus{
- outline: none;
- box-shadow: none;
- }
- </style>
|