LeftPanel.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <!-- 左侧折叠面板 -->
  3. <transition name="drawer-slide">
  4. <div class="left-group">
  5. <el-row class="tac">
  6. <el-col :span="12">
  7. <el-menu
  8. :default-active="currentActiveIndex"
  9. class="el-menu-vertical-demo"
  10. @open="handleOpen"
  11. @close="handleClose"
  12. >
  13. <el-menu-item
  14. v-for="(item, index) in groupList"
  15. :key="index"
  16. :index="index.toString()"
  17. @click="navigateToAI(item)"
  18. v-model="currentActiveIndex"
  19. @mouseover="item.isHover = true"
  20. @mouseout="item.isHover = false"
  21. >
  22. <!-- 根据状态切换图片-->
  23. <img
  24. :src="currentActiveIndex === index.toString() || item.isHover ? item.hoverIcon : item.icon"
  25. alt=""
  26. class="menu-icon"
  27. />
  28. {{ item.title }}
  29. </el-menu-item>
  30. </el-menu>
  31. </el-col>
  32. </el-row>
  33. </div>
  34. </transition>
  35. </template>
  36. <script setup>
  37. import { ref, onMounted,watch} from 'vue'
  38. import { useRouter, useRoute } from 'vue-router'
  39. import { teacherList } from '@/api/teachers.js'
  40. // 导入图片 白色
  41. import question from '@/assets/icon/question.png'
  42. import painting from '@/assets/icon/painting.png'
  43. import Human from '@/assets/icon/human.png'
  44. import image2image from '@/assets/icon/image2image.png'
  45. import video from '@/assets/icon/video.png'
  46. import labImage from '@/assets/icon/labImage.png'
  47. import en from '@/assets/icon/en.png'
  48. import blockly from '@/assets/icon/blockly.png'
  49. // 黑色
  50. import question02 from '@/assets/icon/question02.png'
  51. import painting02 from '@/assets/icon/painting02.png'
  52. import Human02 from '@/assets/icon/Human02.png'
  53. import image2image02 from '@/assets/icon/image2image02.png'
  54. import video02 from '@/assets/icon/video02.png'
  55. import labImage02 from '@/assets/icon/labImage02.png'
  56. import en02 from '@/assets/icon/en02.png'
  57. import blockly02 from '@/assets/icon/blockly02.png'
  58. const router = useRouter()
  59. const route = useRoute()
  60. // 添加抽屉显示状态
  61. const drawerVisible = ref(true)
  62. // 当前选中索引状态
  63. const currentActiveIndex = ref('2')
  64. // 渲染侧边栏
  65. const groupList = ref([
  66. {
  67. icon: question, // 默认图片
  68. hoverIcon: question02, // 交互图片
  69. title: '智能问答'
  70. },
  71. {
  72. icon: painting,
  73. hoverIcon: painting02,
  74. title: '智能绘画'
  75. },
  76. {
  77. icon: Human,
  78. hoverIcon: Human02,
  79. title: '数字人老师'
  80. },
  81. {
  82. icon: en,
  83. hoverIcon: en02,
  84. title: '英文数字人老师'
  85. },
  86. {
  87. icon: image2image,
  88. hoverIcon: image2image02,
  89. title: '图生图'
  90. },
  91. {
  92. icon: video,
  93. hoverIcon: video02,
  94. title: '图生视频'
  95. },
  96. {
  97. icon: labImage,
  98. hoverIcon: labImage02,
  99. title: '虚拟实验室'
  100. },
  101. {
  102. icon: blockly,
  103. hoverIcon: blockly02,
  104. title: 'blockly游戏'
  105. },
  106. ])
  107. // 提取更新选中状态的逻辑为单独函数
  108. // 优化后的更新选中状态的方法
  109. const updateActiveIndex = () => {
  110. const path = route.path;
  111. const from = route.query.from;
  112. // 使用映射表存储路径和索引的对应关系
  113. const pathIndexMap = {
  114. 'ai-questions': '0', // 智能问答
  115. 'ai-painting': '1', // 智能绘画
  116. 'ai-laboratory': '2', // 数字人老师
  117. 'ai-ennumerals': '3', // 英文数字人老师
  118. 'ai-image': '4' , // 图生图
  119. 'ai-video': '5' , // 图生视频
  120. 'virtual-laboratory':"6",// 虚拟实验室
  121. 'gamepage':"7"// 虚拟实验室
  122. };
  123. // 从数字人老师页面进入智能问答页面
  124. if (path.includes('ai-questions') && from === 'ai-laboratory') {
  125. currentActiveIndex.value = '2'; // 保持选中数字人老师
  126. return;
  127. }
  128. // 从英文数字人老师页面进入智能问答页面
  129. if (path.includes('ai-questions') && from === 'ai-ennumerals') {
  130. currentActiveIndex.value = '3'; // 保持选中英文数字人老师
  131. return;
  132. }
  133. // 查找路径对应的索引
  134. for (const [key, index] of Object.entries(pathIndexMap)) {
  135. if (path.includes(key)) {
  136. currentActiveIndex.value = index;
  137. return;
  138. }
  139. }
  140. };
  141. // 组件挂载时确保默认选中状态
  142. onMounted(() => {
  143. updateActiveIndex();
  144. });
  145. // 添加路由变化监听,更新选中状态
  146. watch(() => route, () => {
  147. updateActiveIndex();
  148. }, { immediate: true, deep: true });
  149. // 存储小智数据
  150. const personData = ref([])
  151. // 跳转智能问答
  152. const navigateToAI = async (group) => {
  153. if (group.title === '智能问答') {
  154. try {
  155. const grade = route.query.grade || localStorage.getItem('selectedGrade')
  156. // 获取小学低年级AI数据
  157. const juniorAIRes = await teacherList({ category: grade + 'AI' })
  158. const aiPerson = juniorAIRes.data.list.find(
  159. person => person.name === '小智'
  160. )
  161. if (aiPerson) {
  162. personData.value = {
  163. id: aiPerson.id,
  164. name: aiPerson.name,
  165. image: aiPerson.model2dPath,
  166. message: aiPerson.systemMessage,
  167. default: aiPerson.questTip
  168. }
  169. console.log(personData.value)
  170. router
  171. .push({
  172. path: '/ai-questions',
  173. query: {
  174. ...personData.value,
  175. category: grade + 'AI'
  176. }
  177. })
  178. } else {
  179. console.warn('未找到名为小智的数据')
  180. }
  181. } catch (error) {
  182. console.error('获取小学低年级AI数据失败:', error)
  183. }
  184. }
  185. if (group.title === '智能绘画') {
  186. router.push('/ai-painting')
  187. }
  188. if (group.title === '数字人老师') {
  189. router.push('/ai-laboratory')
  190. }
  191. if (group.title === '英文数字人老师') {
  192. router.push('/ai-ennumerals')
  193. }
  194. if (group.title === '图生图') {
  195. router.push('/ai-image')
  196. }
  197. if (group.title === '图生视频') {
  198. router.push('/ai-video')
  199. }
  200. if (group.title === '虚拟实验室') {
  201. router.push('/virtual-laboratory')
  202. }
  203. if (group.title === 'blockly游戏') {
  204. router.push('/gamepage')
  205. }
  206. }
  207. // 处理菜单展开和关闭
  208. const handleOpen = () => {}
  209. const handleClose = () => {}
  210. // 导出状态和方法供父组件使用
  211. defineExpose({
  212. drawerVisible,
  213. toggleDrawer: () => {
  214. drawerVisible.value = !drawerVisible.value
  215. }
  216. })
  217. </script>
  218. <style scoped lang="scss">
  219. @use 'sass:math';
  220. // 定义rpx转换函数
  221. @function rpx($px) {
  222. @return math.div($px, 750) * 100vw;
  223. }
  224. /* 添加过渡样式 */
  225. ::v-deep .drawer-slide-enter-active,
  226. ::v-deep .drawer-slide-leave-active {
  227. transition: all 0.3s ease;
  228. }
  229. ::v-deep .drawer-slide-enter-from,
  230. ::v-deep .drawer-slide-leave-to {
  231. transform: translateX(-100%);
  232. opacity: 0;
  233. }
  234. // 侧边栏
  235. .left-group {
  236. width: rpx(135);
  237. height: 100%;
  238. background: linear-gradient(to bottom, #001169, #8a78d0);
  239. }
  240. .mb-2 {
  241. color: black;
  242. margin-top: rpx(1);
  243. }
  244. .tac ::v-deep(.el-menu) {
  245. background-color: transparent;
  246. border: none;
  247. width: 100%;
  248. margin-top: rpx(55);
  249. margin-left: rpx(10);
  250. }
  251. .el-menu-item {
  252. width: rpx(115);
  253. height: rpx(25);
  254. margin-bottom: rpx(5);
  255. border-radius: rpx(6);
  256. color: white;
  257. font-size: rpx(8);
  258. }
  259. .el-menu-item .el-icon svg {
  260. font-size: rpx(15);
  261. color: white;
  262. }
  263. .el-menu .el-menu-item:hover {
  264. background: linear-gradient(to bottom, #ffefb0, #ffcc00);
  265. box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
  266. color: black;
  267. font-size: rpx(8);
  268. }
  269. :deep(.el-menu .el-menu-item.is-active) {
  270. background: linear-gradient(to bottom, #fee78a, #ffce1b);
  271. color: black;
  272. font-size: rpx(8);
  273. box-shadow: 0 4px 8px rgba(3, 3, 3, 0.3);
  274. }
  275. .menu-icon {
  276. width: rpx(11);
  277. height: rpx(11);
  278. margin-right: rpx(2);
  279. }
  280. </style>