AIDevelop.vue 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  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. <el-drawer
  22. v-model="drawerVisible"
  23. direction="ltr"
  24. size="18%"
  25. :with-header="false"
  26. >
  27. <!-- 添加抽屉 -->
  28. <div class="drawer-box">
  29. <el-row class="tac">
  30. <el-col :span="12">
  31. <span class="mb-2">
  32. <img :src="classImages" alt="课程小节图标" />
  33. 课程小节
  34. </span>
  35. <el-menu
  36. :default-active="course.key"
  37. @open="handleOpen"
  38. @close="handleClose"
  39. @select="handleSelect"
  40. :default-openeds="['3','5']"
  41. >
  42. <template v-for="item in menuItems" :key="item.key">
  43. <el-menu-item v-if="!item.children" :index="item.key">{{
  44. item.title
  45. }}</el-menu-item>
  46. <el-sub-menu v-else :index="item.key">
  47. <template #title>
  48. <span>{{ item.title }}</span>
  49. </template>
  50. <el-menu-item-group v-if="item.children">
  51. <template v-for="child in item.children" :key="child.key">
  52. <el-menu-item :index="child.key"
  53. >• {{ child.title }}</el-menu-item
  54. >
  55. </template>
  56. </el-menu-item-group>
  57. </el-sub-menu>
  58. </template>
  59. </el-menu>
  60. </el-col>
  61. </el-row>
  62. </div>
  63. </el-drawer>
  64. <div class="content-box">
  65. <div class="box-1">
  66. <div class="inner-box left-box">
  67. <div class="box-icon" @click="goBack">
  68. <el-icon class="left-icon"><ArrowLeftBold /></el-icon>
  69. {{ boxIconTitle }}
  70. </div>
  71. </div>
  72. <div class="inner-box right-box">
  73. <div class="top-right-box">
  74. <el-autocomplete
  75. v-model="SearchInput"
  76. :fetch-suggestions="querySearch"
  77. placeholder="搜索"
  78. @select="handleSearchSelect"
  79. class="search-input"
  80. value-key="title"
  81. :trigger-on-focus="false"
  82. >
  83. <template #prefix>
  84. <el-icon class="el-input__icon"><search /></el-icon>
  85. </template>
  86. <template #popper-append-to-body>
  87. <el-option
  88. class="scrollbar"
  89. v-for="item in filteredTitles"
  90. :key="item.key"
  91. :label="item.title"
  92. :value="item"
  93. ></el-option>
  94. </template>
  95. </el-autocomplete>
  96. </div>
  97. </div>
  98. </div>
  99. <div class="box-2">
  100. <!-- 课程标题 autoplay自动播放 @ended="playNextVideo"-->
  101. <div class="small-title">
  102. <span>{{ course.courseName }}</span>
  103. </div>
  104. <div class="box-video">
  105. <video
  106. class="full-box-video video-js vjs-default-skin"
  107. :src="course.courseVideoPath"
  108. controlsList="nodownload"
  109. controls
  110. @timeupdate="handleTimeUpdate"
  111. @play="checkVideoPermission"
  112. @seeked="handleSeeked"
  113. @ended="handleVideoEnded"
  114. ref="videoRef"
  115. >
  116. <source :src="course.courseVideoPath" type="video/mp4" />
  117. 您的浏览器不支持视频播放。
  118. </video>
  119. </div>
  120. <!-- 添加切换视频 -->
  121. <div class="video-switch">
  122. <!-- 上一个视频 -->
  123. <div class="caret-left" @click="playPreviousVideo">
  124. <el-button type="warning" round>
  125. <img :src="leftImg" alt="Left" />
  126. 上一节</el-button
  127. >
  128. </div>
  129. <!-- 下一个视频 -->
  130. <div class="caret-right" @click="playNextVideo">
  131. <el-button type="warning" round
  132. >下一节
  133. <img :src="rightImg" alt="Right" />
  134. </el-button>
  135. </div>
  136. </div>
  137. </div>
  138. <!-- 添加试题弹框 -->
  139. <transition name="fade-scale">
  140. <div
  141. v-show="questionDialogVisible"
  142. class="child-dialog-wrapper"
  143. @click.self="handleCloseQuestionDialog"
  144. >
  145. <div class="child-dialog">
  146. <div class="question-title">
  147. <span class="question-icon">?</span>
  148. <span v-html="courseConfig.ccQuestContent"></span>
  149. </div>
  150. <!-- 选项区域 -->
  151. <div
  152. v-if="
  153. courseConfig.ccQuestOption &&
  154. courseConfig.ccQuestOption.length > 0
  155. "
  156. class="options-container"
  157. >
  158. <div
  159. v-for="(option, index) in courseConfig.ccQuestOption"
  160. :key="index"
  161. class="question-option"
  162. >
  163. <el-radio
  164. v-model="selectedOption"
  165. :label="index"
  166. :value="option"
  167. v-cloak="(selectedOption = option)"
  168. >
  169. <span>{{ option }}</span>
  170. </el-radio>
  171. </div>
  172. </div>
  173. <div v-else class="no-options">
  174. <!-- 暂无选项 -->
  175. </div>
  176. <!-- 底部按钮 -->
  177. <div class="dialog-footer">
  178. <!-- <el-button class="child-button cancel" @click="questionDialogVisible = false; showAIDialog = false">取消</el-button>-->
  179. <el-button
  180. class="child-button confirm"
  181. @click="handleSubmitAnswer"
  182. >确定</el-button
  183. >
  184. </div>
  185. <!-- 右侧小图标 -->
  186. <div
  187. v-if="courseConfig.ccAiAnswer !== null"
  188. class="ai-icon-container"
  189. @click="handleAIClick"
  190. >
  191. <img
  192. src="@/assets/images/xiaozhi.png"
  193. alt="AI对话"
  194. class="ai-icon"
  195. />
  196. <span class="ai-text">小智智能助手</span>
  197. </div>
  198. </div>
  199. </div>
  200. </transition>
  201. <!-- AI对话弹框 -->
  202. <div
  203. v-show="showAIDialog"
  204. class="ai-dialog-wrapper"
  205. @click.self="showAIDialog = false"
  206. >
  207. <div class="ai-dialog">
  208. <div class="ai-dialog-header">
  209. <h3>
  210. <img :src="auto" alt="" />
  211. 小智智能助手
  212. </h3>
  213. <el-button @click="showAIDialog = false" class="close-btn"
  214. >×</el-button
  215. >
  216. </div>
  217. <div class="ai-dialog-content">
  218. <div class="ai-message-history">
  219. <div
  220. v-for="(message, index) in messageList"
  221. :key="index"
  222. :class="['message', message.type]"
  223. >
  224. <img
  225. v-if="message.type === 'user'"
  226. src="@/assets/images/user.png"
  227. class="avatar user"
  228. />
  229. <img v-else src="@/assets/images/xiaozhi.png" class="avatar" />
  230. <div
  231. class="message-content"
  232. v-if="message.type === 'user'"
  233. v-html="message.content"
  234. ></div>
  235. <div class="message-content" v-else>
  236. <MarkdownView class="left-text" :content="message.content" />
  237. </div>
  238. </div>
  239. </div>
  240. <!-- 弹框默认消息 -->
  241. <DefaultMessage
  242. class="default-messages"
  243. :category="'ai_develop'"
  244. :questTip="
  245. course.courseConfigList && course.courseConfigList[0]
  246. ? course.courseConfigList[0].ccAiQuestTip
  247. : ''
  248. "
  249. @select-message="handleSelectMessage"
  250. />
  251. <el-input
  252. v-model="prompt"
  253. placeholder="输入问题..."
  254. class="user-input"
  255. @keyup.enter="handleSendByKeydown"
  256. >
  257. <template #append class="flex flex-wrap items-center mb-4">
  258. <el-button @click="handleSendByButton" size="large" round
  259. >发送</el-button
  260. >
  261. </template>
  262. </el-input>
  263. </div>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. </template>
  269. <script setup>
  270. import { ref, onMounted, onUnmounted, onBeforeUnmount, computed } from 'vue'
  271. import { useRoute, useRouter } from 'vue-router'
  272. import videojs from 'video.js'
  273. import 'video.js/dist/video-js.css'
  274. import '@videojs/http-streaming' // 支持HLS分片
  275. const videoPlayer = ref(null)
  276. let player = null
  277. import { Expand, Fold, Memo } from '@element-plus/icons-vue'
  278. import { Search, ArrowLeftBold } from '@element-plus/icons-vue'
  279. import {
  280. ElMessage,
  281. ElMessageBox,
  282. ElNotification,
  283. valueEquals
  284. } from 'element-plus'
  285. import classImages from '@/assets/icon/class.png'
  286. import leftImg from '@/assets/icon/backward.png'
  287. import rightImg from '@/assets/icon/f-backward.png'
  288. import auto from '@/assets/icon/auto_awesome.png'
  289. import { ClassType } from '@/api/class.js'
  290. import { Message } from '@/utils/message/Message.js'
  291. import { saveRecord } from '@/api/personalized/index.js'
  292. import DefaultMessage from '@/components/DefaultMessage/index.vue'
  293. import { CreateDialogue, sendChatMessageStream } from '@/api/questions.js'
  294. import { teacherList } from '@/api/teachers.js'
  295. import MarkdownView from '@/components/MarkdownView/index.vue'
  296. // 导入全局状态
  297. import { globalState } from '@/utils/globalState.js'
  298. // 处理选择的默认消息
  299. const handleSelectMessage = message => {
  300. prompt.value = message
  301. }
  302. const router = useRouter() // 获取当前路由对象
  303. // 添加按钮显示状态
  304. const buttonVisible = ref(false)
  305. // 添加抽屉显示状态
  306. const drawerVisible = ref(false)
  307. // 添加切换抽屉显示状态的函数
  308. const toggleDrawer = () => {
  309. drawerVisible.value = !drawerVisible.value
  310. }
  311. // 返回上一页
  312. const goBack = () => {
  313. router.go(-1)
  314. }
  315. // 渲染页面标题
  316. const boxIconTitle = ref('')
  317. // 课程集合数据
  318. const courseList = ref([])
  319. //当前课程
  320. const course = ref({})
  321. // 菜单数据
  322. const menuItems = ref([])
  323. // 课程集合数据
  324. const videoPathMap = ref({})
  325. // 已观看课程ID列表
  326. const watchedCourseIds = ref([])
  327. //课程小节字典(需要新加接口调取字典)
  328. const menuDict = ref({
  329. 1: '课前回顾',
  330. 2: '课程引入',
  331. 3: '知识讲解',
  332. 4: '趣味实操',
  333. 5: '课程总结'
  334. })
  335. // 渲染 课程数据结构 以及 视频
  336. onMounted(async () => {
  337. const typeId = router.currentRoute.value.query.typeId
  338. if (typeId) {
  339. try {
  340. // 取接口课程数据
  341. const res = await ClassType(typeId)
  342. console.log(res);
  343. courseList.value = res.data
  344. // 初始化已观看课程ID
  345. const savedWatchedIds = localStorage.getItem('watchedCourseIds')
  346. if (savedWatchedIds) {
  347. watchedCourseIds.value = JSON.parse(savedWatchedIds)
  348. }
  349. //课程数据
  350. courseList.value.forEach((courseTemp, index) => {
  351. let menuIndex = courseTemp.courseLabel + '-' + (index + 1)
  352. //填充大纲小节
  353. let menu = menuItems.value.find(
  354. menu => courseTemp.courseLabel === menu.index
  355. )
  356. if (menu) {
  357. //小节
  358. menu.children = menu.children || []
  359. menu.children.push({
  360. key: menuIndex,
  361. index: menuIndex,
  362. title: courseTemp.courseName
  363. })
  364. } else {
  365. //大节
  366. let temp = {
  367. key: menuIndex,
  368. index: courseTemp.courseLabel,
  369. title: menuDict.value[courseTemp.courseLabel]
  370. }
  371. if (courseTemp.courseLabel === '3' || courseTemp.courseLabel === '5') {
  372. temp.children = [
  373. {
  374. key: menuIndex,
  375. index: menuIndex,
  376. title: courseTemp.courseName
  377. }
  378. ]
  379. }
  380. menuItems.value.push(temp)
  381. }
  382. courseTemp['key'] = menuIndex
  383. videoPathMap.value[menuIndex] = courseTemp
  384. //确定默认课程
  385. if (index === 0) {
  386. course.value = courseTemp
  387. }
  388. })
  389. } catch (error) {
  390. console.error('获取课程数据失败:', error)
  391. }
  392. }
  393. const title = router.currentRoute.value.query.typeName
  394. if (title) {
  395. boxIconTitle.value = String(title)
  396. }
  397. // 在视频元素上添加时间更新事件监听
  398. if (videoRef.value) {
  399. videoRef.value.addEventListener('timeupdate', handleTimeUpdate)
  400. }
  401. })
  402. // 菜单打开和关闭的处理函数
  403. const handleOpen = () => {}
  404. const handleClose = () => {}
  405. // 菜单选择的处理函数
  406. const handleSelect = index => {
  407. //测试账号禁用视频
  408. if (disableVideo(index)) return
  409. const findTitle = items => {
  410. for (const item of items) {
  411. if (item.key === index) {
  412. return item.title
  413. }
  414. if (item.children) {
  415. const result = findTitle(item.children)
  416. if (result) {
  417. return result
  418. }
  419. }
  420. }
  421. return null
  422. }
  423. // 根据索引切换视频,使用新的 videoPathMap
  424. if (videoPathMap.value[index]) {
  425. course.value = videoPathMap.value[index]
  426. courseId.value = course.value.id
  427. // 切换标题后,关闭抽屉
  428. drawerVisible.value = false
  429. } else {
  430. //视频不存在
  431. Message().notifyWarning('视频不存在!', true)
  432. }
  433. //测试账号禁用视频
  434. if (disableVideo()) return
  435. }
  436. // 展平所有菜单项索引
  437. const flattenMenuItems = () => {
  438. const indices = []
  439. const traverse = items => {
  440. for (const item of items) {
  441. if (!item.children) {
  442. indices.push(item.key)
  443. } else {
  444. traverse(item.children)
  445. }
  446. }
  447. }
  448. traverse(menuItems.value)
  449. return indices
  450. }
  451. // 播放下一个视频
  452. const playNextVideo = () => {
  453. //测试账号禁用视频
  454. if (disableVideo()) return
  455. // 记录当前视频ID为已观看
  456. if (
  457. course.value &&
  458. course.value.id &&
  459. !watchedCourseIds.value.includes(course.value.id)
  460. ) {
  461. watchedCourseIds.value.push(course.value.id)
  462. localStorage.setItem(
  463. 'watchedCourseIds',
  464. JSON.stringify(watchedCourseIds.value)
  465. )
  466. }
  467. const allIndices = flattenMenuItems()
  468. const currentIndexInList = allIndices.indexOf(course.value.key)
  469. if (currentIndexInList !== -1 && currentIndexInList < allIndices.length - 1) {
  470. const nextIndex = allIndices[currentIndexInList + 1]
  471. handleSelect(nextIndex)
  472. // 切换视频后自动播放
  473. if (videoRef.value) {
  474. videoRef.value.addEventListener('loadedmetadata', tryPlayVideo, {
  475. once: true
  476. })
  477. }
  478. }
  479. // 重置
  480. pausedIndices.value = []
  481. prompt.value = ''
  482. messageList.value = []
  483. }
  484. // 切换视频
  485. // 播放上一个视频
  486. const playPreviousVideo = () => {
  487. //测试账号禁用视频
  488. if (disableVideo()) return
  489. const allIndices = flattenMenuItems()
  490. const currentIndexInList = allIndices.indexOf(course.value.key)
  491. if (currentIndexInList > 0) {
  492. const previousIndex = allIndices[currentIndexInList - 1]
  493. handleSelect(previousIndex)
  494. // 切换视频后自动播放
  495. if (videoRef.value) {
  496. videoRef.value.addEventListener('loadedmetadata', tryPlayVideo, {
  497. once: true
  498. })
  499. }
  500. }
  501. }
  502. // 尝试播放视频,处理浏览器自动播放限制
  503. const tryPlayVideo = () => {
  504. //测试账号禁用视频
  505. if (disableVideo()) return
  506. const playPromise = videoRef.value.play()
  507. if (playPromise !== undefined) {
  508. playPromise.catch(error => {
  509. console.error('视频播放失败,可能是浏览器自动播放限制:', error)
  510. })
  511. }
  512. player = videojs(videoPlayer.value, {
  513. controls: true,
  514. sources: [
  515. {
  516. src: course.value.courseVideoPath,
  517. type: 'video/mp4'
  518. }
  519. ],
  520. preload: 'metadata' // 仅加载元数据,避免预加载整个文件
  521. })
  522. }
  523. // 检查视频播放权限
  524. const checkVideoPermission = () => {
  525. if (disableVideo() || questionDialogVisible.value) {
  526. if (videoRef.value) {
  527. videoRef.value.pause()
  528. }
  529. }
  530. }
  531. //禁用视频
  532. const disableVideo = (index = course.value.key) => {
  533. let dis = [
  534. '3-7',
  535. '3-8',
  536. '3-9',
  537. '3-10',
  538. '3-11',
  539. '3-12',
  540. '3-13',
  541. '4-14',
  542. '5-15'
  543. ]
  544. if (
  545. localStorage.getItem('userName') === 'aiTest' &&
  546. dis.indexOf(index) !== -1
  547. ) {
  548. if (videoRef.value) {
  549. // 记录当前播放时间
  550. videoRef.value.pause()
  551. // 阻止用户跳转到新的时间点,将播放时间重置为之前的时间
  552. videoRef.value.currentTime = 0
  553. }
  554. //提示禁用// 显示消息框
  555. Message().notifyWarning('您的账号并未开放此课程!', true)
  556. return true
  557. }
  558. return false
  559. }
  560. // 视频 ref
  561. const videoRef = ref(null)
  562. // 记录已经暂停过的时间点索引
  563. let pausedIndices = ref([])
  564. // 试题弹框显示状态
  565. const questionDialogVisible = ref(false)
  566. // 当前显示的试题
  567. const courseConfig = ref({})
  568. // 用户选择的选项
  569. const selectedOption = ref(null)
  570. // 记录已经保存的进度百分比
  571. const savedProgress = ref([])
  572. // 节流时间间隔(毫秒)
  573. const THROTTLE_TIME = 5000
  574. // 上次播放进度
  575. const lastPlayProgress = ref(0)
  576. // 定义进度数组
  577. const targetProgresses = [10, 50, 100]
  578. // AI对话弹出框显示状态
  579. let showAIDialog = ref(false)
  580. // 消息历史记录
  581. // let messageList = ref([])
  582. // 年级id
  583. const gradeId = ref('')
  584. // 课程大纲id
  585. const typeId = ref('')
  586. // 课程小节id
  587. const courseId = ref('')
  588. // AI问答次数
  589. const aiQuestionCount = ref(0)
  590. // 定义节流函数
  591. const throttle = (fn, delay) => {
  592. let lastCall = 0
  593. return function(...args) {
  594. const now = Date.now()
  595. if (now - lastCall >= delay) {
  596. lastCall = now
  597. return fn.apply(this, args)
  598. }
  599. }
  600. }
  601. // 保存进度(带节流)
  602. const saveProgress = throttle(async (progress, currentTime) => {
  603. try {
  604. // 保存到localStorage,下次加载视频续播
  605. localStorage.setItem(`videoProgress_${courseId.value}`, JSON.stringify({
  606. progress: progress,
  607. currentTime: currentTime,
  608. timestamp: Date.now()
  609. }))
  610. // 获取课程小节id
  611. if (typeId.value) {
  612. const courseRes = await ClassType(typeId.value)
  613. if (courseRes.data && courseRes.data.length > 0) {
  614. // 使用选中的课程id
  615. if (course.value && course.value.id) {
  616. courseId.value = course.value.id
  617. } else {
  618. // 如果没有选中的课程,默认使用第一个课程id
  619. courseId.value = courseRes.data[0].id
  620. }
  621. }
  622. }
  623. // 保存视频进度接口
  624. await saveRecord({
  625. brpNjId: gradeId.value,
  626. brpCtId: typeId.value,
  627. brpCourseId: courseId.value,
  628. brpType: 'course',
  629. brpProgress: progress
  630. })
  631. savedProgress.value.push(progress)
  632. } catch (error) {
  633. console.error(`保存进度失败:`, error)
  634. }
  635. }, THROTTLE_TIME)
  636. // 处理视频时间更新事件
  637. const handleTimeUpdate = () => {
  638. // 测试账号禁用视频
  639. if (!videoRef.value) return
  640. const currentTime = parseInt(videoRef.value.currentTime)
  641. const duration = videoRef.value.duration || 0
  642. const progressPercentage = duration > 0 ? Math.round((currentTime / duration) * 100) : 0
  643. // 更新最后播放进度
  644. lastPlayProgress.value = progressPercentage
  645. // 检查是否达到目标进度点且尚未保存
  646. targetProgresses.some(target => {
  647. const isNearTarget = Math.abs(progressPercentage - target) <= 2
  648. const isNotSaved = !savedProgress.value.includes(target)
  649. if (isNearTarget && isNotSaved) {
  650. // 保存目标进度
  651. saveProgress(target, currentTime)
  652. return true
  653. }
  654. return false
  655. })
  656. // 使用节流保存进度
  657. saveProgress(progressPercentage, currentTime)
  658. if (!course.value.courseConfigList) return
  659. course.value.courseConfigList.forEach(courseCofig => {
  660. //暂停时间
  661. let time = courseCofig.ccTime
  662. // 检查是否到达时间点且还未暂停过
  663. if (currentTime === time && !pausedIndices.value.includes(time)) {
  664. videoRef.value.pause()
  665. // 记录暂停时间
  666. pausedIndices.value.push(currentTime)
  667. // 视频弹框显示对应的问题
  668. if (courseCofig.ccQuestContent) {
  669. questionDialogVisible.value = true
  670. courseConfig.value = courseCofig
  671. // 解析选项
  672. if (courseCofig.ccQuestOption) {
  673. courseConfig.courseQuestion = courseCofig.ccQuestOption.split(',')
  674. }
  675. // 添加试题进度
  676. const saveQuestProgress = async () =>{
  677. try {
  678. // 确保courseId已经设置
  679. if (!courseId.value && typeId.value) {
  680. const courseRes = await ClassType(typeId.value)
  681. if (courseRes.data && courseRes.data.length > 0) {
  682. courseId.value = course.value && course.value.id ? course.value.id : courseRes.data[0].id
  683. }
  684. }
  685. if (courseCofig.id) {
  686. // 保存弹窗问题进度
  687. await saveRecord({
  688. brpNjId: gradeId.value,
  689. brpCtId: typeId.value,
  690. brpCourseConfigId: courseCofig.id,
  691. brpCourseId: courseId.value,
  692. brpType: 'courseQuest',
  693. brpProgress: progressPercentage
  694. })
  695. } else {
  696. console.error('无法保存试题进度: 试题id不存在')
  697. }
  698. }catch(error){
  699. console.error(`保存试题进度失败:`, error)
  700. }
  701. }
  702. // 调用异步函数
  703. saveQuestProgress()
  704. }
  705. }
  706. })
  707. }
  708. // 在视频加载完成后设置上次播放进度
  709. const setLastPlayPosition = () => {
  710. if (!videoRef.value) return
  711. try {
  712. const savedData = localStorage.getItem(`videoProgress_${courseId.value}`)
  713. if (savedData) {
  714. const { currentTime, progress } = JSON.parse(savedData)
  715. if (currentTime && !isNaN(currentTime)) {
  716. videoRef.value.currentTime = currentTime
  717. lastPlayProgress.value = progress
  718. }
  719. }
  720. } catch (error) {
  721. console.error('读取上次播放进度失败:', error)
  722. }
  723. }
  724. // 视频完成拖动进度条时触发的方法
  725. const handleSeeked = () => {
  726. pausedIndices.value = []
  727. }
  728. // 关闭试题弹框
  729. const handleCloseQuestionDialog = () => {
  730. questionDialogVisible.value = false
  731. // 继续播放视频
  732. videoRef.value.play()
  733. }
  734. // 提交答案
  735. const handleSubmitAnswer = () => {
  736. // 这里可以添加答案验证逻辑
  737. questionDialogVisible.value = false
  738. // 继续播放视频
  739. videoRef.value.play()
  740. selectedOption.value = null
  741. }
  742. // 发送消息
  743. const sendMessage = async () => {
  744. if (prompt.value.trim()) {
  745. // 添加用户消息到历史记录
  746. messageList.value.push({
  747. type: 'user',
  748. content: prompt.value
  749. })
  750. // 模拟 AI 回复
  751. const aiResponse = await simulateAIResponse(prompt.value)
  752. messageList.value.push({
  753. type: 'ai',
  754. content: aiResponse
  755. })
  756. activeMessageList.value = messageList.value
  757. // 清空输入框
  758. prompt.value = ''
  759. }
  760. }
  761. // 处理 AI 助手点击事件
  762. const handleAIClick = () => {
  763. // 清空输入框
  764. messageList.value = []
  765. if (courseConfig.value.ccQuestContent) {
  766. prompt.value = courseConfig.value.ccQuestContent
  767. sendMessage()
  768. prompt.value = ''
  769. }
  770. showAIDialog.value = true
  771. //创建对话
  772. createAiChart()
  773. }
  774. // 模拟 AI 回复
  775. const simulateAIResponse = question => {
  776. return new Promise(resolve => {
  777. setTimeout(() => {
  778. if (courseConfig.value.ccAiAnswer) {
  779. resolve(courseConfig.value.ccAiAnswer)
  780. return
  781. }
  782. // 若未匹配到自定义回复,给出默认回复
  783. resolve(`您的问题是:${question},这是 AI 的回复示例。`)
  784. }, 1000)
  785. })
  786. }
  787. // 关闭AI对话弹出框
  788. const handleCloseAIDialog = () => {
  789. showAIDialog.value = false
  790. }
  791. // 搜索框
  792. const SearchInput = ref('')
  793. // 添加搜索建议查询方法
  794. const querySearch = (queryString, cb) => {
  795. const sections = getAllCourseSections()
  796. const results = queryString
  797. ? sections.filter(section =>
  798. section.title.toLowerCase().includes(queryString.toLowerCase())
  799. )
  800. : sections
  801. cb(results)
  802. }
  803. const filteredTitles = computed(() => {
  804. const sections = getAllCourseSections()
  805. if (!SearchInput.value) {
  806. return sections
  807. }
  808. return sections.filter(section =>
  809. section.title.toLowerCase().includes(SearchInput.value.toLowerCase())
  810. )
  811. })
  812. const handleSearchSelect = item => {
  813. handleSelect(item.key)
  814. // 添加以下代码清空输入框
  815. SearchInput.value = ''
  816. }
  817. // 添加课程小节数据提取方法
  818. const getAllCourseSections = () => {
  819. let sections = []
  820. const traverse = items => {
  821. items.forEach(item => {
  822. if (item.children) {
  823. traverse(item.children)
  824. } else {
  825. sections.push({ title: item.title, key: item.key })
  826. }
  827. })
  828. }
  829. traverse(menuItems.value)
  830. return sections
  831. }
  832. // =========== 【聊天对话】小智ai ===========
  833. // 数字人接口
  834. const route = useRoute()
  835. const grade = ref('')
  836. const xZAiData = ref({})
  837. const getXzAi = async () => {
  838. try {
  839. grade.value = route.query.grade || localStorage.getItem('selectedGrade')
  840. // 获取小学低年级AI数据
  841. const juniorAIRes = await teacherList({ category: grade.value + 'AI' })
  842. const aiPerson = juniorAIRes.data.list.find(
  843. person => person.name === '小智'
  844. )
  845. if (aiPerson) {
  846. xZAiData.value = {
  847. id: aiPerson.id,
  848. name: aiPerson.name,
  849. image: aiPerson.model2dPath,
  850. message: aiPerson.systemMessage,
  851. default: aiPerson.questTip
  852. }
  853. } else {
  854. console.warn('未找到名为小智的数据')
  855. }
  856. } catch (error) {
  857. console.error('获取年级AI数据失败:', error)
  858. }
  859. }
  860. // =========== 【聊天对话】对话相关 ===========
  861. // 聊天对话
  862. const activeConversationModelPath = ref(null) // 选中的对话编号
  863. const activeConversationId = ref(null) // 选中的对话编号
  864. const activeConversation = ref(null) // 选中的 Conversation
  865. const conversationInProgress = ref(false) // 对话是否正在进行中。目前只有【发送】消息时,会更新为 true,避免切换对话、删除对话等操作,导致 stream 中断
  866. // 消息列表
  867. const messageRef = ref()
  868. const activeMessageList = ref([]) // 选中对话的消息列表
  869. // 消息滚动
  870. const textSpeed = ref(50) // Typing speed in milliseconds
  871. const textRoleRunning = ref(false) // Typing speed in milliseconds
  872. // 发送消息输入框
  873. const isComposing = ref(false) // 判断用户是否在输入
  874. const conversationInAbortController = ref() // 对话进行中 abort 控制器(控制 stream 对话)
  875. const inputTimeout = ref() // 处理输入中回车的定时器
  876. const prompt = ref() // prompt
  877. const enableContext = ref(true) // 是否开启上下文
  878. // 接收 Stream 消息
  879. const receiveMessageFullText = ref('')
  880. const receiveMessageDisplayedText = ref('')
  881. //创建对话
  882. const createAiChart = async () => {
  883. // 先获取数字人接口
  884. await getXzAi()
  885. // 智能问答
  886. CreateDialogue({ roleId: xZAiData.value.id })
  887. .then(res => {
  888. // console.log('创建会话:', res)
  889. activeConversationId.value = res.data
  890. })
  891. .catch(error => {
  892. console.error('请求出错:', error)
  893. })
  894. await getConversation(xZAiData.value.id)
  895. }
  896. // =========== 【聊天对话】相关 ===========
  897. /** 获取对话信息 */
  898. const getConversation = async id => {
  899. if (!id) {
  900. return
  901. }
  902. const conversation = ref({})
  903. if (!conversation) {
  904. return
  905. }
  906. conversation.systemMessage = xZAiData.value.message
  907. activeConversation.value = conversation
  908. activeConversationModelPath.value = xZAiData.value.image
  909. }
  910. // =========== 【发送消息】相关 ===========
  911. /** 处理来自 keydown 的发送消息 */
  912. const handleSendByKeydown = async event => {
  913. // 判断用户是否在输入
  914. if (isComposing.value) {
  915. return
  916. }
  917. // 进行中不允许发送
  918. if (conversationInProgress.value) {
  919. return
  920. }
  921. const content = prompt.value?.trim()
  922. if (event.key === 'Enter') {
  923. if (event.shiftKey) {
  924. // 插入换行
  925. prompt.value += '\r\n'
  926. event.preventDefault() // 防止默认的换行行为
  927. } else {
  928. // 发送消息
  929. await doSendMessage(content)
  930. event.preventDefault() // 防止默认的提交行为
  931. }
  932. }
  933. }
  934. onMounted(() => {
  935. // 获取本地存储中的值
  936. gradeId.value = globalState.initGradeId()
  937. typeId.value = localStorage.getItem('typeId') || ''
  938. // 视频相关初始化
  939. initVideoProgress()
  940. })
  941. const initVideoProgress = () => {
  942. // 延迟设置上次播放进度,确保视频已加载
  943. setTimeout(() => {
  944. setLastPlayPosition()
  945. }, 1000)
  946. // 检查是否已有保存的进度点
  947. const savedData = localStorage.getItem(`videoProgress_${courseId.value}`)
  948. if (savedData) {
  949. try {
  950. const { progress } = JSON.parse(savedData)
  951. if (progress >= 10) savedProgress.value.push(10)
  952. if (progress >= 50) savedProgress.value.push(50)
  953. if (progress >= 100) savedProgress.value.push(100)
  954. } catch (error) {
  955. console.error('解析保存的进度失败:', error)
  956. }
  957. }
  958. }
  959. // 添加视频结束事件处理
  960. const handleVideoEnded = () => {
  961. // 视频结束时保存100%进度
  962. if (!savedProgress.value.includes(100)) {
  963. saveProgress(100, videoRef.value.duration)
  964. }
  965. }
  966. /** 处理来自【发送】按钮的发送消息 */
  967. const handleSendByButton = () => {
  968. doSendMessage(prompt.value?.trim())
  969. }
  970. /** 处理 prompt 输入变化 */
  971. const handlePromptInput = event => {
  972. // 非输入法 输入设置为 true
  973. if (!isComposing.value) {
  974. // 回车 event data 是 null
  975. if (event.data == null) {
  976. return
  977. }
  978. isComposing.value = true
  979. }
  980. // 清理定时器
  981. if (inputTimeout.value) {
  982. clearTimeout(inputTimeout.value)
  983. }
  984. // 重置定时器
  985. inputTimeout.value = setTimeout(() => {
  986. isComposing.value = false
  987. }, 400)
  988. }
  989. // TODO注:是不是可以通过 @keydown.enter、@keydown.shift.enter 来实现,回车发送、shift+回车换行;主要看看,是不是可以简化 isComposing 相关的逻辑
  990. const onCompositionstart = () => {
  991. isComposing.value = true
  992. }
  993. const onCompositionend = () => {
  994. setTimeout(() => {
  995. isComposing.value = false
  996. }, 200)
  997. }
  998. /** 真正执行【发送】消息操作 */
  999. const doSendMessage = async content => {
  1000. // 校验
  1001. if (content.length < 1) {
  1002. console.error('发送失败,原因:内容为空!')
  1003. return
  1004. }
  1005. if (activeConversationId.value == null) {
  1006. console.error('还没创建对话,不能发送!')
  1007. return
  1008. }
  1009. // 增加问答次数
  1010. aiQuestionCount.value++
  1011. // 保存AI问答次数
  1012. try {
  1013. await saveRecord({
  1014. brpNjId: gradeId.value,
  1015. brpType: 'aiCount',
  1016. brpProgress: aiQuestionCount.value
  1017. })
  1018. } catch (error) {
  1019. console.error('保存AI问答次数失败:', error)
  1020. }
  1021. // 清空输入框
  1022. prompt.value = ''
  1023. // 执行发送
  1024. await doSendMessageStream({
  1025. conversationId: activeConversationId.value,
  1026. content: content
  1027. })
  1028. }
  1029. /** 真正执行【发送】消息操作 */
  1030. const doSendMessageStream = async userMessage => {
  1031. // 创建 AbortController 实例,以便中止请求
  1032. conversationInAbortController.value = new AbortController()
  1033. // 标记对话进行中
  1034. conversationInProgress.value = true
  1035. // 设置为空
  1036. receiveMessageFullText.value = ''
  1037. try {
  1038. // 1.1 先添加两个假数据,等 stream 返回再替换
  1039. activeMessageList.value.push({
  1040. id: -1,
  1041. conversationId: activeConversationId.value,
  1042. type: 'user',
  1043. content: userMessage.content,
  1044. createTime: new Date()
  1045. })
  1046. activeMessageList.value.push({
  1047. id: -2,
  1048. conversationId: activeConversationId.value,
  1049. type: 'assistant',
  1050. content: '思考中...',
  1051. createTime: new Date()
  1052. })
  1053. // 1.3 开始滚动
  1054. textRoll()
  1055. // 2. 发送 event stream
  1056. let isFirstChunk = true // 是否是第一个 chunk 消息段
  1057. await sendChatMessageStream(
  1058. userMessage.conversationId,
  1059. userMessage.content,
  1060. conversationInAbortController.value,
  1061. enableContext.value,
  1062. async res => {
  1063. const { code, data, msg } = JSON.parse(res.data)
  1064. if (code !== 0) {
  1065. console.log(`对话异常! ${msg}`)
  1066. return
  1067. }
  1068. // 如果内容为空,就不处理。
  1069. // if (data.receive.content === '') {
  1070. // return
  1071. // }
  1072. receiveMessageFullText.value =
  1073. receiveMessageFullText.value + data.receive.content
  1074. // 首次返回需要添加一个 message 到页面,后面的都是更新
  1075. if (isFirstChunk) {
  1076. isFirstChunk = false
  1077. // 弹出两个假数据
  1078. activeMessageList.value.pop()
  1079. activeMessageList.value.pop()
  1080. // 更新返回的数据
  1081. activeMessageList.value.push(data.send)
  1082. activeMessageList.value.push(data.receive)
  1083. }
  1084. },
  1085. error => {
  1086. console.log(`对话异常! ${error}`)
  1087. stopStream()
  1088. // 需要抛出异常,禁止重试
  1089. throw error
  1090. },
  1091. () => {
  1092. stopStream()
  1093. }
  1094. )
  1095. } catch {}
  1096. }
  1097. /** 停止 stream 流式调用 */
  1098. const stopStream = async () => {
  1099. // tip:如果 stream 进行中的 message,就需要调用 controller 结束
  1100. if (conversationInAbortController.value) {
  1101. conversationInAbortController.value.abort()
  1102. }
  1103. // 设置为 false
  1104. conversationInProgress.value = false
  1105. }
  1106. /**
  1107. * 消息列表
  1108. *
  1109. * 和 {@link #getMessageList()} 的差异是,把 systemMessage 考虑进去
  1110. */
  1111. const messageList = ref([])
  1112. // ============== 【消息滚动】相关 =============
  1113. /** 滚动到 message 底部 */
  1114. const scrollToBottom = async isIgnore => {
  1115. // if (messageRef.value) {
  1116. // messageRef.value.scrollToBottom(isIgnore)
  1117. // }
  1118. }
  1119. /** 自提滚动效果 */
  1120. const textRoll = async () => {
  1121. let index = 0
  1122. try {
  1123. // 只能执行一次
  1124. if (textRoleRunning.value) {
  1125. return
  1126. }
  1127. // 设置状态
  1128. textRoleRunning.value = true
  1129. receiveMessageDisplayedText.value = ''
  1130. const task = async () => {
  1131. // 调整速度
  1132. const diff =
  1133. (receiveMessageFullText.value.length -
  1134. receiveMessageDisplayedText.value.length) /
  1135. 10
  1136. if (diff > 5) {
  1137. textSpeed.value = 10
  1138. } else if (diff > 2) {
  1139. textSpeed.value = 30
  1140. } else if (diff > 1.5) {
  1141. textSpeed.value = 50
  1142. } else {
  1143. textSpeed.value = 100
  1144. }
  1145. // 对话结束,就按 30 的速度
  1146. if (!conversationInProgress.value) {
  1147. textSpeed.value = 10
  1148. }
  1149. if (index < receiveMessageFullText.value.length) {
  1150. receiveMessageDisplayedText.value += receiveMessageFullText.value[index]
  1151. index++
  1152. // 更新 message
  1153. const lastMessage =
  1154. activeMessageList.value[activeMessageList.value.length - 1]
  1155. lastMessage.content = receiveMessageDisplayedText.value
  1156. // 滚动到住下面
  1157. await scrollToBottom()
  1158. // 重新设置任务
  1159. timer = setTimeout(task, textSpeed.value)
  1160. } else {
  1161. // 不是对话中可以结束
  1162. if (!conversationInProgress.value) {
  1163. textRoleRunning.value = false
  1164. clearTimeout(timer)
  1165. } else {
  1166. // 重新设置任务
  1167. timer = setTimeout(task, textSpeed.value)
  1168. }
  1169. }
  1170. }
  1171. let timer = setTimeout(task, textSpeed.value)
  1172. } catch {}
  1173. }
  1174. </script>
  1175. <style scoped lang="scss">
  1176. @use 'sass:math';
  1177. @use 'sass:color'; // 引入 color 模块
  1178. // 定义rpx转换函数
  1179. @function rpx($px) {
  1180. @return math.div($px, 750) * 100vw;
  1181. }
  1182. // 定义儿童风格的蓝紫色调
  1183. $primary-color: rgba(106, 90, 205, 0.52); // 主色调:蓝紫色
  1184. $secondary-color: rgba(147, 112, 219, 0.66); // 辅助色:亮蓝紫色
  1185. $accent-color: rgb(133, 89, 220); // 强调色:暗蓝紫色
  1186. $light-color: #ffffff; // 浅色背景:淡紫色
  1187. $text-color: #483d8b; // 文本颜色:靛蓝色
  1188. /* 添加过渡样式 */
  1189. .drawer-slide-enter-active,
  1190. .drawer-slide-leave-active {
  1191. transition: all 0.3s ease;
  1192. }
  1193. .drawer-slide-enter-from,
  1194. .drawer-slide-leave-to {
  1195. transform: translateX(-100%);
  1196. opacity: 0;
  1197. }
  1198. .home-container ::v-deep(.el-drawer__body) {
  1199. width: rpx(135);
  1200. height: 100%;
  1201. position: relative;
  1202. background: linear-gradient(to bottom, #001169, #8a78d0);
  1203. }
  1204. .content-box {
  1205. flex: 1;
  1206. height: 100%;
  1207. display: flex;
  1208. flex-direction: column; /* 子元素上下排列 */
  1209. background: linear-gradient(to bottom, #001169, #8a78d0);
  1210. }
  1211. .icon-expand {
  1212. width: rpx(8);
  1213. height: rpx(35);
  1214. border-top-right-radius: rpx(5);
  1215. border-bottom-right-radius: rpx(5);
  1216. z-index: 9999;
  1217. position: absolute;
  1218. top: 50%;
  1219. left: 18%;
  1220. transform: translateY(-50%);
  1221. cursor: pointer; // 添加鼠标指针样式
  1222. clip-path: polygon(0 0, 100% 15%, 100% 85%, 0 100%);
  1223. display: flex;
  1224. justify-content: center;
  1225. align-items: center;
  1226. transition: all 0.3s ease;
  1227. }
  1228. .icon-expand .vertical-lines {
  1229. color: #8a78d0;
  1230. font-size: rpx(10);
  1231. }
  1232. .home-container {
  1233. position: fixed;
  1234. top: 0;
  1235. left: 0;
  1236. right: 0;
  1237. bottom: 0;
  1238. background: linear-gradient(to bottom, #001169, #b4a8e1);
  1239. display: flex;
  1240. }
  1241. .el-row {
  1242. margin: auto;
  1243. margin-top: rpx(20);
  1244. }
  1245. .tac ::v-deep(.el-menu) {
  1246. background-color: transparent;
  1247. border: none;
  1248. width: 100%;
  1249. margin-top: rpx(8);
  1250. }
  1251. /* 取消点击后的蓝色字体 el-sub-menu__title*/
  1252. .tac ::v-deep(.el-menu-item.is-active),
  1253. .tac ::v-deep(.el-sub-menu__title.is-active) {
  1254. color: white;
  1255. }
  1256. // 取消鼠标悬浮颜色
  1257. .tac ::v-deep(.el-sub-menu__title) {
  1258. width: rpx(130);
  1259. height: rpx(20);
  1260. margin-bottom: rpx(5);
  1261. border-radius: rpx(6);
  1262. // 添加flex布局使标题和图标两端对齐
  1263. display: flex;
  1264. justify-content: space-between;
  1265. align-items: center;
  1266. }
  1267. .el-menu ::v-deep(.el-sub-menu__title:hover),
  1268. .el-menu ::v-deep(.el-sub-menu__title:focus),
  1269. .el-menu ::v-deep(.el-sub-menu__title:active) {
  1270. background: linear-gradient(to bottom, #fee78a, #ffce1b);
  1271. background-color: transparent;
  1272. }
  1273. // 添加二级标题折叠图标样式
  1274. ::v-deep(.el-sub-menu__icon-arrow) {
  1275. color: white;
  1276. font-size: rpx(10); // 增大图标尺寸
  1277. margin-left: auto; // 将图标推到右侧
  1278. margin-top: rpx(-5);
  1279. display: block;
  1280. width: rpx(16); // 确保有明确宽度
  1281. }
  1282. // 鼠标悬停时的图标样式
  1283. .el-menu ::v-deep(.el-sub-menu__title:hover .el-sub-menu__icon-arrow) {
  1284. color: black; // 与悬停状态的文字颜色保持一致
  1285. }
  1286. .el-menu ::v-deep(.el-icon svg) {
  1287. font-size: rpx(9);
  1288. }
  1289. .mb-2 {
  1290. color: white;
  1291. font-size: rpx(9);
  1292. }
  1293. .mb-2 img {
  1294. width: rpx(10);
  1295. height: rpx(10);
  1296. vertical-align: middle;
  1297. margin-top: rpx(-2);
  1298. }
  1299. .el-menu-item {
  1300. width: rpx(100);
  1301. height: rpx(20);
  1302. margin-bottom: rpx(5);
  1303. border-radius: rpx(6);
  1304. color: white;
  1305. font-size: rpx(8);
  1306. }
  1307. .el-menu ::v-deep(.el-sub-menu__title) {
  1308. color: white;
  1309. width: rpx(100);
  1310. height: rpx(20);
  1311. margin-bottom: rpx(5);
  1312. font-size: rpx(8);
  1313. }
  1314. .el-menu ::v-deep(.el-sub-menu__title:hover),
  1315. .el-menu ::v-deep(.el-sub-menu__title:focus),
  1316. .el-menu ::v-deep(.el-sub-menu__title:active) {
  1317. background: linear-gradient(to bottom, #fee78a, #ffce1b);
  1318. color: black;
  1319. }
  1320. .el-menu ::v-deep(.el-menu-item:hover),
  1321. .el-menu ::v-deep(.el-menu-item:focus),
  1322. .el-menu ::v-deep(.el-menu-item:active) {
  1323. background: linear-gradient(to bottom, #fee78a, #ffce1b);
  1324. color: black;
  1325. font-size: rpx(8);
  1326. box-shadow: 0 4px 8px rgba(3, 3, 3, 0.3);
  1327. }
  1328. .el-menu .el-menu-item.is-active {
  1329. background: linear-gradient(to bottom, #fee78a, #ffce1b);
  1330. color: black;
  1331. font-size: rpx(8);
  1332. box-shadow: 0 4px 8px rgba(3, 3, 3, 0.3);
  1333. }
  1334. .drawer-box {
  1335. position: absolute;
  1336. display: flex;
  1337. align-items: center;
  1338. height: 100%;
  1339. width: 80%;
  1340. }
  1341. .drawer-box .toggle-button {
  1342. width: rpx(10);
  1343. height: rpx(50);
  1344. font-size: rpx(7);
  1345. background-color: rgba(17, 23, 29, 0.2);
  1346. border: none;
  1347. position: relative;
  1348. writing-mode: vertical-lr; // 文字垂直排列,从左到右
  1349. text-orientation: upright; // 文字保持正立
  1350. }
  1351. .toggle-button:hover {
  1352. left: 0;
  1353. }
  1354. .toggle-button.is-active,
  1355. .toggle-button:active,
  1356. .toggle-button:focus {
  1357. background-color: rgba(165, 209, 247, 0.8);
  1358. color: white;
  1359. border: none; // 移除点击时的边框
  1360. outline: none; // 移除点击时的外边框
  1361. }
  1362. .box-1 {
  1363. width: 100%;
  1364. height: rpx(50);
  1365. margin-top: rpx(10);
  1366. display: flex;
  1367. justify-content: center;
  1368. align-items: center;
  1369. box-sizing: border-box;
  1370. font-size: rpx(15); // 默认字体大小
  1371. }
  1372. .inner-box {
  1373. height: 100%;
  1374. display: flex;
  1375. justify-content: center;
  1376. align-items: center;
  1377. font-size: rpx(16); // 默认字体大小
  1378. }
  1379. .left-box {
  1380. position: relative;
  1381. justify-content: flex-start;
  1382. align-items: flex-start;
  1383. flex: 1; // 设置左侧盒子占比为 2
  1384. cursor: pointer; // 添加鼠标指针样式
  1385. }
  1386. .box-icon {
  1387. width: 100%;
  1388. height: 100%;
  1389. flex: 1;
  1390. display: flex; // 添加 flex 布局
  1391. align-items: center; // 垂直居中
  1392. color: white; // 设置图标颜色为白色
  1393. padding-left: rpx(15);
  1394. font-size: rpx(10); // 设置图标大小,可按需调整
  1395. }
  1396. .box-icon .left-icon {
  1397. margin-left: rpx(10);
  1398. margin-right: rpx(5); // 设置图标和文字之间的间距 ;
  1399. }
  1400. .left-box span {
  1401. position: absolute;
  1402. font-size: rpx(11); // 默认字体大小
  1403. color: white;
  1404. }
  1405. .right-box {
  1406. flex: 1;
  1407. position: relative; // 添加相对定位;
  1408. }
  1409. .top-right-box {
  1410. position: absolute; // 添加绝对定位
  1411. // margin-top: rpx(9); // 调整上边距离
  1412. margin-left: rpx(260); // 调整右边距离
  1413. width: rpx(100); // 设置盒子宽度,可按需调整
  1414. // height: 60px; // 设置盒子高度,可按需调整
  1415. display: flex;
  1416. justify-content: flex-end;
  1417. }
  1418. .top-right-box {
  1419. ::v-deep(.el-input__wrapper) {
  1420. height: rpx(15);
  1421. font-size: rpx(6);
  1422. background-color: rgb(255, 255, 255, 0.5);
  1423. border-radius: rpx(12);
  1424. border: white 1px solid;
  1425. color: white;
  1426. }
  1427. ::v-deep(.el-input__icon) {
  1428. color: white; // 设置输入框图标颜色为白色
  1429. }
  1430. // 添加占位符样式
  1431. ::v-deep(.el-input__inner::placeholder) {
  1432. color: white;
  1433. }
  1434. // 添加输入框文字颜色样式
  1435. ::v-deep(.el-input__inner) {
  1436. color: black;
  1437. }
  1438. }
  1439. // 搜索框
  1440. .search-input {
  1441. width: rpx(100);
  1442. height: rpx(15);
  1443. font-size: rpx(7);
  1444. }
  1445. .box-2 {
  1446. width: 100%;
  1447. flex: 1;
  1448. box-shadow: 0 4px 8px rgba(202, 52, 52, 0.1);
  1449. box-sizing: border-box;
  1450. display: flex; // 确保子元素水平排列
  1451. flex-wrap: wrap; // 允许子元素换行;
  1452. align-content: center; // 顶部对齐;
  1453. cursor: pointer; // 添加鼠标指针样式
  1454. }
  1455. .box-video {
  1456. width: 100%;
  1457. height: rpx(300);
  1458. video.full-box-video {
  1459. height: rpx(280);
  1460. width: 67%;
  1461. margin: 0 auto;
  1462. border-radius: rpx(12);
  1463. object-fit: cover;
  1464. }
  1465. }
  1466. /* 隐藏 Chrome 视频控件的渐变背景等默认样式 */
  1467. video::-webkit-media-controls-panel {
  1468. background: transparent !important; /* 去掉背景渐变,设为透明 */
  1469. }
  1470. .small-title {
  1471. width: 100%;
  1472. margin-top: rpx(-20);
  1473. height: rpx(20);
  1474. color: white;
  1475. font-size: rpx(10);
  1476. justify-content: center; //使子元素水平居中
  1477. }
  1478. .video-switch {
  1479. width: 100%;
  1480. // height: rpx(50);
  1481. display: flex;
  1482. margin-top: rpx(-20);
  1483. // background-color: saddlebrown;
  1484. }
  1485. .caret-right,
  1486. .caret-left {
  1487. width: rpx(50);
  1488. margin: auto;
  1489. display: flex;
  1490. margin-top: rpx(5);
  1491. margin-bottom: rpx(15);
  1492. }
  1493. .caret-left ::v-deep(.el-button.is-round),
  1494. .caret-right ::v-deep(.el-button.is-round) {
  1495. width: rpx(50);
  1496. height: rpx(15);
  1497. color: white;
  1498. font-size: rpx(7);
  1499. border-radius: none;
  1500. border: 1px white solid;
  1501. background-color: rgb(255, 255, 255, 0.5); // 进度条背景颜色,调浅为半透明白色
  1502. box-shadow: 0 4px 8px rgba(202, 52, 52, 0.1);
  1503. }
  1504. .caret-right img,
  1505. .caret-left img {
  1506. width: rpx(12);
  1507. }
  1508. // 儿童风格试题弹框样式
  1509. .child-dialog {
  1510. .el-dialog__header {
  1511. display: none; // 隐藏原有的标题栏
  1512. }
  1513. .el-dialog__body {
  1514. padding: rpx(20);
  1515. position: relative;
  1516. }
  1517. .el-dialog__footer {
  1518. border-top: none;
  1519. padding: rpx(10) rpx(20);
  1520. text-align: center;
  1521. margin-top: auto; // 使底部按钮位于底部
  1522. }
  1523. .el-dialog__wrapper {
  1524. // 修改半透明背景色
  1525. background-color: rgba(0, 0, 0, 0.6);
  1526. }
  1527. .el-dialog {
  1528. border: none;
  1529. border-radius: rpx(20);
  1530. background: linear-gradient(
  1531. 135deg,
  1532. $light-color,
  1533. #d8bfd8
  1534. ); // 柔和的蓝紫色渐变
  1535. overflow: hidden;
  1536. display: flex; // 添加 flex 布局
  1537. flex-direction: column; // 设置垂直布局
  1538. min-height: 0; // 防止子元素溢出
  1539. // 添加装饰元素
  1540. &::before {
  1541. content: '';
  1542. position: absolute;
  1543. top: 0;
  1544. left: 0;
  1545. width: 100%;
  1546. height: rpx(10);
  1547. background: linear-gradient(90deg, $secondary-color, $accent-color);
  1548. }
  1549. }
  1550. }
  1551. // 问题标题样式
  1552. .question-title {
  1553. padding: rpx(15);
  1554. border-radius: rpx(12);
  1555. margin-bottom: rpx(20);
  1556. color: #483d8b;
  1557. font-weight: bold;
  1558. font-size: rpx(12);
  1559. position: relative;
  1560. display: flex;
  1561. // align-items: center;
  1562. .question-icon {
  1563. background-color: $accent-color;
  1564. color: white;
  1565. width: rpx(24);
  1566. height: rpx(24);
  1567. border-radius: 50%;
  1568. display: flex;
  1569. align-items: center;
  1570. justify-content: center;
  1571. margin-right: rpx(10);
  1572. font-weight: bold;
  1573. box-shadow: 0 rpx(2) rpx(5) rgba($accent-color, 0.3);
  1574. }
  1575. }
  1576. // 选项容器样式
  1577. .options-container {
  1578. margin-bottom: rpx(20);
  1579. }
  1580. // 问题选项样式
  1581. .question-option {
  1582. margin: rpx(8) 0;
  1583. padding: rpx(10) rpx(15);
  1584. border-radius: rpx(12);
  1585. border: rpx(1) solid rgba($primary-color, 0.3);
  1586. transition: all 0.3s ease;
  1587. display: flex;
  1588. align-items: center;
  1589. background-color: white;
  1590. box-shadow: 0 rpx(2) rpx(5) rgba($primary-color, 0.05);
  1591. ::v-deep(.el-radio__label) {
  1592. color: $text-color;
  1593. margin-left: rpx(8);
  1594. flex: 1;
  1595. text-align: left;
  1596. // 增大字体大小
  1597. font-size: rpx(12);
  1598. }
  1599. // 选中时的样式变化
  1600. .el-radio__input.is-checked + .el-radio__label {
  1601. font-weight: bold;
  1602. color: $accent-color;
  1603. }
  1604. &:hover {
  1605. background-color: rgba($primary-color, 0.05);
  1606. border-color: rgba($primary-color, 0.5);
  1607. transform: translateY(-rpx(1));
  1608. }
  1609. }
  1610. // 暂无选项样式
  1611. .no-options {
  1612. color: rgba($text-color, 0.7);
  1613. text-align: center;
  1614. padding: rpx(20);
  1615. font-size: rpx(12);
  1616. }
  1617. // 底部按钮样式
  1618. .child-button {
  1619. min-width: rpx(80);
  1620. height: rpx(30);
  1621. border-radius: rpx(8);
  1622. font-size: rpx(12);
  1623. font-weight: 500;
  1624. transition: all 0.3s ease;
  1625. box-shadow: 0 rpx(2) rpx(8) rgba(0, 0, 0, 0.1);
  1626. &.confirm {
  1627. background: linear-gradient(to bottom, #ab81ff, #8559dc);
  1628. border: none;
  1629. border-right: 15px;
  1630. color: white;
  1631. &:hover {
  1632. background: linear-gradient(
  1633. to bottom,
  1634. color.adjust(#ab81ff, $lightness: -5%),
  1635. color.adjust(#8559dc, $lightness: -5%)
  1636. );
  1637. transform: translateY(-rpx(1));
  1638. color: white;
  1639. }
  1640. }
  1641. &.cancel {
  1642. background: white;
  1643. border: rpx(1) solid rgba($primary-color, 0.3);
  1644. color: $text-color;
  1645. &:hover {
  1646. background: rgba($primary-color, 0.05);
  1647. border-color: rgba($primary-color, 0.5);
  1648. transform: translateY(-rpx(1));
  1649. }
  1650. }
  1651. }
  1652. // AI对话图标样式
  1653. .ai-icon-container {
  1654. position: absolute;
  1655. bottom: rpx(20);
  1656. right: rpx(20);
  1657. display: flex;
  1658. flex-direction: column;
  1659. align-items: center;
  1660. cursor: pointer;
  1661. transition: all 0.3s ease;
  1662. &:hover {
  1663. transform: translateY(-rpx(2));
  1664. }
  1665. .ai-icon {
  1666. width: rpx(30);
  1667. height: rpx(30);
  1668. margin-bottom: rpx(0);
  1669. filter: drop-shadow(0 rpx(2) rpx(4) rgba($primary-color, 0.3));
  1670. // 添加过渡动画
  1671. transition: transform 0.3s ease;
  1672. }
  1673. // 悬浮时放大效果
  1674. .ai-icon:hover {
  1675. transform: scale(1.5);
  1676. }
  1677. .ai-text {
  1678. color: $text-color;
  1679. font-size: rpx(8);
  1680. background-color: rgba(255, 255, 255, 0.7);
  1681. padding: rpx(2) rpx(5);
  1682. border-radius: rpx(5);
  1683. }
  1684. }
  1685. // AI消息样式
  1686. .ai-message {
  1687. display: flex;
  1688. align-items: flex-start;
  1689. margin-bottom: rpx(15);
  1690. .ai-avatar {
  1691. width: rpx(30);
  1692. height: rpx(30);
  1693. border-radius: 50%;
  1694. margin-right: rpx(10);
  1695. background-color: $primary-color;
  1696. padding: rpx(5);
  1697. // box-shadow: 0 rpx(2) rpx(5) rgba($primary-color, 0.2);
  1698. }
  1699. .ai-text-content {
  1700. background-color: $light-color;
  1701. padding: rpx(8) rpx(12);
  1702. border-radius: rpx(10);
  1703. font-size: rpx(10);
  1704. color: $text-color;
  1705. max-width: 80%;
  1706. // box-shadow: 0 rpx(1) rpx(3) rgba(0, 0, 0, 0.05);
  1707. }
  1708. }
  1709. // 用户输入框样式
  1710. .user-input {
  1711. ::v-deep(.el-input__wrapper) {
  1712. height: rpx(23);
  1713. border-top-left-radius: rpx(5);
  1714. border-bottom-left-radius: rpx(5);
  1715. border-color: rgba($primary-color, 0.3);
  1716. &:focus-within {
  1717. box-shadow: 0 0 0 rpx(1) rgba($primary-color, 0.5);
  1718. }
  1719. }
  1720. ::v-deep(.el-input__inner) {
  1721. font-size: rpx(10);
  1722. // color: $text-color;
  1723. text-indent: 1em;
  1724. }
  1725. ::v-deep(.el-input-group__append, .el-input-group__prepend) {
  1726. background: linear-gradient(to bottom, #ab81ff, #8559dc);
  1727. border-top-right-radius: rpx(5);
  1728. border-bottom-right-radius: rpx(5);
  1729. color: white;
  1730. font-size: rpx(9);
  1731. }
  1732. }
  1733. /* 定义淡入和缩放动画 */
  1734. .fade-scale-enter-active,
  1735. .fade-scale-leave-active {
  1736. transition: all 0.5s ease;
  1737. }
  1738. .fade-scale-enter-from,
  1739. .fade-scale-leave-to {
  1740. opacity: 0.1;
  1741. transform: scale(0.9);
  1742. }
  1743. // 自定义试题弹框背景
  1744. .child-dialog-wrapper {
  1745. position: fixed;
  1746. top: 0;
  1747. left: 0;
  1748. right: 0;
  1749. bottom: 0;
  1750. background-color: rgba(0, 0, 0, 0.6); // 半透明背景
  1751. display: flex;
  1752. justify-content: center;
  1753. align-items: center;
  1754. z-index: 1000;
  1755. }
  1756. .child-dialog {
  1757. border: none;
  1758. border-radius: rpx(15);
  1759. background: rgb(255, 255, 255, 0.8); // 柔和的蓝紫色渐变
  1760. overflow: hidden;
  1761. padding: rpx(5);
  1762. // width: 40%;
  1763. // height: 60%;
  1764. position: relative;
  1765. }
  1766. // AI对话弹框样式
  1767. .ai-dialog-wrapper {
  1768. position: fixed;
  1769. top: 0;
  1770. left: 0;
  1771. right: 0;
  1772. bottom: 0;
  1773. display: flex;
  1774. justify-content: flex-end;
  1775. align-items: center;
  1776. z-index: 1001;
  1777. pointer-events: none;
  1778. }
  1779. .ai-dialog {
  1780. border: none;
  1781. border-radius: rpx(15);
  1782. background: rgb(255, 255, 255, 0.8);
  1783. overflow: hidden;
  1784. padding: rpx(20);
  1785. width: 30%;
  1786. // 增加高度
  1787. height: 80%;
  1788. margin-right: rpx(50);
  1789. pointer-events: auto;
  1790. position: relative;
  1791. display: flex;
  1792. flex-direction: column;
  1793. &::before {
  1794. content: '';
  1795. position: absolute;
  1796. top: 0;
  1797. left: 0;
  1798. width: 100%;
  1799. height: rpx(10);
  1800. }
  1801. }
  1802. .ai-dialog-header {
  1803. position: relative;
  1804. display: flex;
  1805. justify-content: center;
  1806. align-items: center;
  1807. margin-bottom: rpx(15);
  1808. margin-top: rpx(-10);
  1809. img {
  1810. width: rpx(15);
  1811. }
  1812. h3 {
  1813. color: black;
  1814. font-size: rpx(12);
  1815. }
  1816. .close-btn {
  1817. padding: 0;
  1818. width: rpx(20);
  1819. height: rpx(20);
  1820. font-size: rpx(16);
  1821. line-height: 1;
  1822. position: absolute;
  1823. background-color: transparent;
  1824. border: none;
  1825. margin-left: rpx(200);
  1826. }
  1827. }
  1828. .ai-dialog-content {
  1829. flex: 1;
  1830. display: flex;
  1831. flex-direction: column;
  1832. }
  1833. .ai-message-history {
  1834. flex: 1;
  1835. // 当内容超出容器高度时,显示垂直滚动条
  1836. overflow-y: auto;
  1837. margin-bottom: rpx(15);
  1838. // 可以根据实际情况调整最大高度
  1839. font-size: rpx(5);
  1840. max-height: 50vh;
  1841. // padding: 5px 10px;
  1842. .message {
  1843. display: flex;
  1844. align-items: flex-start;
  1845. margin-bottom: rpx(10);
  1846. &.user {
  1847. flex-direction: row-reverse;
  1848. }
  1849. .avatar {
  1850. width: rpx(30);
  1851. height: rpx(30);
  1852. border-radius: 50%;
  1853. margin: 0 rpx(10);
  1854. }
  1855. .user {
  1856. width: 15px;
  1857. height: 15px;
  1858. }
  1859. .message-content {
  1860. background-color: #ffffff;
  1861. font-size: rpx(5);
  1862. max-width: 80%;
  1863. color: black;
  1864. box-shadow: 0 rpx(1) rpx(3) rgba(0, 0, 0, 0.05);
  1865. }
  1866. }
  1867. // 滚动条整体样式
  1868. &::-webkit-scrollbar {
  1869. width: rpx(4); // 滚动条宽度
  1870. }
  1871. // 滚动条滑块样式
  1872. &::-webkit-scrollbar-thumb {
  1873. background-color: $primary-color; // 滑块颜色
  1874. border-radius: rpx(4); // 滑块圆角
  1875. transition: background-color 0.3s ease; // 颜色过渡效果
  1876. &:hover {
  1877. //background-color: darken($primary-color, 10%); // 悬停时滑块颜色加深
  1878. }
  1879. }
  1880. // 滚动条轨道样式
  1881. &::-webkit-scrollbar-track {
  1882. background-color: rgba($primary-color, 0.2); // 轨道颜色
  1883. border-radius: rpx(4); // 轨道圆角
  1884. }
  1885. .message {
  1886. display: flex;
  1887. align-items: flex-start;
  1888. margin-bottom: rpx(10);
  1889. &.user {
  1890. flex-direction: row-reverse;
  1891. }
  1892. .avatar {
  1893. width: rpx(30);
  1894. height: rpx(30);
  1895. border-radius: 50%;
  1896. margin: 0 rpx(10);
  1897. }
  1898. .message-content {
  1899. background-color: white;
  1900. padding: rpx(8) rpx(12);
  1901. border-radius: rpx(5);
  1902. font-size: rpx(8);
  1903. color: black;
  1904. max-width: 80%;
  1905. box-shadow: 0 rpx(1) rpx(3) rgba(0, 0, 0, 0.05);
  1906. }
  1907. }
  1908. }
  1909. // 优化发送按钮样式
  1910. .send-button {
  1911. //background: linear-gradient(90deg, $primary-color, $secondary-color);
  1912. border: none;
  1913. color: white;
  1914. &:hover {
  1915. //background: linear-gradient(90deg, darken($primary-color, 5%), darken($secondary-color, 5%));
  1916. }
  1917. }
  1918. </style>
  1919. <style lang="scss">
  1920. // 搜索下拉框样式
  1921. @use 'sass:math';
  1922. // 定义rpx转换函数
  1923. @function rpx($px) {
  1924. @return math.div($px, 750) * 100vw;
  1925. }
  1926. /* 消除小三角 */
  1927. .el-popper__arrow {
  1928. display: none;
  1929. }
  1930. .el-popper.is-light,
  1931. .el-dropdown__popper.el-popper {
  1932. background: transparent;
  1933. border: none;
  1934. box-shadow: none;
  1935. }
  1936. .el-dropdown__popper {
  1937. --el-dropdown-menuItem-hover-color: none;
  1938. }
  1939. .el-autocomplete-suggestion .el-scrollbar__wrap {
  1940. margin: 0 auto;
  1941. background-color: rgba(255, 255, 255, 0.7);
  1942. border: 2px solid white;
  1943. border-radius: rpx(5);
  1944. backdrop-filter: blur(rpx(5));
  1945. }
  1946. .el-autocomplete-suggestion li {
  1947. color: black;
  1948. font-size: rpx(7);
  1949. padding: rpx(5) rpx(8); // 调整下拉项内边距
  1950. }
  1951. .el-autocomplete-suggestion li:hover {
  1952. background: linear-gradient(to bottom, #ffefb0, #ffcc00);
  1953. }
  1954. </style>
  1955. <style scoped lang="scss">
  1956. @use 'sass:math';
  1957. // 定义rpx转换函数
  1958. @function rpx($px) {
  1959. @return math.div($px, 750) * 100vw;
  1960. }
  1961. .default-messages {
  1962. margin-top: rpx(-10);
  1963. margin-bottom: rpx(5);
  1964. }
  1965. </style>