AILaboratory.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <!-- AI实验室 -->
  3. <div class="home-container">
  4. <!-- 展开收起侧边栏 -->
  5. <div
  6. class="icon-expand"
  7. :style="{
  8. backgroundColor: drawerVisible ? '#44449c' : '#7F70C840',
  9. left: drawerVisible ? '18%' : '0'
  10. }"
  11. @click="toggleDrawer"
  12. >
  13. <span
  14. class="vertical-lines"
  15. :style="{
  16. color: drawerVisible ? '#8a78d0' : 'white'
  17. }"
  18. >||</span
  19. >
  20. </div>
  21. <!-- 侧边栏组件 -->
  22. <LeftPanel ref="leftPanelRef" v-show="drawerVisible" />
  23. <!-- 右侧数字人 -->
  24. <div class="number-people">
  25. <div class="title-box">
  26. <div class="box-icon" @click="goBack">
  27. <el-icon class="left-icon"><ArrowLeftBold /></el-icon>
  28. 返回首页|{{ groupList[2].title }}
  29. </div>
  30. </div>
  31. <!-- 动态渲染数字人 -->
  32. <div class="content-box">
  33. <div
  34. v-for="(person, index) in peopleList"
  35. :key="index"
  36. @click="navigateToAIQuestions(person)"
  37. class="small-box"
  38. >
  39. <div class="people-box">
  40. <img :src="person.image" alt="" />
  41. </div>
  42. <div class="people-title">{{ person.name }}</div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script setup>
  49. import { ref, onMounted } from 'vue'
  50. import { useRouter, useRoute } from 'vue-router'
  51. import {
  52. Document,
  53. Menu as IconMenu,
  54. Setting,
  55. ArrowLeftBold,
  56. Fold,
  57. Expand,
  58. ChatLineRound,
  59. Picture,
  60. MagicStick,
  61. User
  62. } from '@element-plus/icons-vue'
  63. import LeftPanel from '@/components/LeftPanel.vue'
  64. const leftPanelRef = ref(null)
  65. // 数字人接口
  66. import { teacherList } from '@/api/teachers.js'
  67. // 添加抽屉显示状态
  68. const drawerVisible = ref(true)
  69. // 添加切换抽屉显示状态的函数
  70. const toggleDrawer = () => {
  71. drawerVisible.value = !drawerVisible.value
  72. }
  73. const router = useRouter()
  74. const route = useRoute()
  75. // 返回上一页
  76. const goBack = () => {
  77. router.push(homeRoutes.home)
  78. }
  79. // 导入图片
  80. import question from '@/assets/icon/question.png'
  81. import painting from '@/assets/icon/painting.png'
  82. import human from '@/assets/icon/human.png'
  83. import {homeRoutes} from "@/router/index.js";
  84. // 数字人接口
  85. const grade = ref('')
  86. const peopleList = ref([])
  87. onMounted(async () => {
  88. try {
  89. // 使用history.state接收参数,如果没有则从localStorage获取
  90. grade.value = history.state?.grade || localStorage.getItem('selectedGrade')
  91. // 获取小学低年级数据
  92. const juniorRes = await teacherList({ category: grade.value })
  93. peopleList.value = juniorRes.data.list.map(person => ({
  94. id: person.id,
  95. name: person.name,
  96. image: person.model2dPath,
  97. message: person.systemMessage,
  98. default: person.questTip
  99. }))
  100. } catch (error) {
  101. console.error('获取小学低年级数据失败:', error)
  102. }
  103. })
  104. // 跳转页面携带名字和人物形象
  105. const navigateToAIQuestions = person => {
  106. router.push({
  107. path: '/ai-questions',
  108. state: {
  109. ...person,
  110. from: 'ai-laboratory',
  111. category: grade.value
  112. }
  113. })
  114. }
  115. const groupList = ref([
  116. {
  117. icon: question,
  118. title: '智能问答'
  119. },
  120. {
  121. icon: painting,
  122. title: '智能绘画'
  123. },
  124. {
  125. icon: human,
  126. title: '数字人老师'
  127. }
  128. ])
  129. </script>
  130. <style scoped lang="scss">
  131. @use 'sass:math';
  132. // 定义rpx转换函数
  133. @function rpx($px) {
  134. @return math.div($px, 750) * 100vw;
  135. }
  136. /* 添加过渡样式 */
  137. .drawer-slide-enter-active,
  138. .drawer-slide-leave-active {
  139. transition: all 0.3s ease;
  140. }
  141. .drawer-slide-enter-from,
  142. .drawer-slide-leave-to {
  143. transform: translateX(-100%);
  144. opacity: 0;
  145. transition: all 0.3s ease;
  146. }
  147. .home-container {
  148. position: fixed;
  149. top: 0;
  150. left: 0;
  151. right: 0;
  152. bottom: 0;
  153. display: flex;
  154. flex-direction: row;
  155. gap: rpx(0);
  156. background: linear-gradient(to bottom, #e2ddfc, #f1effd);
  157. }
  158. .icon-expand {
  159. width: rpx(8);
  160. height: rpx(35);
  161. border-top-right-radius: rpx(5);
  162. border-bottom-right-radius: rpx(5);
  163. z-index: 9999;
  164. position: absolute;
  165. top: 50%;
  166. left: 18%;
  167. transform: translateY(-50%);
  168. background-color: #44449c;
  169. cursor: pointer; // 添加鼠标指针样式
  170. clip-path: polygon(0 0, 100% 15%, 100% 85%, 0 100%);
  171. display: flex;
  172. justify-content: center;
  173. align-items: center;
  174. transition: all 0.3s ease;
  175. }
  176. .icon-expand .vertical-lines {
  177. color: #8a78d0;
  178. font-size: rpx(10);
  179. }
  180. .menu-icon {
  181. width: rpx(11);
  182. height: rpx(11);
  183. margin-right: rpx(2);
  184. }
  185. // 侧边栏
  186. .left-group {
  187. width: rpx(135);
  188. height: 100%;
  189. background: linear-gradient(to bottom, #001169, #8a78d0);
  190. }
  191. .mb-2 {
  192. color: black;
  193. margin-top: rpx(1);
  194. }
  195. .tac ::v-deep(.el-menu) {
  196. background-color: transparent;
  197. border: none;
  198. width: 100%;
  199. margin-top: rpx(55);
  200. margin-left: rpx(10);
  201. }
  202. .el-menu-item {
  203. width: rpx(115);
  204. height: rpx(25);
  205. margin-bottom: rpx(5);
  206. border-radius: rpx(6);
  207. color: white;
  208. font-size: rpx(8);
  209. }
  210. .el-menu-item .el-icon svg {
  211. font-size: rpx(15);
  212. color: white;
  213. }
  214. .el-menu ::v-deep(.el-menu-item:hover) {
  215. background: linear-gradient(to bottom, #ffefb0, #ffcc00);
  216. box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
  217. color: black;
  218. font-size: rpx(8);
  219. }
  220. .el-menu-vertical-demo .el-menu-item.is-active {
  221. background: linear-gradient(to bottom, #ffefb0, #ffcc00);
  222. box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
  223. color: black;
  224. font-size: rpx(8);
  225. }
  226. .el-menu .el-menu-item.is-active {
  227. background: linear-gradient(to bottom, #fee78a, #ffce1b);
  228. color: black;
  229. font-size: rpx(8);
  230. box-shadow: 0 4px 8px rgba(3, 3, 3, 0.3);
  231. }
  232. // 右侧数字人内容
  233. .number-people {
  234. flex: 1;
  235. height: 100%;
  236. display: flex;
  237. flex-direction: column;
  238. background: linear-gradient(to bottom, #e2ddfc, #f1effd);
  239. }
  240. // 标题样式
  241. .title-box {
  242. height: rpx(35);
  243. }
  244. .box-icon {
  245. width: 100%;
  246. height: 100%;
  247. flex: 1;
  248. display: flex; // 添加 flex 布局
  249. align-items: center; // 垂直居中
  250. color: black; // 设置图标颜色为白色
  251. padding-left: rpx(15);
  252. font-size: rpx(10); // 设置图标大小,可按需调整
  253. cursor: pointer; // 添加鼠标指针样式
  254. }
  255. // .box-icon .left-icon {
  256. // margin-left: rpx(10);
  257. // margin-right: rpx(5); // 设置图标和文字之间的间距 ;
  258. // }
  259. // 内容样式
  260. .content-box {
  261. // width: 100%;
  262. box-sizing: border-box;
  263. cursor: pointer; // 鼠标指针样式
  264. flex: 1;
  265. display: flex;
  266. flex-wrap: wrap;
  267. overflow-y: auto;
  268. // justify-content: center;
  269. }
  270. .content-box::-webkit-scrollbar {
  271. width: rpx(2);
  272. }
  273. .content-box::-webkit-scrollbar-track {
  274. background: transparent; // 设置滚动条轨道背景
  275. border-radius: rpx(3); // 设置滚动条轨道圆角
  276. }
  277. .content-box::-webkit-scrollbar-thumb {
  278. background: linear-gradient(to bottom, hsl(230, 100%, 21%), #8a78d0);
  279. border-radius: rpx(3); // 设置滚动条滑块圆角
  280. }
  281. .content-box::-webkit-scrollbar-thumb:hover {
  282. background: linear-gradient(to bottom, hsl(230, 100%, 21%), #8a78d0);
  283. }
  284. .small-box {
  285. flex: 0 0 calc(30% - rpx(10)); // 每个小盒子占三分之一宽度,减去间距
  286. // width: rpx(180);
  287. height: rpx(110);
  288. margin-top: rpx(30);
  289. margin-left: rpx(25);
  290. border-radius: rpx(6);
  291. border: 1px solid white;
  292. background: rgba($color: #ffffff, $alpha: 0.5);
  293. position: relative;
  294. cursor: pointer; // 鼠标指针样式
  295. display: flex; // 此行,启用flex布局
  296. flex-direction: column; // 此行,垂直排列子元素
  297. align-items: center;
  298. }
  299. .people-box {
  300. position: absolute;
  301. top: rpx(-30);
  302. overflow: hidden;
  303. width: rpx(180);
  304. height: rpx(140);
  305. border-radius: rpx(6);
  306. margin-bottom: rpx(5);
  307. // background-color: pink;
  308. display: flex;
  309. justify-content: center;
  310. align-items: center;
  311. }
  312. .people-box img {
  313. width: rpx(100);
  314. margin-top: rpx(75);
  315. // margin-left: rpx(50) auto;
  316. transition: transform 0.3s ease; // 过渡效果
  317. }
  318. .people-box img:hover {
  319. transform: scale(1.1); // 鼠标经过时放大1.1倍
  320. }
  321. .people-title {
  322. font-size: rpx(8);
  323. margin-top: rpx(110);
  324. }
  325. .small-box span {
  326. color: black;
  327. font-size: rpx(8);
  328. }
  329. </style>