LeftPanel.vue 6.5 KB

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