AILaboratory.vue 7.8 KB

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