Browse Source

侧边栏定位

丸子 2 months ago
parent
commit
e8245b75d2

+ 22 - 11
package-lock.json

@@ -135,6 +135,7 @@
       "resolved": "https://registry.npmmirror.com/@babel/core/-/core-7.28.0.tgz",
       "integrity": "sha512-UlLAnTPrFdNGoFtbSXwcGFQBtQZJCNjaN6hQNP3UPvuNXT1i82N26KL3dZeIpNalWywr9IuQuncaAfUaS1g6sQ==",
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "@ampproject/remapping": "^2.2.0",
         "@babel/code-frame": "^7.27.1",
@@ -1629,6 +1630,7 @@
         }
       ],
       "license": "MIT",
+      "peer": true,
       "engines": {
         "node": ">=18"
       },
@@ -1652,6 +1654,7 @@
         }
       ],
       "license": "MIT",
+      "peer": true,
       "engines": {
         "node": ">=18"
       }
@@ -2424,7 +2427,6 @@
       "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.10.tgz",
       "integrity": "sha512-0pPkgz9dY+bijgistcTTJ5mR+ocqRXLuhXHYdzoMmmoJ2C9S46RCm2GMUbatPEUK9Yjy26IrAy8D/M00lLkv+Q==",
       "license": "MIT",
-      "peer": true,
       "dependencies": {
         "@jridgewell/gen-mapping": "^0.3.5",
         "@jridgewell/trace-mapping": "^0.3.25"
@@ -3066,6 +3068,7 @@
       "resolved": "https://registry.npmmirror.com/@types/lodash-es/-/lodash-es-4.17.12.tgz",
       "integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "@types/lodash": "*"
       }
@@ -3094,6 +3097,7 @@
       "integrity": "sha512-ENHwaH+JIRTDIEEbDK6QSQntAYGtbvdDXnMXnZaZ6k13Du1dPMmprkEHIL7ok2Wl2aZevetwTAb5S+7yIF+enA==",
       "devOptional": true,
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "undici-types": "~7.8.0"
       }
@@ -3435,6 +3439,7 @@
       "resolved": "https://registry.npmmirror.com/acorn/-/acorn-8.15.0.tgz",
       "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
       "license": "MIT",
+      "peer": true,
       "bin": {
         "acorn": "bin/acorn"
       },
@@ -3707,6 +3712,7 @@
         }
       ],
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "caniuse-lite": "^1.0.30001726",
         "electron-to-chromium": "^1.5.173",
@@ -3742,8 +3748,7 @@
       "version": "1.1.2",
       "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
       "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
