PoetryHome.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <div class="home-container">
  3. <div class="box-1">
  4. <div class="inner-box left-box">
  5. <div class="box-icon" @click="goToManagementInterface">
  6. <div class="app-header">
  7. <img :src="LogoImage" alt="Logo" class="app-logo" />
  8. <el-icon class="left-icon"><HomeFilled /></el-icon>
  9. <span>{{ platformTitle }}</span>
  10. </div>
  11. </div>
  12. <div class="dropdown-box">
  13. <el-dropdown v-model="selectedGrade" @command="handleGradeSelect" @visible-change="handleVisibleChange" popper-class="no-arrow-dropdown">
  14. <el-button type="primary">
  15. {{ selectedGrade }}
  16. <el-icon class="el-icon--right" v-if="!dropdownVisible"><ArrowDownBold /></el-icon>
  17. <el-icon class="el-icon--right" v-else><ArrowUpBold /></el-icon>
  18. </el-button>
  19. <template #dropdown>
  20. <el-dropdown-menu class="dropdown-menu">
  21. <el-dropdown-item
  22. v-for="item in classData"
  23. :key="item.id"
  24. :command="item.ctType"
  25. >{{ item.ctType }}</el-dropdown-item
  26. >
  27. </el-dropdown-menu>
  28. </template>
  29. </el-dropdown>
  30. </div>
  31. </div>
  32. <div class="inner-box right-box">
  33. <div class="top-right-box">
  34. <el-button
  35. v-for="button in buttonConfigs"
  36. :key="button.name"
  37. round
  38. class="top-right-btn"
  39. :class="{ 'is-active': selectedButton === button.name }"
  40. @click="handleButtonClick(button)"
  41. >{{ button.name }}</el-button
  42. >
  43. <UserInfoPopover />
  44. </div>
  45. </div>
  46. </div>
  47. <div class="box-2">
  48. <div
  49. class="left-box-in-box2"
  50. @click="goToAIPoetryCourse"
  51. :style="{ backgroundImage: `url(${indexImages[0]})` }"
  52. >
  53. <span style="background-color: #77b7db78;
  54. margin: 20px;
  55. padding: 10px;
  56. border-radius: 27px;">
  57. AI诗词课
  58. </span>
  59. </div>
  60. <div
  61. class="center-box-in-box2"
  62. @click="goToAILab()"
  63. :style="{ backgroundImage: `url(${indexImages[1]})` }"
  64. >
  65. <span>AI实验室</span>
  66. </div>
  67. <div class="right-box-in-box2">
  68. <div
  69. class="top-sub-box"
  70. :style="{ backgroundImage: `url(${indexImages[2]})` }"
  71. @click="goToEvaluation"
  72. >
  73. <span>能力测评</span>
  74. </div>
  75. <div
  76. class="bottom-sub-box"
  77. :style="{ backgroundImage: `url(${indexImages[3]})` }"
  78. @click="goToPersonalized"
  79. >
  80. <span>评估报告</span>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </template>
  86. <script setup>
  87. import { ref, onMounted, watch } from 'vue'
  88. import { useRouter } from 'vue-router'
  89. import { ClassList } from '@/api/class.js'
  90. import {ArrowUpBold, ArrowDownBold, HomeFilled} from '@element-plus/icons-vue'
  91. import UserInfoPopover from '@/components/user/UserInfoPopover.vue'
  92. import LogoImage from '@/assets/images/logo.png'
  93. import poetryImg from '@/assets/aiPoetry/poetry.png'
  94. import roomImg from '@/assets/images/room.png'
  95. import testImg from '@/assets/images/test.png'
  96. import studyImg from '@/assets/images/study.png'
  97. import {logoutLogic, removeLocalStorageKey} from '@/utils/loginUtils.js'
  98. import {aiCourseRoutes, blocklyRoutes, homeRoutes, aiPoetryRoutes} from "@/router/index.js";
  99. const platformTitle = ref(import.meta.env.VITE_APP_TITLE)
  100. const updatePlatformTitle = () => {
  101. platformTitle.value = localStorage.getItem('tenantName') || import.meta.env.VITE_APP_DEFAULT_LOGIN_TENANT
  102. }
  103. const router = useRouter()
  104. const handleButtonClick = (button) => {
  105. selectedButton.value = button.name
  106. router.push(button.route)
  107. }
  108. const buttonConfigs = ref([
  109. // { name: 'AI编程课', route: blocklyRoutes.home },
  110. ])
  111. const selectedButton = ref('')
  112. const indexImages = ref([poetryImg, roomImg, testImg, studyImg])
  113. const goToAIPoetryCourse = () => {
  114. router.push('/ai-poetry-course')
  115. }
  116. const goToManagementInterface = () => {
  117. router.push('/management-interface')
  118. }
  119. const goToAILab = () => {
  120. router.push({
  121. path: '/ai-laboratory',
  122. state: { grade: selectedGrade.value }
  123. })
  124. }
  125. const goToEvaluation = () =>{
  126. router.push({
  127. path:'/evaluation'
  128. })
  129. }
  130. const goToPersonalized = () =>{
  131. router.push({
  132. path:'/personalized'
  133. })
  134. }
  135. const selectedGrade = ref(localStorage.getItem('selectedGrade') || '')
  136. const selectedGradeId = ref(localStorage.getItem('selectedGradeId') || '')
  137. const dropdownVisible = ref(false)
  138. const classData = ref([])
  139. const handleVisibleChange = (visible) => {
  140. dropdownVisible.value = visible
  141. }
  142. const fetchCtTypes = async () => {
  143. try {
  144. const response = await ClassList()
  145. if (response.code === 0) {
  146. classData.value = response.data
  147. if (classData.value.length > 0 && !selectedGrade.value) {
  148. selectedGrade.value = classData.value[0].ctType
  149. selectedGradeId.value = classData.value[0].id
  150. localStorage.setItem('selectedGrade', selectedGrade.value)
  151. localStorage.setItem('selectedGradeId', selectedGradeId.value)
  152. }
  153. }
  154. } catch (error) {
  155. console.error('获取 ctType 数据失败:', error)
  156. }
  157. }
  158. watch(selectedGrade, (newValue) => {
  159. if (newValue) {
  160. localStorage.setItem('selectedGrade', newValue)
  161. const selectedItem = classData.value.find(item => item.ctType === newValue)
  162. if (selectedItem) {
  163. selectedGradeId.value = selectedItem.id
  164. localStorage.setItem('selectedGradeId', selectedGradeId.value)
  165. }
  166. }
  167. })
  168. watch(selectedGradeId, (newValue) => {
  169. if (newValue) {
  170. localStorage.setItem('selectedGradeId', newValue)
  171. }
  172. })
  173. const handleGradeSelect = (command) => {
  174. selectedGrade.value = command
  175. const selectedItem = classData.value.find(item => item.ctType === command)
  176. if (selectedItem) {
  177. selectedGradeId.value = selectedItem.id
  178. }
  179. }
  180. onMounted(() => {
  181. fetchCtTypes()
  182. updatePlatformTitle()
  183. window.addEventListener('storage', (e) => {
  184. if (e.key === 'tenantName') {
  185. updatePlatformTitle()
  186. }
  187. })
  188. removeLocalStorageKey(localStorage.getItem("token") + "_ai_")
  189. removeLocalStorageKey(localStorage.getItem('token') + "_course_")
  190. removeLocalStorageKey(localStorage.getItem("token") + "_blockly_")
  191. removeLocalStorageKey(localStorage.getItem("token") + "_aiCourse_")
  192. })
  193. window.updateTenantName = (newName) => {
  194. localStorage.setItem('tenantName', newName)
  195. updatePlatformTitle()
  196. }
  197. </script>
  198. <style scoped lang="scss">
  199. @use 'sass:math';
  200. @function rpx($px) {
  201. @return math.div($px, 750) * 100vw;
  202. }
  203. .home-container {
  204. position: fixed;
  205. top: 0;
  206. left: 0;
  207. right: 0;
  208. bottom: 0;
  209. background: linear-gradient(to bottom, #001169, #8a78d0);
  210. display: flex;
  211. flex-direction: column;
  212. gap: rpx(0);
  213. }
  214. .box-1 {
  215. width: 100%;
  216. min-height: rpx(50);
  217. display: flex;
  218. justify-content: space-between;
  219. align-items: center;
  220. flex-wrap: wrap;
  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-sizing: border-box;
  232. cursor: pointer;
  233. }
  234. .box-2 span {
  235. padding: rpx(10) 0 0 rpx(10);
  236. font-size: rpx(12);
  237. color: white;
  238. }
  239. .left-box-in-box2,
  240. .center-box-in-box2 {
  241. background-color: rgba(133, 135, 176, 0.5);
  242. border-radius: rpx(30);
  243. flex: 1;
  244. margin: 0 rpx(10);
  245. height: 85%;
  246. display: flex;
  247. justify-content: flex-start;
  248. align-items: flex-start;
  249. background-origin: border-box;
  250. background-clip: padding-box;
  251. }
  252. .left-box-in-box2:hover,
  253. .left-box-in-box2:active,
  254. .center-box-in-box2:hover,
  255. .center-box-in-box2:active {
  256. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  257. }
  258. .left-box-in-box2,
  259. .center-box-in-box2,
  260. .top-sub-box,
  261. .bottom-sub-box {
  262. background-repeat: no-repeat;
  263. background-size: cover;
  264. background-position: center;
  265. }
  266. .right-box-in-box2 {
  267. flex: 1;
  268. margin: 0 rpx(10);
  269. height: 85%;
  270. display: flex;
  271. flex-direction: column;
  272. justify-content: flex-start;
  273. align-items: flex-start;
  274. gap: rpx(10);
  275. }
  276. .top-sub-box,
  277. .bottom-sub-box {
  278. background-color: rgba(133, 135, 176, 0.5);
  279. flex: 1;
  280. display: flex;
  281. border-radius: rpx(20);
  282. width: 100%;
  283. }
  284. .top-sub-box:hover,
  285. .top-sub-box:active,
  286. .bottom-sub-box:hover,
  287. .bottom-sub-box:active {
  288. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  289. }
  290. .inner-box {
  291. height: 100%;
  292. display: flex;
  293. justify-content: center;
  294. align-items: center;
  295. font-size: rpx(16);
  296. }
  297. .inner-box.left-box {
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-between;
  301. padding: 0 rpx(20);
  302. }
  303. .left-icon{
  304. font-size: rpx(14);
  305. color: white;
  306. cursor: pointer;
  307. }
  308. .app-header {
  309. width: 100%;
  310. height: rpx(30);
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. gap: rpx(5);
  315. }
  316. .app-logo {
  317. width: rpx(20);
  318. height: rpx(20);
  319. object-fit: contain;
  320. }
  321. .app-header span {
  322. color: white;
  323. font-size: rpx(11);
  324. letter-spacing: rpx(1);
  325. display: flex;
  326. align-items: center;
  327. height: 100%;
  328. }
  329. .left-box span {
  330. position: static;
  331. margin-top: 0;
  332. margin-left: 0;
  333. margin-right: rpx(10);
  334. font-size: rpx(11);
  335. color: white;
  336. max-width: rpx(200);
  337. white-space: normal;
  338. line-height: rpx(16);
  339. text-align: left;
  340. }
  341. .box-icon {
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. gap: rpx(5);
  346. padding: rpx(3) rpx(5);
  347. margin-right: rpx(5);
  348. border-radius: rpx(30);
  349. backdrop-filter: blur(10px);
  350. cursor: pointer;
  351. transition: all 0.3s ease;
  352. font-size: rpx(14);
  353. color: white;
  354. }
  355. .right-box {
  356. flex: 1;
  357. display: flex;
  358. justify-content: flex-end;
  359. align-items: center;
  360. margin-right: rpx(60);
  361. }
  362. .top-right-box {
  363. width: 100%;
  364. display: flex;
  365. justify-content: flex-end;
  366. align-items: center;
  367. flex-wrap: wrap;
  368. cursor: pointer;
  369. }
  370. .top-right-btn {
  371. width: rpx(50);
  372. height: rpx(15);
  373. margin: rpx(10) rpx(5) 0 0;
  374. background-color: transparent;
  375. color: white;
  376. border: none;
  377. font-size: rpx(8);
  378. outline: none;
  379. }
  380. .top-right-btn:hover {
  381. background-color: rgba(255, 255, 255, 0.7);
  382. border: 1px white solid;
  383. color: #8B4513;
  384. outline: none;
  385. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  386. }
  387. .dropdown-box {
  388. align-items: center;
  389. margin-top: 0;
  390. display: flex;
  391. }
  392. .dropdown-box .el-button {
  393. width: rpx(60);
  394. height: rpx(15);
  395. background-color: rgba(255, 255, 255, 0.7);
  396. border: 1px white solid;
  397. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  398. color: #8B4513;
  399. border-radius: rpx(12);
  400. font-size: rpx(8);
  401. }
  402. .dropdown-box .el-button:hover,
  403. .dropdown-box .el-button:focus,
  404. .dropdown-box .el-button:active {
  405. border: none;
  406. outline: none;
  407. }
  408. .dropdown-menu {
  409. width: rpx(100);
  410. border-radius: rpx(5);
  411. border: 1px white solid;
  412. background-color: rgba(255, 255, 255, 0.5);
  413. backdrop-filter: blur(rpx(5));
  414. box-shadow: 0 4px 8px rgba(139, 69, 19, 0.1);
  415. margin-left: rpx(40);
  416. }
  417. .el-scrollbar__view .el-dropdown__list{
  418. background-color: transparent;
  419. }
  420. .dropdown-menu ::v-deep(.el-dropdown-menu__item) {
  421. font-size: rpx(8);
  422. color: #8B4513;
  423. border-radius: rpx(5);
  424. width: rpx(78);
  425. height: rpx(20);
  426. margin-left: rpx(4);
  427. margin-bottom: rpx(8);
  428. }
  429. .dropdown-menu ::v-deep(.el-dropdown-menu__item:hover),
  430. .dropdown-menu ::v-deep(.el-dropdown-menu__item:focus),
  431. .dropdown-menu ::v-deep(.el-dropdown-menu__item:active) {
  432. background: linear-gradient(
  433. to bottom,
  434. #ffd700,
  435. #ffa500
  436. );
  437. box-shadow: 0 4px 8px rgba(139, 69, 19, 0.1);
  438. }
  439. </style>
  440. <style lang="scss">
  441. .no-arrow-dropdown .el-popper__arrow{
  442. display: none;
  443. }
  444. .el-popper.is-light,
  445. .el-dropdown__popper.el-popper{
  446. background: transparent;
  447. border: none;
  448. box-shadow: none;
  449. }
  450. .el-dropdown__popper{
  451. --el-dropdown-menuItem-hover-color: none;
  452. }
  453. .user-name-box:focus,
  454. .user-name-box:focus-within,
  455. .user-name-box:hover{
  456. outline: none;
  457. box-shadow: none;
  458. }
  459. .el-dropdown .el-dropdown__trigger:focus{
  460. outline: none;
  461. box-shadow: none;
  462. }
  463. </style>