Przeglądaj źródła

侧边栏接口逻辑

丸子 9 miesięcy temu
rodzic
commit
9d120fafed

+ 1 - 1
src/api/teachers.js

@@ -7,4 +7,4 @@ export function teacherList (data) {
     method: 'get',
     data
   })
-}
+}

+ 185 - 0
src/components/LeftPanel.vue

@@ -0,0 +1,185 @@
+<template>
+  <!-- 左侧折叠面板 -->
+  <transition name="drawer-slide">
+    <div class="left-group" >
+      <el-row class="tac">
+        <el-col :span="12">
+          <el-menu
+            default-active="2"
+            class="el-menu-vertical-demo"
+            @open="handleOpen"
+            @close="handleClose"
+          >
+            <el-menu-item
+              v-for="(item, index) in groupList"
+              :key="index"
+              @click="navigateToAI(item)"
+            >
+              <img :src="item.icon" alt="" class="menu-icon" />
+              {{ item.title }}
+            </el-menu-item>
+          </el-menu>
+        </el-col>
+      </el-row>
+    </div>
+  </transition>
+</template>
+
+<script setup>
+import { ref,onMounted } from 'vue'
+import { useRouter,useRoute } from 'vue-router'
+
+// 导入图片
+import question from '@/assets/icon/question.png'
+import painting from '@/assets/icon/painting.png'
+import human from '@/assets/icon/human.png'
+
+import { teacherList } from '@/api/teachers.js'
+
+
+const router = useRouter()
+const route = useRoute()
+
+// 添加抽屉显示状态
+const drawerVisible = ref(true)
+// 渲染侧边栏
+const groupList = ref([
+  {
+    icon: question,
+    title: '智能问答'
+  },
+  {
+    icon: painting,
+    title: '智能绘画'
+  },
+  {
+    icon: human,
+    title: '数字人老师'
+  }
+])
+
+
+
+// 存储小智数据
+const personData = ref([])
+// 跳转智能问答
+const navigateToAI = async (group) => {
+  if (group.title === '智能问答') {
+    try {
+       const grade = route.query.grade || localStorage.getItem('selectedGrade')
+       console.log(grade);
+      // 获取小学低年级AI数据
+      const juniorAIRes = await teacherList({ category: grade + 'AI' })
+      console.log(juniorAIRes);
+      const aiPerson = juniorAIRes.data.list.find(person => person.name === '小智')
+      if (aiPerson) {
+        personData.value = {
+          id: aiPerson.id,
+          name: aiPerson.name,
+          image: aiPerson.model2dPath,
+          message: aiPerson.systemMessage
+        }
+        console.log(personData.value);
+        router.push({
+          path: '/ai-questions',
+          query: personData.value
+        })
+      } else {
+        console.warn('未找到名为小智的数据');
+      }
+    } catch (error) {
+      console.error('获取小学低年级AI数据失败:', error)
+    }
+  }
+  if (group.title === '智能绘画') {
+    router.push('/ai-painting')
+  }
+  if (group.title === '数字人老师') {
+    router.push('/ai-laboratory')
+  }
+}
+
+
+// 处理菜单展开和关闭
+const handleOpen = () => {}
+const handleClose = () => {}
+
+// 导出状态和方法供父组件使用
+defineExpose({
+  drawerVisible,
+  toggleDrawer: () => {
+    drawerVisible.value = !drawerVisible.value
+  }
+})
+</script>
+
+<style scoped lang="scss">
+@use 'sass:math';
+// 定义rpx转换函数
+@function rpx($px) {
+  @return math.div($px, 750) * 100vw;
+}
+/* 添加过渡样式 */
+.drawer-slide-enter-active,
+.drawer-slide-leave-active {
+  transition: all 0.3s ease;
+}
+.drawer-slide-enter-from,
+.drawer-slide-leave-to {
+  transform: translateX(-100%);
+}
+
+// 侧边栏
+.left-group {
+  width: rpx(135);
+  height: 100%;
+  background: linear-gradient(to bottom, #001169, #8a78d0);
+}
+.mb-2 {
+  color: black;
+  margin-top: rpx(1);
+}
+.tac ::v-deep(.el-menu) {
+  background-color: transparent;
+  border: none;
+  width: 100%;
+  margin-top: rpx(55);
+  margin-left: rpx(10);
+}
+.el-menu-item {
+  width: rpx(115);
+  height: rpx(25);
+  margin-bottom: rpx(5);
+  border-radius: rpx(6);
+  color: white;
+  font-size: rpx(8);
+}
+.el-menu-item .el-icon svg {
+  font-size: rpx(15);
+  color: white;
+}
+.el-menu ::v-deep(.el-menu-item:hover) {
+  background: linear-gradient(to bottom, #ffefb0, #ffcc00);
+  box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
+  color: black;
+  font-size: rpx(8);
+}
+.el-menu-vertical-demo .el-menu-item.is-active {
+  background: linear-gradient(to bottom, #ffefb0, #ffcc00);
+  box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
+  color: black;
+  font-size: rpx(8);
+}
+.el-menu .el-menu-item.is-active {
+  background: linear-gradient(to bottom, #fee78a, #ffce1b);
+  color: black;
+  font-size: rpx(8);
+  box-shadow: 0 4px 8px rgba(3, 3, 3, 0.3);
+}
+.menu-icon {
+  width: rpx(11);
+  height: rpx(11);
+  margin-right: rpx(2);
+}
+
+</style>

+ 10 - 67
src/views/AILaboratory.vue

@@ -19,30 +19,8 @@
       >
     </div>
 
-    <!-- 左侧折叠面板 -->
-    <transition name="drawer-slide">
-      <div class="left-group" v-if="drawerVisible">
-        <el-row class="tac">
-          <el-col :span="12">
-            <el-menu
-              default-active="2"
-              class="el-menu-vertical-demo"
-              @open="handleOpen"
-              @close="handleClose"
-            >
-              <el-menu-item
-                v-for="(item, index) in groupList"
-                :key="index"
-                @click="navigateToAI(item)"
-              >
-                <img :src="item.icon" alt="" class="menu-icon" />
-                {{ item.title }}
-              </el-menu-item>
-            </el-menu>
-          </el-col>
-        </el-row>
-      </div>
-    </transition>
+    <!-- 侧边栏组件 -->
+      <LeftPanel ref="leftPanelRef" v-if="drawerVisible"/>
 
     <!-- 右侧数字人 -->
     <div class="number-people">
@@ -87,6 +65,9 @@ import {
   User
 } from '@element-plus/icons-vue'
 
+import LeftPanel from '@/components/LeftPanel.vue'
+const leftPanelRef = ref(null)
+
 // 数字人接口
 import { teacherList } from '@/api/teachers.js'
 
@@ -111,13 +92,13 @@ import human from '@/assets/icon/human.png'
 
 // 数字人接口
 const peopleList = ref([])
-
 onMounted(async () => {
   try {
-     const grade = route.query.grade || '小学低年级'
+     const grade = route.query.grade || localStorage.getItem('selectedGrade')
      console.log(grade);
     // 获取小学低年级数据
-    const juniorRes = await teacherList({ category: grade })
+    const juniorRes = await teacherList({ category:  grade })
+    console.log(juniorRes);
     peopleList.value = juniorRes.data.list.map(person => ({
       id: person.id,
       name: person.name,
@@ -137,44 +118,6 @@ const navigateToAIQuestions = (person) => {
   })
 }
 
-// 存储 id 为 10 的小智数据
-const personId10 = ref([])
-// 跳转智能问答
-const navigateToAI = async (group) => {
-  if (group.title === '智能问答') {
-    try {
-       const grade = route.query.grade || '小学低年级AI'
-     console.log(grade);
-      // 获取小学低年级AI数据
-      const juniorAIRes = await teacherList({ category: grade })
-      const aiPerson = juniorAIRes.data.list.find(person => person.id === 10)
-      if (aiPerson) {
-        personId10.value = {
-          id: aiPerson.id,
-          name: aiPerson.name,
-          image: aiPerson.model2dPath,
-          message: aiPerson.systemMessage
-        }
-        router.push({
-          path: '/ai-questions',
-          query: personId10.value
-        })
-      } else {
-        console.warn('未找到 ID 为 10 的数据');
-      }
-    } catch (error) {
-      console.error('获取小学低年级AI数据失败:', error)
-    }
-  }
-  if (group.title === '智能绘画') {
-    router.push('/ai-painting')
-  }
-  if (group.title === '数字人老师') {
-    router.push('/ai-laboratory')
-  }
-}
-
-// 渲染侧边栏
 const groupList = ref([
   {
     icon: question,
@@ -343,10 +286,10 @@ const groupList = ref([
 }
 .people-box {
   position: absolute;
-  top: rpx(-30);
+  top: rpx(-20);
   overflow: hidden;
   width: rpx(180);
-  height: rpx(140);
+  height: rpx(130);
   border-radius: rpx(6);
   margin-bottom: rpx(5);
   // background-color: pink;

+ 4 - 23
src/views/AIPainting.vue

@@ -21,29 +21,7 @@
     </div>
 
     <!-- 左侧折叠面板 -->
-    <transition name="drawer-slide">
-      <div class="left-group1" v-if="drawerVisible">
-        <el-row class="tac">
-          <el-col :span="12">
-            <el-menu
-              default-active="2"
-              class="el-menu-vertical-demo"
-              @open="handleOpen"
-              @close="handleClose"
-            >
-              <el-menu-item
-                v-for="(item, index) in groupList"
-                :key="index"
-                @click="navigateToAI(item)"
-              >
-                <img :src="item.icon" alt="" class="menu-icon" />
-                {{ item.title }}
-              </el-menu-item>
-            </el-menu>
-          </el-col>
-        </el-row>
-      </div>
-    </transition>
+    <LeftPanel ref="leftPanelRef" v-if="drawerVisible"/>
 
     <div class="left-group2">
       <div class="title-box">
@@ -213,6 +191,9 @@ import question from '@/assets/icon/question.png'
 import painting from '@/assets/icon/painting.png'
 import human from '@/assets/icon/human.png'
 
+import LeftPanel from '@/components/LeftPanel.vue'
+const leftPanelRef = ref(null)
+
 // 添加抽屉显示状态
 const drawerVisible = ref(true)
 // 添加切换抽屉显示状态的函数

+ 9 - 69
src/views/AIQuestions.vue

@@ -1,8 +1,8 @@
 <template>
   <!-- 数字人智能问答 -->
   <div class="home-container">
-    <!-- 展开收起侧边栏 -->
-    <div
+     <!-- 展开收起侧边栏 -->
+  <div
       class="icon-expand"
       :style="{
         backgroundColor: drawerVisible ? '#44449c' : '#7F70C840',
@@ -20,29 +20,7 @@
     </div>
 
     <!-- 左侧折叠面板 -->
-    <transition name="drawer-slide">
-      <div class="left-group" v-if="drawerVisible">
-        <el-row class="tac">
-          <el-col :span="12">
-            <el-menu
-              default-active="1-1"
-              class="el-menu-vertical-demo"
-              @open="handleOpen"
-              @close="handleClose"
-            >
-              <el-menu-item
-                v-for="(item, index) in groupList"
-                :key="index"
-                @click="navigateToAI(item)"
-              >
-               <img :src="item.icon" alt="" class="menu-icon" />
-                {{ item.title }}
-              </el-menu-item>
-            </el-menu>
-          </el-col>
-        </el-row>
-      </div>
-    </transition>
+    <LeftPanel ref="leftPanelRef"  v-if="drawerVisible"/>
 
     <!-- 原左侧折叠面板和右侧AI问答 -->
     <div class="content-wrapper">
@@ -119,56 +97,18 @@ import question from '@/assets/icon/question.png'
 import painting from '@/assets/icon/painting.png'
 import human from '@/assets/icon/human.png'
 
+import LeftPanel from '@/components/LeftPanel.vue'
+const leftPanelRef = ref(null)
+
+
 // 添加抽屉显示状态
 const drawerVisible = ref(true)
 // 添加切换抽屉显示状态的函数
 const toggleDrawer = () => {
   drawerVisible.value = !drawerVisible.value
 }
-// 渲染侧边栏
-const groupList = ref([
-  {
-    icon: question,
-    title: '智能问答'
-  },
-  {
-    icon: painting,
-    title: '智能绘画'
-  },
-  {
-    icon: human,
-    title: '数字人老师'
-  }
-])
-// 跳转智能问答
-const navigateToAI = group => {
-  if (group.title === '智能问答') {
-    let person = {
-      id: 10,
-      name: '小智',
-      image: '@/assets/images/xiaozhi.png',
-      message:
-        '您好,我是您的AI智能助手小智,我会尽力回答您的问题或提供有用的建议!!!!'
-    }
-    router.push({
-      // 跳转问答页面
-      path: '/ai-questions',
-      query: {
-        id: person.id,
-        name: person.name,
-        image: person.image,
-        message: person.message
-      }
-    })
-    
-  }
-  if (group.title === '智能绘画') {
-    router.push('/ai-painting')
-  }
-  if (group.title === '数字人老师') {
-    router.push('/ai-laboratory') // 添加跳转到AI实验室的逻辑
-  }
-}
+
+
 // 处理菜单展开和关闭
 const handleOpen = () => {}
 const handleClose = () => {}