-      "license": "MIT",
-      "peer": true
+      "license": "MIT"
     },
     "node_modules/call-bind-apply-helpers": {
       "version": "1.0.2",
@@ -3958,8 +3963,7 @@
       "version": "2.20.3",
       "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
       "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
-      "license": "MIT",
-      "peer": true
+      "license": "MIT"
     },
     "node_modules/concat-map": {
       "version": "0.0.1",
@@ -4395,6 +4399,7 @@
       "integrity": "sha512-LSehfdpgMeWcTZkWZVIJl+tkZ2nuSkyyB9C27MZqFWXuph7DvaowgcTvKqxvpLW1JZIk8PN7hFY3Rj9LQ7m7lg==",
       "dev": true,
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "@eslint-community/eslint-utils": "^4.2.0",
         "@eslint-community/regexpp": "^4.12.1",
@@ -5092,6 +5097,7 @@
       "resolved": "https://registry.npmjs.org/ink/-/ink-6.6.0.tgz",
       "integrity": "sha512-QDt6FgJxgmSxAelcOvOHUvFxbIUjVpCH5bx+Slvc5m7IEcpGt3dYwbz/L+oRnqEGeRvwy1tineKK4ect3nW1vQ==",
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "@alcalzone/ansi-tokenize": "^0.2.1",
         "ansi-escapes": "^7.2.0",
@@ -5644,13 +5650,15 @@
       "version": "4.17.21",
       "resolved": "https://registry.npmmirror.com/lodash/-/lodash-4.17.21.tgz",
       "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
-      "license": "MIT"
+      "license": "MIT",
+      "peer": true
     },
     "node_modules/lodash-es": {
       "version": "4.17.21",
       "resolved": "https://registry.npmmirror.com/lodash-es/-/lodash-es-4.17.21.tgz",
       "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
-      "license": "MIT"
+      "license": "MIT",
+      "peer": true
     },
     "node_modules/lodash-unified": {
       "version": "1.0.3",
@@ -6204,6 +6212,7 @@
       "resolved": "https://registry.npmmirror.com/picomatch/-/picomatch-4.0.2.tgz",
       "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
       "license": "MIT",
+      "peer": true,
       "engines": {
         "node": ">=12"
       },
@@ -6325,6 +6334,7 @@
       "resolved": "https://registry.npmjs.org/react/-/react-19.2.1.tgz",
       "integrity": "sha512-DGrYcCWK7tvYMnWh79yrPHt+vdx9tY+1gPZa7nJQtO/p8bLTDaHp4dzwEhQB7pZ4Xe3ok4XKuEPrVuc+wlpkmw==",
       "license": "MIT",
+      "peer": true,
       "engines": {
         "node": ">=0.10.0"
       }
@@ -6585,6 +6595,7 @@
       "integrity": "sha512-xCmtksBKd/jdJ9Bt9p7nPKiuqrlBMBuuGkQlkhZjjQk3Ty48lv93k5Dq6OPkKt4XwxDJ7tvlfrTa1MPA9bf+QA==",
       "devOptional": true,
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "chokidar": "^4.0.0",
         "immutable": "^5.0.2",
@@ -6690,7 +6701,6 @@
       "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
       "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
       "license": "BSD-3-Clause",
-      "peer": true,
       "engines": {
         "node": ">=0.10.0"
       }
@@ -6709,7 +6719,6 @@
       "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
       "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
       "license": "MIT",
-      "peer": true,
       "dependencies": {
         "buffer-from": "^1.0.0",
         "source-map": "^0.6.0"
@@ -7110,6 +7119,7 @@
       "resolved": "https://registry.npmjs.org/video.js/-/video.js-7.21.5.tgz",
       "integrity": "sha512-WRq86tXZKrThA9mK+IR+v4tIQVVvnb5LhvL71fD2AX7TxVOPdaeK1X/wyuUruBqWaOG3w2sZXoMY6HF2Jlo9qA==",
       "license": "Apache-2.0",
+      "peer": true,
       "dependencies": {
         "@babel/runtime": "^7.12.5",
         "@videojs/http-streaming": "2.16.2",
@@ -7349,6 +7359,7 @@
       "resolved": "https://registry.npmmirror.com/vite/-/vite-7.0.0.tgz",
       "integrity": "sha512-ixXJB1YRgDIw2OszKQS9WxGHKwLdCsbQNkpJN171udl6szi/rIySHL6/Os3s2+oE4P/FLD4dxg4mD7Wust+u5g==",
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "esbuild": "^0.25.0",
         "fdir": "^6.4.6",
@@ -7423,6 +7434,7 @@
       "resolved": "https://registry.npmmirror.com/vue/-/vue-3.5.17.tgz",
       "integrity": "sha512-LbHV3xPN9BeljML+Xctq4lbz2lVHCR6DtbpTf5XIO6gugpXUN49j2QQPcMj086r9+AkJ0FfUT8xjulKKBkkr9g==",
       "license": "MIT",
+      "peer": true,
       "dependencies": {
         "@vue/compiler-dom": "3.5.17",
         "@vue/compiler-sfc": "3.5.17",
@@ -7445,6 +7457,7 @@
       "integrity": "sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==",
       "hasInstallScript": true,
       "license": "MIT",
+      "peer": true,
       "bin": {
         "vue-demi-fix": "bin/vue-demi-fix.js",
         "vue-demi-switch": "bin/vue-demi-switch.js"
@@ -7471,7 +7484,6 @@
       "integrity": "sha512-CydUvFOQKD928UzZhTp4pr2vWz1L+H99t7Pkln2QSPdvmURT0MoC4wUccfCnuEaihNsu9aYYyk+bep8rlfkUXw==",
       "dev": true,
       "license": "MIT",
-      "peer": true,
       "dependencies": {
         "debug": "^4.4.0",
         "eslint-scope": "^8.2.0",
@@ -7496,7 +7508,6 @@
       "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",
       "dev": true,
       "license": "ISC",
-      "peer": true,
       "bin": {
         "semver": "bin/semver.js"
       },

+ 1 - 1
src/views/AIPage/AIDevelop.vue

@@ -341,7 +341,7 @@ const toggleDrawer = () => {
 
 // 返回上一页
 const goBack = () => {
-  router.go(-1)
+  router.push('/ai-general-course')
 }
 
 // 菜单打开和关闭的处理函数

+ 48 - 6
src/views/AIPage/AIGeneralCourse.vue

@@ -29,8 +29,8 @@
             <el-row class="tac">
               <el-col :span="12">
                 <el-menu
-                  default-active="general-1"
-                  :default-openeds="['general']"
+                  :default-active="currentActiveIndex"
+                  :default-openeds="[currentOpenedMenu]"
                   :class="{ 'el-menu-vertical-demo': true }"
                   unique-opened
                 >
@@ -39,7 +39,7 @@
                     v-for="menu in menuList" 
                     :key="menu.id"
                     :index="menu.id"
-                    @click="showPracticalCourse = menu.isPractical; showAICourse = menu.isAICourse"
+                    @click="showPracticalCourse = menu.isPractical; showAICourse = menu.isAICourse; currentOpenedMenu = menu.id"
                   >
                     <template #title>
                       <span>{{ menu.title }}</span>
@@ -181,6 +181,13 @@ const aiGeneratedCourseData = ref([])
 const showPracticalCourse = ref(false)
 // 状态变量,跟踪当前显示的是实操课还是AI生成课
 const showAICourse = ref(false)
+// 当前选中的菜单索引
+const currentActiveIndex = ref('general-1')
+// 当前打开的菜单
+const currentOpenedMenu = ref('general')
+// 存储选中状态的键名
+const activeMenuKey = 'aiGeneralCourseActiveMenu'
+const activeIndexKey = 'aiGeneralCourseActiveIndex'
 
 // 菜单列表计算属性
 const menuList = computed(() => [
@@ -216,6 +223,12 @@ const processCourseData = (data) => {
   })
 }
 
+// 保存当前选中状态
+const saveActiveState = (menuId, index) => {
+  localStorage.setItem(activeMenuKey, menuId)
+  localStorage.setItem(activeIndexKey, index)
+}
+
 // 统一函数来获取课程大纲数据 通识课/实操课/AI生成课
 const fetchClassOutline = async (classId) => {
   try {
@@ -312,13 +325,23 @@ const getCourseTitle = index => {
 const pageTitle = ref('返回首页')
 onMounted(() => {
   fetchCtTypes()
+  // 读取之前保存的选中状态
+  const savedMenu = localStorage.getItem(activeMenuKey)
+  const savedIndex = localStorage.getItem(activeIndexKey)
+  
+  if (savedMenu && savedIndex) {
+    currentOpenedMenu.value = savedMenu
+    currentActiveIndex.value = savedIndex
+    
+    // 根据保存的菜单类型设置对应的显示状态
+    showPracticalCourse.value = savedMenu === 'practical'
+    showAICourse.value = savedMenu === 'ai'
+  }
+  
   // const title = history.state?.title
   // if (title) {
   //   pageTitle.value = title
   // }
-  // 默认显示智能课,不读取localStorage中的状态
-  showPracticalCourse.value = false
-  showAICourse.value = false
 })
 
 
@@ -375,6 +398,25 @@ const goBack = () => {
 }
 
 const goToAIExperience = outlineData => {
+  // 确定当前课程所属的菜单类型
+  let menuId = 'general'
+  if (showPracticalCourse.value) {
+    menuId = 'practical'
+  } else if (showAICourse.value) {
+    menuId = 'ai'
+  }
+  
+  // 找到当前课程在对应菜单中的索引
+  const currentData = showPracticalCourse.value ? practicalCourseData.value : 
+                     showAICourse.value ? aiGeneratedCourseData.value : classOutlineData.value
+  const index = currentData.findIndex(item => item.id === outlineData.id)
+  
+  if (index !== -1) {
+    const menuIndex = menuId + '-' + (index + 1)
+    // 保存选中状态
+    saveActiveState(menuId, menuIndex)
+  }
+  
   // 课程跳转逻辑
   router.push({
     path: '/ai-develop', // 跳转视频页面

+ 1 - 1
src/views/AIPage/aiGenerate/DialogContent.vue

@@ -437,7 +437,7 @@ const playNext = () => {
 const goBackToMain = () => {
   // 停止所有音频
   stopAllAudio()
-  // 跳转到 ai-general-course 页面
+  // 跳转到 ai-general-course 页面,保持侧边栏选中状态
   router.push('/ai-general-course')
 }