HomePage.vue 12 KB

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