HomePage.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <div class="home-container">
  3. <div class="box-1">
  4. <div class="inner-box left-box">
  5. <span>京华实验学校</span>
  6. <div class="dropdown-box">
  7. <!-- 下拉菜单 -->
  8. <el-dropdown v-model="selectedGrade" @command="handleGradeSelect" popper-class="no-arrow-dropdown">
  9. <el-button type="primary">
  10. {{ selectedGrade }}
  11. <el-icon class="el-icon--right"><ArrowDown /></el-icon>
  12. </el-button>
  13. <template #dropdown>
  14. <el-dropdown-menu class="dropdown-menu">
  15. <el-dropdown-item
  16. v-for="item in classData"
  17. :key="item.id"
  18. :command="item.ctType"
  19. >{{ item.ctType }}</el-dropdown-item
  20. >
  21. </el-dropdown-menu>
  22. </template>
  23. </el-dropdown>
  24. </div>
  25. </div>
  26. <div class="inner-box right-box">
  27. <div class="top-right-box">
  28. <el-button
  29. round
  30. class="top-right-btn"
  31. :class="{ 'is-active': selectedButton === 'AI通识课' }"
  32. @click="selectedButton = 'AI通识课'"
  33. >AI通识课</el-button
  34. >
  35. <el-button
  36. round
  37. class="top-right-btn"
  38. :class="{ 'is-active': selectedButton === 'AI写作课' }"
  39. @click="
  40. ;(selectedButton = 'AI通识课'),
  41. Message().notifyWarning('演示版未开放此功能!!', true)
  42. "
  43. >AI写作课</el-button
  44. >
  45. <el-button
  46. round
  47. class="top-right-btn"
  48. :class="{ 'is-active': selectedButton === 'AI艺术课' }"
  49. @click="
  50. ;(selectedButton = 'AI通识课'),
  51. Message().notifyWarning('演示版未开放此功能!', true)
  52. "
  53. >AI艺术课</el-button
  54. >
  55. <!-- 退出登录 -->
  56. <!-- <div class="logout-box"> -->
  57. <el-button round class="logout-box-btn" @click="LogoutClick()">
  58. <img :src="logoutIcon" alt="Logout" />
  59. 退出登录
  60. </el-button>
  61. <!-- </div> -->
  62. </div>
  63. </div>
  64. </div>
  65. <div class="box-2">
  66. <div
  67. class="left-box-in-box2"
  68. @click="goToAIGeneralCourse('AI智能课')"
  69. :style="{ backgroundImage: `url(${indexImages[0]})` }"
  70. >
  71. <span>智能课</span>
  72. </div>
  73. <div
  74. class="center-box-in-box2"
  75. @click="goToAILab()"
  76. :style="{ backgroundImage: `url(${indexImages[1]})` }"
  77. >
  78. <span>AI实验室</span>
  79. </div>
  80. <div class="right-box-in-box2">
  81. <!-- @click="goToEvaluation" -->
  82. <div
  83. class="top-sub-box"
  84. :style="{ backgroundImage: `url(${indexImages[2]})` }"
  85. @click="goToEvaluation"
  86. >
  87. <span>能力测评</span>
  88. </div>
  89. <div
  90. class="bottom-sub-box"
  91. :style="{ backgroundImage: `url(${indexImages[3]})` }"
  92. @click="goToPersonalized"
  93. >
  94. <span>评估报告</span>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. </template>
  100. <script setup>
  101. import { ref, onMounted, watch } from 'vue'
  102. import { useRouter } from 'vue-router'
  103. import { ClassList } from '@/api/class.js'
  104. import { ArrowDown, ArrowRightBold } from '@element-plus/icons-vue'
  105. import { Search, ArrowLeftBold } from '@element-plus/icons-vue'
  106. // 导入图片
  107. import intelligenceImg from '@/assets/images/intelligence.png'
  108. import roomImg from '@/assets/images/room.png'
  109. import testImg from '@/assets/images/test.png'
  110. import studyImg from '@/assets/images/study.png'
  111. // 退出登录图标
  112. import logoutIcon from '@/assets/icon/logout.png'
  113. import { Message } from '@/utils/message/Message.js'
  114. // 获取当前路由对象
  115. const router = useRouter()
  116. // 退出登录
  117. const LogoutClick = () => {
  118. // 清空 token 和登录状态
  119. localStorage.removeItem('token')
  120. localStorage.removeItem('isLoggedIn')
  121. localStorage.removeItem('maxCourseSections')
  122. router.push({ path: '/login' })
  123. }
  124. // 默认选中 AI 通识课
  125. const selectedButton = ref('AI通识课')
  126. // 添加图片路径
  127. const indexImages = ref([intelligenceImg, roomImg, testImg, studyImg])
  128. // AI初体验
  129. const goToAIGeneralCourse = title => {
  130. router.push({ path: '/ai-general-course', query: { title } })
  131. }
  132. //AI实验室
  133. const goToAILab = () => {
  134. router.push({
  135. path: '/ai-laboratory',
  136. // 跳转页面携带下拉菜单选中项的值
  137. query: { grade: selectedGrade.value }
  138. })
  139. }
  140. // 能力测评
  141. const goToEvaluation = () =>{
  142. router.push({
  143. path:'/evaluation'
  144. })
  145. }
  146. // 评估报告
  147. const goToPersonalized = () =>{
  148. router.push({
  149. path:'/personalized'
  150. })
  151. }
  152. // 添加下拉菜单选中项
  153. const selectedGrade = ref(localStorage.getItem('selectedGrade') || '')
  154. // 添加年级ID存储变量
  155. const selectedGradeId = ref(localStorage.getItem('selectedGradeId') || '')
  156. // 获取年级
  157. const classData = ref([])
  158. const fetchCtTypes = async () => {
  159. try {
  160. const response = await ClassList()
  161. console.log(response);
  162. if (response.code === 0) {
  163. classData.value = response.data
  164. // 获取到数据,将第一个选项的值作为默认选中值
  165. if (classData.value.length > 0 && !selectedGrade.value) {
  166. selectedGrade.value = classData.value[0].ctType
  167. selectedGradeId.value = classData.value[0].id
  168. localStorage.setItem('selectedGrade', selectedGrade.value)
  169. localStorage.setItem('selectedGradeId', selectedGradeId.value)
  170. }
  171. }
  172. } catch (error) {
  173. console.error('获取 ctType 数据失败:', error)
  174. }
  175. }
  176. // 监听 selectedGrade 变化,保存到 localStorage
  177. watch(selectedGrade, (newValue) => {
  178. if (newValue) {
  179. localStorage.setItem('selectedGrade', newValue)
  180. // 当年级名称变化时,查找对应的ID
  181. const selectedItem = classData.value.find(item => item.ctType === newValue)
  182. if (selectedItem) {
  183. selectedGradeId.value = selectedItem.id
  184. localStorage.setItem('selectedGradeId', selectedGradeId.value)
  185. }
  186. }
  187. })
  188. // 监听 selectedGradeId 变化,保存到 localStorage
  189. watch(selectedGradeId, (newValue) => {
  190. if (newValue) {
  191. localStorage.setItem('selectedGradeId', newValue)
  192. }
  193. })
  194. // 处理下拉菜单选择
  195. const handleGradeSelect = (command) => {
  196. selectedGrade.value = command
  197. // 查找对应的ID
  198. const selectedItem = classData.value.find(item => item.ctType === command)
  199. if (selectedItem) {
  200. selectedGradeId.value = selectedItem.id
  201. }
  202. }
  203. //AI实验室
  204. const notOpen = () => {
  205. Message().notifyWarning(
  206. localStorage.getItem('userName') === 'aiTest'
  207. ? '您的账号并未开放此功能!'
  208. : '演示版未开放此功能!',
  209. true
  210. )
  211. }
  212. onMounted(() => {
  213. fetchCtTypes()
  214. })
  215. </script>
  216. <style scoped lang="scss">
  217. @use 'sass:math';
  218. // 定义rpx转换函数
  219. @function rpx($px) {
  220. @return math.div($px, 750) * 100vw;
  221. }
  222. .logout-box {
  223. width: rpx(100);
  224. position: fixed;
  225. }
  226. .logout-box-btn {
  227. width: rpx(65); // 使用 rpx 函数设置按钮宽度
  228. height: rpx(15); // 使用 rpx 函数设置按钮高度
  229. margin: rpx(10) rpx(10) 0 0; // 使用 rpx 函数设置外边距
  230. background-color: transparent;
  231. color: white;
  232. border: none; // 移除默认边框
  233. font-size: rpx(7); // 使用 rpx 函数设置字体大小
  234. outline: none; // 移除默认的外边框
  235. }
  236. .logout-box-btn img {
  237. width: rpx(10);
  238. }
  239. .home-container {
  240. position: fixed;
  241. top: 0;
  242. left: 0;
  243. right: 0;
  244. bottom: 0;
  245. background: linear-gradient(to bottom, #001169, #8a78d0);
  246. display: flex;
  247. flex-direction: column;
  248. gap: rpx(0);
  249. }
  250. .box-1 {
  251. width: 100%;
  252. height: rpx(50);
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. box-sizing: border-box;
  257. font-size: rpx(16); // 默认字体大小
  258. }
  259. .box-2 {
  260. width: 90%;
  261. margin: auto;
  262. flex: 1;
  263. display: flex;
  264. justify-content: space-between;
  265. align-items: center;
  266. box-shadow: 0 4px 8px rgba(202, 52, 52, 0.1);
  267. box-sizing: border-box;
  268. // padding: 0 rpx(20); // 添加左右内边距
  269. cursor: pointer; // 添加鼠标指针样式
  270. }
  271. .box-2 span {
  272. // 添加 padding,使文字距上边和左边留有间距
  273. padding: rpx(10) 0 0 rpx(10);
  274. font-size: rpx(12); // 默认字体大小
  275. color: white;
  276. }
  277. .left-box-in-box2,
  278. .center-box-in-box2 {
  279. background-color: rgba(133, 135, 176, 0.5);
  280. border-radius: rpx(20);
  281. flex: 1; // 让三个盒子平均分配空间
  282. margin: 0 rpx(10); // 添加左右间距
  283. height: 85%; // 高度占满容器
  284. display: flex;
  285. justify-content: flex-start;
  286. align-items: flex-start;
  287. }
  288. .left-box-in-box2:hover,
  289. .left-box-in-box2:active,
  290. .center-box-in-box2:hover,
  291. .center-box-in-box2:active {
  292. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  293. }
  294. .left-box-in-box2,
  295. .center-box-in-box2,
  296. .top-sub-box,
  297. .bottom-sub-box {
  298. background-repeat: no-repeat;
  299. background-size: cover;
  300. background-position: center;
  301. }
  302. .right-box-in-box2 {
  303. flex: 1; // 让三个盒子平均分配空间
  304. margin: 0 rpx(10); // 添加左右间距
  305. height: 85%; // 高度占满容器
  306. display: flex;
  307. // 确保两个子盒子上下排列
  308. flex-direction: column;
  309. justify-content: flex-start;
  310. align-items: flex-start;
  311. gap: rpx(10);
  312. }
  313. .top-sub-box,
  314. .bottom-sub-box {
  315. background-color: rgba(133, 135, 176, 0.5);
  316. flex: 1; // 让两个子盒子平均分配空间;
  317. display: flex;
  318. border-radius: rpx(20);
  319. width: 100%; // 宽度占满容器;
  320. }
  321. .top-sub-box:hover,
  322. .top-sub-box:active,
  323. .bottom-sub-box:hover,
  324. .bottom-sub-box:active {
  325. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  326. }
  327. .inner-box {
  328. height: 100%;
  329. display: flex;
  330. justify-content: center;
  331. align-items: center;
  332. font-size: rpx(16); // 默认字体大小
  333. }
  334. .left-box {
  335. position: relative;
  336. justify-content: space-between;
  337. align-items: flex-start;
  338. flex: 1; // 设置左侧盒子占比为 2
  339. // background-color: #fff;
  340. }
  341. .left-box span {
  342. position: absolute;
  343. margin-top: rpx(20); // 调整上边距离
  344. margin-left: rpx(25);
  345. font-size: rpx(11); // 默认字体大小
  346. color: white;
  347. }
  348. .right-box {
  349. flex: 1;
  350. position: relative; // 添加相对定位;
  351. margin-right: rpx(25);
  352. }
  353. .top-right-box {
  354. position: absolute; // 添加绝对定位
  355. width: 100%; // 设置盒子宽度,可按需调整
  356. height: 60px; // 设置盒子高度,可按需调整
  357. display: flex;
  358. justify-content: flex-end;
  359. cursor: pointer; // 添加鼠标指针样式
  360. }
  361. .top-right-btn {
  362. width: rpx(50); // 使用 rpx 函数设置按钮宽度
  363. height: rpx(15); // 使用 rpx 函数设置按钮高度
  364. margin: rpx(10) rpx(5) 0 0; // 使用 rpx 函数设置外边距
  365. background-color: transparent;
  366. color: white;
  367. border: none; // 移除默认边框
  368. font-size: rpx(8); // 使用 rpx 函数设置字体大小
  369. outline: none; // 移除默认的外边框
  370. }
  371. .top-right-btn.is-active,
  372. .top-right-btn:active,
  373. .top-right-btn:focus {
  374. background-color: rgb(255, 255, 255, 0.7);
  375. border: 1px white solid;
  376. color: black;
  377. outline: none; // 移除点击时的外边框
  378. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  379. }
  380. .dropdown-box {
  381. width: 100%;
  382. height: 100%;
  383. margin-left: rpx(-80);
  384. flex: 1;
  385. align-items: center; // 垂直居中;
  386. margin-top: rpx(22);
  387. }
  388. .dropdown-box .el-button {
  389. width: rpx(60); // 设置按钮宽度;
  390. height: rpx(15); // 设置按钮高度;
  391. background-color: rgb(255, 255, 255, 0.7);
  392. border: 1px white solid;
  393. box-shadow: 0 4px 8px rgb(0, 0, 0, 0.3);
  394. color: black;
  395. border-radius: rpx(12);
  396. font-size: rpx(8); // 设置字体大小;
  397. }
  398. .dropdown-box .el-button:hover,
  399. .dropdown-box .el-button:focus,
  400. .dropdown-box .el-button:active {
  401. border: none; /* 移除悬停、聚焦、点击状态下的边框 */
  402. outline: none; /* 移除悬停、聚焦、点击状态下的轮廓线 el-scrollbar__view el-dropdown__list */
  403. }
  404. .dropdown-menu {
  405. width: rpx(100);
  406. // height: rpx(60);
  407. border-radius: rpx(5);
  408. border: 1px white solid;
  409. background-color: rgb(255, 255, 255,0.5);
  410. backdrop-filter: blur(rpx(5));
  411. box-shadow: 0 4px 8px rgba(202, 52, 52, 0.1);
  412. margin-left: rpx(40);
  413. }
  414. .el-scrollbar__view .el-dropdown__list{
  415. background-color: transparent;
  416. }
  417. .dropdown-menu ::v-deep(.el-dropdown-menu__item) {
  418. font-size: rpx(8);
  419. color: black;
  420. border-radius: rpx(5);
  421. width: rpx(78);
  422. height: rpx(20);
  423. margin-left: rpx(4);
  424. margin-bottom: rpx(8);
  425. }
  426. .dropdown-menu ::v-deep(.el-dropdown-menu__item:hover),
  427. .dropdown-menu ::v-deep(.el-dropdown-menu__item:focus),
  428. .dropdown-menu ::v-deep(.el-dropdown-menu__item:active) {
  429. background: linear-gradient(
  430. to bottom,
  431. #fee78a,
  432. #ffce1b
  433. );
  434. box-shadow: 0 4px 8px rgba(202, 52, 52, 0.1);
  435. }
  436. </style>
  437. <style lang="scss">
  438. /* 消除小三角 */
  439. .el-popper__arrow{
  440. display: none;
  441. }
  442. .el-popper.is-light,
  443. .el-dropdown__popper.el-popper{
  444. background: transparent;
  445. border: none;
  446. box-shadow: none;
  447. }
  448. .el-dropdown__popper{
  449. --el-dropdown-menuItem-hover-color: none;
  450. }
  451. </style>