四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2193 lines
79 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="book-container">
  3. <!-- 条件编译 -->
  4. <!-- #ifndef H5 -->
  5. <uv-status-bar></uv-status-bar>
  6. <!-- 自定义顶部导航栏 -->
  7. <view class="custom-navbar" :class="{ 'navbar-hidden': !showNavbar }">
  8. <uv-status-bar></uv-status-bar>
  9. <view class="navbar-content">
  10. <view class="navbar-left" @click="goBack">
  11. <uv-icon name="arrow-left" size="20" color="#262626"></uv-icon>
  12. </view>
  13. <view class="navbar-title">{{ currentPageTitle }}</view>
  14. </view>
  15. </view>
  16. <!-- #endif -->
  17. <!-- Swiper内容区域 -->
  18. <swiper class="content-swiper" :current="currentPage - 1" @change="onSwiperChange">
  19. <swiper-item v-for="(page, index) in bookPages" :key="index" class="swiper-item">
  20. <scroll-view scroll-y :scroll-top="scrollTops[index] || 0" :scroll-with-animation="true"
  21. style="height: 100vh;" class="scroll-container" @scroll="onScroll" @touchstart="onTouchStart"
  22. @touchmove="onTouchMove" @touchend="onTouchEnd">
  23. <view class="content-area" @click="toggleNavbar">
  24. <view class="title">{{ currentPageTitle }}</view>
  25. <!-- 会员限制页面 -->
  26. <view v-if="!isMember && pagePay[index] === 'Y'" class="member-content">
  27. <text class="member-title">{{ pageTitles[index] }}</text>
  28. <view class="member-button" @click.stop="unlockBook">
  29. <text class="member-button-text">升级会员解锁</text>
  30. </view>
  31. </view>
  32. <!-- 图片卡片页面 -->
  33. <view class="card-content" v-else-if="pageTypes[index] === '1'">
  34. <view class="card-line">
  35. <image :src="configParamContent('highlight_icon')" class="card-line-image"
  36. mode="aspectFill" />
  37. <text class="card-line-text">划线重点</text>
  38. </view>
  39. <view v-for="(item, itemIndex) in page" :key="itemIndex" class="text-content">
  40. <image class="card-image" v-if="item && item.type === 'image'" :src="item.imageUrl"
  41. mode="widthFix"></image>
  42. <!-- <view :class="['english-text-container', 'clickable-text', { 'lead-text': isCardTextHighlighted(page, itemIndex) }]" v-else-if="item && item.type === 'text' && item.language === 'en' && item.content" @click.stop="handleTextClick(item.content, item, index)" >
  43. <text
  44. v-for="(token, tokenIndex) in splitEnglishSentence(item.content)"
  45. :key="tokenIndex"
  46. :class="['english-token', { 'clickable-word': token.isWord && findWordDefinition(token.text) }]"
  47. @click.stop="token.isWord && findWordDefinition(token.text) ? handleWordClick(token.text) : null"
  48. user-select
  49. :style="item.style"
  50. >{{ token.text }}</text>
  51. </view> -->
  52. <!-- <view :class="{ 'lead-text': isCardTextHighlighted(page, itemIndex) }" v-else-if="item && item.type === 'text' && item.language === 'zh' && item.content" @click.stop="handleTextClick(item.content, item, index)"> -->
  53. <view :class="{
  54. 'lead-text': isCardTextHighlighted(page, itemIndex),
  55. 'introduction-text' : item.isLead,
  56. }"
  57. v-else-if="item && item.type === 'text' && item.content"
  58. @click.stop="handleTextClick(item.content, item, index)">
  59. <text v-for="(segment, segmentIndex) in processChineseText(item.content)"
  60. :key="segmentIndex"
  61. :class="['chinese-segment', { 'clickable-keyword': segment.isKeyword }]"
  62. @click.stop="segment.isKeyword ? handleChineseKeywordClick(segment.keywordData) : handleTextClick(item.content, item, index)"
  63. user-select :style="item.style" :id="`text-segment-${segmentIndex}`">{{
  64. segment.text }}</text>
  65. </view>
  66. </view>
  67. </view>
  68. <view v-else>
  69. <view v-for="(item, itemIndex) in page" :key="itemIndex">
  70. <!-- 文本页面 -->
  71. <view v-if="item && item.type === 'text' && item.content" class="text-content">
  72. <view :class="{
  73. 'lead-text': isTextHighlighted(page, itemIndex),
  74. 'introduction-text' : item.isLead,
  75. }"
  76. @click.stop="handleTextClick(item.content, item, index)"
  77. :ref="`textRef_${index}_${itemIndex}`" :id="`text-${itemIndex}`">
  78. <text class="content-text clickable-text"
  79. :style="item.style" user-select>
  80. {{ item.content }}
  81. </text>
  82. </view>
  83. </view>
  84. <!-- 图片页面 -->
  85. <view v-else-if="item.type === 'image'" class="image-container"
  86. :ref="`imageRef_${index}_${itemIndex}`">
  87. <image class="content-image" :src="item.imageUrl" mode="widthFix"></image>
  88. </view>
  89. <!-- 视频页面 -->
  90. <view v-else-if="item.type === 'video'" class="video-content" @click.stop>
  91. <!-- 视频加载状态 -->
  92. <view v-if="videoLoading" class="video-loading">
  93. <text class="loading-text">视频加载中...</text>
  94. </view>
  95. <!-- 视频播放器 -->
  96. <video v-else :src="item.url" class="video-player" controls :poster="item.coverUrl"
  97. @loadstart="onVideoLoadStart" @loadeddata="onVideoLoadStart"
  98. @error="onVideoError"></video>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </scroll-view>
  104. </swiper-item>
  105. </swiper>
  106. <!-- 自定义底部控制栏 -->
  107. <CustomTabbar :show-navbar="showNavbar" :current-page="currentPage" :course-id="courseId" :voice-id="voiceId"
  108. :book-pages="bookPages" :is-text-page="isTextPage" :should-load-audio="shouldLoadAudio"
  109. :is-member="isMember" :current-page-requires-member="currentPageRequiresMember" :page-pay="pagePay"
  110. :is-word-audio-playing="isWordAudioPlaying" @toggle-course-popup="toggleCoursePopup"
  111. @toggle-sound="toggleSound" @go-to-page="goToPage" @previous-page="previousPage" @next-page="nextPage"
  112. @audio-state-change="onAudioStateChange" @highlight-change="onHighlightChange"
  113. @scroll-to-text="onScrollToText" @voice-change-complete="onVoiceChangeComplete"
  114. @voice-change-error="onVoiceChangeError" @page-data-needed="onPageDataNeeded" ref="customTabbar" />
  115. <!-- 课程选择弹出窗 -->
  116. <CoursePopup :style="{ zIndex: 10000 }" :course-list="courseList" :current-course="currentCourse"
  117. :is-reversed="isReversed" @toggle-sort="toggleSort" @select-course="selectCourse" ref="coursePopup" />
  118. <!-- 释义弹出窗 -->
  119. <MeaningPopup :style="{ zIndex: 10000 }" :current-word-meaning="currentWordMeaning"
  120. @close-meaning-popup="closeMeaningPopup" @repeat-word-audio="repeatWordAudio" ref="meaningPopup" />
  121. </view>
  122. </template>
  123. <script>
  124. import AudioControls from './AudioControls.vue'
  125. import CustomTabbar from './components/CustomTabbar.vue'
  126. import CoursePopup from './components/CoursePopup.vue'
  127. import MeaningPopup from './components/MeaningPopup.vue'
  128. import audioManager from '@/utils/audioManager.js'
  129. export default {
  130. components: {
  131. AudioControls,
  132. CustomTabbar,
  133. CoursePopup,
  134. MeaningPopup
  135. },
  136. data() {
  137. return {
  138. isMember: false,
  139. memberId: '',
  140. voiceId: null,
  141. courseId: '',
  142. showNavbar: true,
  143. currentPage: 1,
  144. currentCourse: 1, // 当前课程索引
  145. currentWordMeaning: null, // 当前显示的单词释义
  146. isReversed: false, // 是否倒序显示
  147. // 文本高亮相关 - 由AudioControls组件管理,这里只保留必要的接口
  148. currentHighlightIndex: -1, // 当前高亮的文本索引,用于模板渲染
  149. wordAudioCache: {}, // 單詞語音緩存
  150. // 注意:音频实例现在由audioManager统一管理,不再在组件中维护
  151. isWordAudioPlaying: false, // 是否有单词音频正在播放
  152. // 音频状态相关 - 这些状态现在由AudioControls组件管理
  153. // 保留这些属性用于与AudioControls组件的数据同步
  154. isAudioLoading: false, // 音频是否正在加载
  155. hasAudioData: false, // 是否有音频数据
  156. audioLoadFailed: false, // 音频加载是否失败
  157. // 视频状态相关
  158. videoLoading: false, // 视频是否正在加载
  159. // 滚动相关
  160. scrollTops: [], // 每个页面的scroll-view滚动位置数组
  161. scrollDebounceTimer: null, // 滚动防抖定时器
  162. isScrolling: false, // 是否正在滚动中
  163. // 手动滚动检测相关
  164. isUserTouching: false, // 用户是否正在触摸屏幕
  165. touchStartTime: 0, // 触摸开始时间
  166. touchStartY: 0, // 触摸开始Y坐标
  167. userScrollTimer: null, // 用户滚动检测定时器
  168. courseIdList: [],
  169. bookTitle: '',
  170. courseList: [
  171. ],
  172. // 二维数组 代表每个页面
  173. bookPages: [
  174. ],
  175. // 存储每个页面的标题
  176. pageTitles: [],
  177. // 存储每个页面的type信息
  178. pageTypes: [],
  179. // 存储每个页面的单词释义数据
  180. pageWords: [],
  181. // 存储每个页面的付费状态
  182. pagePay: [],
  183. }
  184. },
  185. computed: {
  186. displayCourseList() {
  187. return this.isReversed ? [...this.courseList].reverse() : this.courseList;
  188. },
  189. // 判断当前页面是否为文字类型
  190. isTextPage() {
  191. // 如果是卡片页面(type为'1'),不显示音频控制栏
  192. if (this.currentPageType === '1') {
  193. return false;
  194. }
  195. const currentPageData = this.bookPages[this.currentPage - 1];
  196. // currentPageData是一个数组 其中的一个元素的type是text就会返回true
  197. return currentPageData && currentPageData.some(item => item.type === 'text');
  198. },
  199. // 判断当前页面是否需要加载音频(包括文本页面和卡片页面)
  200. shouldLoadAudio() {
  201. // 文本页面需要加载音频
  202. if (this.isTextPage) {
  203. return true;
  204. }
  205. // 卡片页面(type为'1')也需要加载音频以支持点击播放
  206. if (this.currentPageType === '1') {
  207. return true;
  208. }
  209. return false;
  210. },
  211. // 动态页面标题
  212. currentPageTitle() {
  213. return this.pageTitles[this.currentPage - 1] || this.bookTitle;
  214. },
  215. // 当前页面类型
  216. currentPageType() {
  217. return this.pageTypes[this.currentPage - 1] || '';
  218. },
  219. // 当前页面的单词释义数据
  220. currentPageWords() {
  221. return this.pageWords[this.currentPage - 1] || [];
  222. },
  223. // 当前页面是否需要会员
  224. currentPageRequiresMember() {
  225. return this.pagePay[this.currentPage - 1] === 'Y';
  226. }
  227. },
  228. // watch: {
  229. // scrollTops: {
  230. // handler(newVal, oldVal) {
  231. // console.log('📊 scrollTops变化:', {
  232. // currentPage: this.currentPage,
  233. // newScrollTops: newVal,
  234. // currentPageScrollTop: newVal[this.currentPage - 1]
  235. // });
  236. // },
  237. // deep: true
  238. // }
  239. // },
  240. methods: {
  241. // 触摸开始事件 - 检测用户开始触摸
  242. onTouchStart(e) {
  243. this.isUserTouching = true;
  244. this.touchStartTime = Date.now();
  245. this.touchStartY = e.touches[0].pageY;
  246. // 清除之前的用户滚动定时器
  247. if (this.userScrollTimer) {
  248. clearTimeout(this.userScrollTimer);
  249. this.userScrollTimer = null;
  250. }
  251. console.log('👆 用户开始触摸屏幕');
  252. },
  253. // 触摸移动事件 - 检测用户滚动操作
  254. onTouchMove(e) {
  255. if (!this.isUserTouching) return;
  256. const currentY = e.touches[0].pageY;
  257. const deltaY = Math.abs(currentY - this.touchStartY);
  258. // 如果移动距离超过阈值,认为是滚动操作
  259. if (deltaY > 10) {
  260. // 如果当前正在自动滚动,立即停止
  261. if (this.isScrolling) {
  262. console.log('🛑 检测到用户手动滚动,停止自动滚动');
  263. this.isScrolling = false;
  264. // 清除滚动防抖定时器
  265. if (this.scrollDebounceTimer) {
  266. clearTimeout(this.scrollDebounceTimer);
  267. this.scrollDebounceTimer = null;
  268. }
  269. }
  270. }
  271. },
  272. // 触摸结束事件 - 用户停止触摸
  273. onTouchEnd(e) {
  274. this.isUserTouching = false;
  275. // 设置一个短暂的延迟,在用户停止触摸后的一段时间内仍然阻止自动滚动
  276. // 这样可以避免用户刚停止滚动就立即触发自动滚动
  277. this.userScrollTimer = setTimeout(() => {
  278. console.log('✋ 用户滚动操作结束,允许自动滚动');
  279. this.userScrollTimer = null;
  280. }, 1000); // 1秒后允许自动滚动
  281. console.log('👆 用户停止触摸屏幕');
  282. },
  283. // 检查是否应该阻止自动滚动
  284. shouldPreventAutoScroll() {
  285. return this.isUserTouching || this.userScrollTimer !== null;
  286. },
  287. // 处理scroll-view滚动事件
  288. onScroll(e) {
  289. // 更新当前页面的滚动位置
  290. const scrollTop = e.detail.scrollTop;
  291. const currentPageIndex = this.currentPage - 1;
  292. const previousScrollTop = this.scrollTops[currentPageIndex] || 0;
  293. // 只有当滚动位置发生显著变化时才更新
  294. if (Math.abs(previousScrollTop - scrollTop) > 5) {
  295. // 检测是否为手动滚动(如果正在自动滚动中,但滚动位置与预期不符,则认为是手动滚动)
  296. if (this.isScrolling) {
  297. // 如果滚动差异很大,可能是用户手动滚动,中断自动滚动状态
  298. const scrollDifference = Math.abs(previousScrollTop - scrollTop);
  299. if (scrollDifference > 100) { // 大幅度滚动,很可能是手动操作
  300. console.log('🖐️ 检测到手动滚动,中断自动滚动状态');
  301. this.isScrolling = false;
  302. }
  303. }
  304. this.$set(this.scrollTops, currentPageIndex, scrollTop);
  305. }
  306. },
  307. // 视频事件处理方法
  308. onVideoLoadStart() {
  309. this.videoLoading = true;
  310. },
  311. onVideoCanPlay() {
  312. this.videoLoading = false;
  313. },
  314. onVideoError() {
  315. this.videoLoading = false;
  316. uni.showToast({
  317. title: '视频加载失败',
  318. icon: 'none',
  319. duration: 2000
  320. });
  321. },
  322. // 獲取用戶會員信息 判斷是否和傳參傳過來的會員id相同
  323. async getMemberInfo() {
  324. const memberRes = await this.$api.member.getUserMemberInfo()
  325. if (memberRes.code === 200) {
  326. this.isMember = memberRes.result.map(item => item.memberId).includes(this.memberId)
  327. }
  328. },
  329. // 处理AudioControls组件的事件
  330. onAudioStateChange(audioState) {
  331. // 更新高亮状态
  332. this.currentHighlightIndex = audioState.currentHighlightIndex;
  333. // 更新音频加载状态(用于控制UI显示)
  334. if (audioState.hasOwnProperty('isLoading')) {
  335. this.isAudioLoading = audioState.isLoading;
  336. }
  337. // 更新音频数据状态
  338. if (audioState.hasOwnProperty('hasAudioData')) {
  339. this.hasAudioData = audioState.hasAudioData;
  340. }
  341. // 更新音频加载失败状态
  342. if (audioState.hasOwnProperty('audioLoadFailed')) {
  343. this.audioLoadFailed = audioState.audioLoadFailed;
  344. }
  345. },
  346. // 处理页面数据需要重新加载的事件
  347. async onPageDataNeeded(pageNumber) {
  348. console.log('收到页面数据需要重新加载的请求,页面:', pageNumber);
  349. // 如果页面数据不存在或为空,重新获取
  350. if (!this.bookPages || this.bookPages.length === 0 || !this.bookPages[pageNumber - 1]) {
  351. console.log('页面数据不存在,重新获取页面数据');
  352. try {
  353. await this.getBookPages();
  354. console.log('页面数据重新获取完成');
  355. // 页面数据更新后,AudioControls组件的bookPages监听器会自动触发音频获取
  356. // 无需手动调用getCurrentPageAudio,避免重复调用
  357. } catch (error) {
  358. console.error('重新获取页面数据失败:', error);
  359. }
  360. } else {
  361. console.log('页面数据已存在,无需重新获取');
  362. }
  363. },
  364. // 处理音色切换完成事件
  365. onVoiceChangeComplete(data) {
  366. // 可以在这里添加一些UI反馈,比如显示切换成功的提示
  367. if (data.hasAudioData) {
  368. } else {
  369. }
  370. // 如果启用了预加载所有页面
  371. if (data.preloadAllPages) {
  372. // 可以显示一个提示,告诉用户正在后台加载
  373. uni.showToast({
  374. title: '正在加载新音色...',
  375. icon: 'loading',
  376. duration: 2000
  377. });
  378. }
  379. },
  380. // 处理音色切换错误事件
  381. onVoiceChangeError(error) {
  382. console.error('音色切换失败:', error);
  383. // 可以在这里显示错误提示给用户
  384. uni.showToast({
  385. title: '音色切换失败,请重试',
  386. icon: 'none',
  387. duration: 2000
  388. });
  389. },
  390. // 处理音频切换时的自动滚动
  391. // onScrollToText(refName) {
  392. // try {
  393. // console.log('🎯 onScrollToText 被调用:', refName);
  394. //
  395. // // 调用scrollTo插件
  396. // this.$scrollTo(refName);
  397. //
  398. // } catch (error) {
  399. // console.error('❌ onScrollToText 执行失败:', error);
  400. // }
  401. // },
  402. // 处理文本点击事件
  403. handleTextClick(textContent, item, pageIndex) {
  404. // console.log('🎯 ===== 文本点击事件开始 =====');
  405. // console.log('📝 点击文本:', textContent);
  406. // console.log('📄 textContent类型:', typeof textContent);
  407. // console.log('❓ textContent是否为undefined:', textContent === undefined);
  408. // console.log('📦 完整item对象:', item);
  409. // console.log('📝 item.content:', item ? item.content : 'item为空');
  410. // console.log('📖 当前页面索引:', this.currentPage);
  411. // console.log('👆 点击的页面索引:', pageIndex);
  412. // console.log('📊 当前页面类型:', this.currentPageType);
  413. // console.log('📄 是否为文本页面:', this.isTextPage);
  414. // console.log('📋 当前页面数据:', this.bookPages[this.currentPage - 1]);
  415. // console.log('📏 页面数据长度:', this.bookPages[this.currentPage - 1] ? this.bookPages[this.currentPage - 1].length : '页面不存在');
  416. // 检查音频播放状态
  417. // console.log('🎵 ===== 音频状态检查 =====');
  418. // console.log(' isWordAudioPlaying:', this.isWordAudioPlaying);
  419. // console.log(' currentWordAudio存在:', !!this.currentWordAudio);
  420. // console.log(' currentWordMeaning存在:', !!this.currentWordMeaning);
  421. if (this.isWordAudioPlaying) {
  422. // console.log('⚠️ 检测到单词音频正在播放状态,这可能会阻止句子音频播放');
  423. // console.log('🔄 尝试重置音频播放状态...');
  424. this.isWordAudioPlaying = false;
  425. // console.log('✅ 音频播放状态已重置');
  426. }
  427. // 检查是否点击的是当前页面
  428. if (pageIndex !== undefined && pageIndex !== this.currentPage - 1) {
  429. console.warn('⚠️ 点击的不是当前页面,忽略点击事件');
  430. // console.log(` 期望页面: ${this.currentPage - 1}, 点击页面: ${pageIndex}`);
  431. return;
  432. }
  433. // 验证参数有效性
  434. if (!item) {
  435. console.error('❌ handleTextClick: item参数为空');
  436. uni.showToast({
  437. title: '数据错误,请刷新页面',
  438. icon: 'none'
  439. });
  440. return;
  441. }
  442. // 如果textContent为undefined,尝试从item中获取
  443. if (!textContent && item && item.content) {
  444. textContent = item.content;
  445. }
  446. // 最终验证textContent
  447. if (!textContent || typeof textContent !== 'string' || textContent.trim() === '') {
  448. console.error('❌ handleTextClick: 无效的文本内容', textContent);
  449. uni.showToast({
  450. title: '文本内容无效',
  451. icon: 'none'
  452. });
  453. return;
  454. }
  455. if (!this.$refs.customTabbar) {
  456. console.error('❌ customTabbar引用不存在');
  457. uni.showToast({
  458. title: '音频控制组件未准备好',
  459. icon: 'none'
  460. });
  461. return;
  462. }
  463. // console.log(' audioControls存在:', !!this.$refs.customTabbar.$refs.audioControls);
  464. if (!this.$refs.customTabbar.$refs.audioControls) {
  465. console.error('❌ audioControls引用不存在');
  466. uni.showToast({
  467. title: '音频控制组件未准备好',
  468. icon: 'none'
  469. });
  470. return;
  471. }
  472. // 检查当前页面是否为文本页面或卡片页面
  473. // 卡片页面(type为'1')现在也支持整句音频播放
  474. // 特别针对划线重点页面的调试
  475. if (this.currentPageType === '1') {
  476. }
  477. if (!this.isTextPage && this.currentPageType !== '1') {
  478. console.warn('⚠️ 当前页面不是文本页面或卡片页面');
  479. uni.showToast({
  480. title: '当前页面不支持音频播放',
  481. icon: 'none'
  482. });
  483. return;
  484. }
  485. // 获取音频控制组件实例
  486. const audioControls = this.$refs.customTabbar.$refs.audioControls;
  487. // 检查音频是否正在加载中
  488. if (audioControls.isAudioLoading) {
  489. uni.showToast({
  490. title: '音频正在加载中,请稍后再试',
  491. icon: 'loading',
  492. duration: 1500
  493. });
  494. // 等待音频加载完成后自动播放
  495. const checkAndPlay = () => {
  496. if (!audioControls.isAudioLoading && audioControls.currentPageAudios.length > 0) {
  497. const success = audioControls.playSpecificAudio(textContent);
  498. if (!success) {
  499. console.error('❌ 音频加载完成后播放失败');
  500. }
  501. } else if (!audioControls.isAudioLoading) {
  502. console.error('❌ 音频加载完成但没有音频数据');
  503. uni.showToast({
  504. title: '当前页面没有音频内容',
  505. icon: 'none'
  506. });
  507. } else {
  508. // 继续等待
  509. setTimeout(checkAndPlay, 500);
  510. }
  511. };
  512. // 延迟检查,给音频加载一些时间
  513. setTimeout(checkAndPlay, 500);
  514. return;
  515. }
  516. // 检查是否有音频数据
  517. if (!audioControls.currentPageAudios || audioControls.currentPageAudios.length === 0) {
  518. console.warn('⚠️ 当前页面没有音频数据,尝试重新加载');
  519. uni.showToast({
  520. title: '正在重新加载音频...',
  521. icon: 'loading'
  522. });
  523. // 尝试重新加载音频
  524. audioControls.getCurrentPageAudio();
  525. // 等待重新加载完成后播放
  526. const retryPlay = () => {
  527. if (!audioControls.isAudioLoading && audioControls.currentPageAudios.length > 0) {
  528. const success = audioControls.playSpecificAudio(textContent);
  529. if (!success) {
  530. console.error('❌ 音频重新加载后播放失败');
  531. }
  532. } else if (!audioControls.isAudioLoading) {
  533. console.error('❌ 音频重新加载失败');
  534. uni.showToast({
  535. title: '音频加载失败,请检查网络连接',
  536. icon: 'none'
  537. });
  538. } else {
  539. // 继续等待
  540. setTimeout(retryPlay, 500);
  541. }
  542. };
  543. setTimeout(retryPlay, 1500);
  544. return;
  545. }
  546. // 调用AudioControls组件的播放指定音频方法
  547. const success = audioControls.playSpecificAudio(textContent);
  548. // console.log('🎵 playSpecificAudio 返回结果:', success);
  549. if (success) {
  550. // console.log('✅ 成功播放指定音频段落');
  551. } else {
  552. console.error('❌ 播放指定音频段落失败');
  553. // console.log('💡 失败可能原因:');
  554. // console.log(' 1. 文本内容与音频数据不匹配');
  555. // console.log(' 2. 音频数据尚未加载完成');
  556. // console.log(' 3. 音频文件路径错误或文件损坏');
  557. // console.log(' 4. 网络连接问题');
  558. }
  559. // console.log('🎯 ===== 文本点击事件结束 =====');
  560. },
  561. onHighlightChange(highlightData) {
  562. // 兼容旧格式(直接传递索引)和新格式(传递对象)
  563. if (typeof highlightData === 'number') {
  564. // 旧格式:直接是索引
  565. this.currentHighlightIndex = highlightData;
  566. } else if (typeof highlightData === 'object' && highlightData !== null) {
  567. // 新格式:包含详细信息的对象
  568. this.currentHighlightIndex = highlightData.highlightIndex;
  569. // 可以在这里处理分段音频的额外信息
  570. if (highlightData.isSegmented) {
  571. // console.log('分段音频高亮:', {
  572. // highlightIndex: highlightData.highlightIndex,
  573. // segmentIndex: highlightData.segmentIndex,
  574. // startIndex: highlightData.startIndex,
  575. // endIndex: highlightData.endIndex,
  576. // currentText: highlightData.currentText
  577. // });
  578. }
  579. } else {
  580. // 清除高亮
  581. this.currentHighlightIndex = -1;
  582. }
  583. },
  584. // 处理滚动到高亮文本
  585. onScrollToText(scrollData) {
  586. // 检查是否应该阻止自动滚动(用户正在手动操作)
  587. if (this.shouldPreventAutoScroll()) {
  588. console.log('🚫 用户正在手动滚动,跳过自动滚动到文本');
  589. return;
  590. }
  591. // 防抖处理:如果正在滚动中,清除之前的定时器
  592. if (this.scrollDebounceTimer) {
  593. clearTimeout(this.scrollDebounceTimer);
  594. }
  595. this.scrollDebounceTimer = setTimeout(() => {
  596. // 再次检查是否应该阻止自动滚动
  597. if (this.shouldPreventAutoScroll()) {
  598. console.log('🚫 防抖延迟后检测到用户手动滚动,跳过自动滚动到文本');
  599. return;
  600. }
  601. this.performScrollToText(scrollData);
  602. }, 100); // 100ms防抖延迟
  603. },
  604. // 执行滚动到高亮文本的具体逻辑
  605. performScrollToText(scrollData) {
  606. // 最终检查:如果用户正在手动操作,直接返回
  607. if (this.shouldPreventAutoScroll()) {
  608. console.log('🚫 执行滚动前检测到用户手动操作,取消自动滚动');
  609. return;
  610. }
  611. // 确保在任何情况下都能重置滚动状态
  612. const resetScrollingState = () => {
  613. this.isScrolling = false;
  614. console.log('🔄 滚动状态已重置');
  615. };
  616. // 设置安全超时,确保状态不会永久卡住
  617. const safetyTimeout = setTimeout(() => {
  618. if (this.isScrolling) {
  619. console.warn('⚠️ 滚动状态安全超时,强制重置');
  620. resetScrollingState();
  621. }
  622. }, 2000); // 2秒安全超时
  623. if (!scrollData || typeof scrollData.highlightIndex !== 'number' || scrollData.highlightIndex < 0) {
  624. console.warn('滚动数据无效:', scrollData);
  625. clearTimeout(safetyTimeout);
  626. return;
  627. }
  628. // 确保在当前页面
  629. if (scrollData.currentPage && scrollData.currentPage !== this.currentPage) {
  630. console.warn('页面不匹配,跳过滚动:', {
  631. scrollDataPage: scrollData.currentPage,
  632. currentPage: this.currentPage
  633. });
  634. clearTimeout(safetyTimeout);
  635. return;
  636. }
  637. // 如果正在滚动中,跳过本次滚动
  638. if (this.isScrolling) {
  639. console.warn('正在滚动中,跳过本次滚动');
  640. clearTimeout(safetyTimeout);
  641. return;
  642. }
  643. // 构建元素选择器
  644. let selector = '';
  645. if (scrollData.isSegmented && typeof scrollData.segmentIndex === 'number') {
  646. // 分段音频:使用分段索引
  647. selector = `#text-segment-${scrollData.segmentIndex}`;
  648. } else {
  649. // 普通音频:需要找到对应的文本元素
  650. // originalTextIndex是指向原始页面数据中的索引,需要映射到实际的DOM元素
  651. const targetItemIndex = this.findTextItemIndex(scrollData.highlightIndex);
  652. if (targetItemIndex !== -1) {
  653. selector = `#text-${targetItemIndex}`;
  654. } else {
  655. console.warn('无法找到对应的文本元素索引:', scrollData.highlightIndex);
  656. selector = `#text-${scrollData.highlightIndex}`; // 备用方案
  657. }
  658. }
  659. console.log('开始滚动到文本:', { selector, scrollData });
  660. // 标记正在滚动
  661. this.isScrolling = true;
  662. // 等待DOM更新后再查找元素
  663. this.$nextTick(() => {
  664. // 使用uni.createSelectorQuery获取元素位置
  665. const query = uni.createSelectorQuery().in(this);
  666. // 获取scroll-view容器的位置信息
  667. query.select('.scroll-container').boundingClientRect();
  668. // 获取目标元素的位置信息
  669. query.select(selector).boundingClientRect();
  670. query.exec((res) => {
  671. // 清除安全超时
  672. clearTimeout(safetyTimeout);
  673. const scrollViewRect = res[0];
  674. const targetRect = res[1];
  675. console.log('查询结果:', {
  676. scrollViewRect: scrollViewRect ? '找到' : '未找到',
  677. targetRect: targetRect ? '找到' : '未找到',
  678. selector
  679. });
  680. if (scrollViewRect && targetRect) {
  681. // 计算目标元素相对于scroll-view的位置
  682. const currentScrollTop = this.scrollTops[this.currentPage - 1] || 0;
  683. const targetOffsetTop = targetRect.top - scrollViewRect.top + currentScrollTop;
  684. // 计算滚动位置,让目标元素在屏幕上方1/4处(更好的阅读体验)
  685. const screenHeight = uni.getSystemInfoSync().windowHeight;
  686. const targetScrollTop = targetOffsetTop - screenHeight / 4;
  687. // 更新scroll-view的滚动位置
  688. const finalScrollTop = Math.max(0, targetScrollTop);
  689. // 检查是否需要滚动(避免不必要的滚动)
  690. const currentScroll = this.scrollTops[this.currentPage - 1] || 0;
  691. const scrollDifference = Math.abs(finalScrollTop - currentScroll);
  692. if (scrollDifference > 30) { // 降低滚动阈值,提高响应性
  693. this.$set(this.scrollTops, this.currentPage - 1, finalScrollTop);
  694. // 滚动完成后重置状态
  695. setTimeout(() => {
  696. resetScrollingState();
  697. }, 300); // 稍微减少等待时间
  698. console.log('✅ 滚动到高亮文本:', {
  699. selector,
  700. targetOffsetTop,
  701. finalScrollTop,
  702. currentPage: this.currentPage,
  703. scrollDifference
  704. });
  705. } else {
  706. // 不需要滚动,立即重置状态
  707. resetScrollingState();
  708. console.log('📍 目标已在视野内,无需滚动');
  709. }
  710. } else {
  711. console.error('❌ 未找到目标元素或scroll-view:', {
  712. selector,
  713. scrollViewFound: !!scrollViewRect,
  714. targetFound: !!targetRect,
  715. currentPage: this.currentPage,
  716. highlightIndex: scrollData.highlightIndex
  717. });
  718. // 尝试备用方案:直接滚动到页面顶部附近
  719. if (!targetRect) {
  720. console.log('🔄 尝试备用滚动方案');
  721. const fallbackScrollTop = scrollData.highlightIndex * 100; // 简单估算位置
  722. this.$set(this.scrollTops, this.currentPage - 1, fallbackScrollTop);
  723. setTimeout(() => {
  724. resetScrollingState();
  725. }, 300);
  726. } else {
  727. // 立即重置状态
  728. resetScrollingState();
  729. }
  730. }
  731. });
  732. });
  733. },
  734. // 查找文本元素在页面中的实际索引
  735. findTextItemIndex(originalTextIndex) {
  736. const currentPageData = this.bookPages[this.currentPage - 1];
  737. if (!currentPageData || !Array.isArray(currentPageData)) {
  738. return -1;
  739. }
  740. let textCount = 0;
  741. for (let i = 0; i < currentPageData.length; i++) {
  742. const item = currentPageData[i];
  743. if (item && item.type === 'text' && item.content) {
  744. if (textCount === originalTextIndex) {
  745. return i; // 返回在页面数组中的实际索引
  746. }
  747. textCount++;
  748. }
  749. }
  750. return -1; // 未找到
  751. },
  752. // 获取音色列表 拿第一个做默认的音色id
  753. async getVoiceList() {
  754. const voiceRes = await this.$api.music.list()
  755. if (voiceRes.code === 200) {
  756. // console.log('音色列表API返回:', voiceRes.result);
  757. // console.log('第一个音色数据:', voiceRes.result[0]);
  758. this.voiceId = Number(voiceRes.result[0].voiceType)
  759. // console.log('获取默认音色ID:', this.voiceId, '类型:', typeof this.voiceId);
  760. // 同步默认音色设置到audioManager
  761. audioManager.setGlobalVoiceId(this.voiceId);
  762. }
  763. },
  764. toggleNavbar() {
  765. this.showNavbar = !this.showNavbar
  766. },
  767. goBack() {
  768. uni.navigateBack()
  769. },
  770. toggleCoursePopup() {
  771. if (this.$refs.coursePopup) {
  772. this.$refs.coursePopup.open()
  773. }
  774. // console.log('123123123');
  775. },
  776. toggleSort() {
  777. this.isReversed = !this.isReversed
  778. },
  779. selectCourse(courseId) {
  780. this.currentCourse = courseId
  781. // 这里可以添加切换课程的逻辑
  782. // console.log('选择课程:', courseId)
  783. this.getCourseList(courseId)
  784. },
  785. showWordMeaning() {
  786. if (this.$refs.meaningPopup) {
  787. this.$refs.meaningPopup.open()
  788. }
  789. },
  790. closeMeaningPopup() {
  791. this.currentWordMeaning = null;
  792. // 重置音频播放状态,确保后续句子点击能正常播放
  793. if (this.isWordAudioPlaying) {
  794. this.isWordAudioPlaying = false;
  795. // 如果有正在播放的音频,停止它
  796. if (this.currentWordAudio) {
  797. try {
  798. this.currentWordAudio.pause();
  799. this.currentWordAudio.destroy();
  800. } catch (error) {
  801. }
  802. this.currentWordAudio = null;
  803. }
  804. }
  805. },
  806. // 将英文句子分割成单词数组
  807. splitEnglishSentence(sentence) {
  808. // 使用正则表达式分割句子,保留标点符号
  809. const tokens = sentence.match(/\b\w+\b|[^\w\s]/g) || [];
  810. return tokens.map((token, index) => ({
  811. text: token,
  812. index: index,
  813. isWord: /\b\w+\b/.test(token), // 判断是否为单词
  814. hasDefinition: false // 是否有释义,稍后会设置
  815. }));
  816. },
  817. // 查找单词释义
  818. findWordDefinition(word) {
  819. const currentPageWords = this.pageWords[this.currentPage - 1] || [];
  820. // 不区分大小写匹配
  821. return currentPageWords.find(wordData =>
  822. wordData.word.toLowerCase() === word.toLowerCase()
  823. );
  824. },
  825. // 处理中文文本,标记重点词汇
  826. processChineseText(text) {
  827. const currentPageWords = this.pageWords[this.currentPage - 1] || [];
  828. if (!text || currentPageWords.length === 0) {
  829. return [{ text: text, isKeyword: false, keywordData: null }];
  830. }
  831. // 创建一个数组来存储处理后的文本片段
  832. const segments = [];
  833. let currentIndex = 0;
  834. // 按照重点词汇的长度排序,优先匹配较长的词汇
  835. const sortedWords = [...currentPageWords].sort((a, b) => b.word.length - a.word.length);
  836. while (currentIndex < text.length) {
  837. let matched = false;
  838. // 尝试匹配重点词汇
  839. for (const wordData of sortedWords) {
  840. const keyword = wordData.word;
  841. if (text.substr(currentIndex, keyword.length) === keyword) {
  842. // 找到匹配的重点词汇
  843. segments.push({
  844. text: keyword,
  845. isKeyword: true,
  846. keywordData: wordData
  847. });
  848. currentIndex += keyword.length;
  849. matched = true;
  850. break;
  851. }
  852. }
  853. if (!matched) {
  854. // 没有匹配到重点词汇,添加单个字符
  855. segments.push({
  856. text: text[currentIndex],
  857. isKeyword: false,
  858. keywordData: null
  859. });
  860. currentIndex++;
  861. }
  862. }
  863. // 合并相邻的非重点词汇片段
  864. const mergedSegments = [];
  865. let currentSegment = null;
  866. for (const segment of segments) {
  867. if (segment.isKeyword) {
  868. // 如果当前有未完成的非重点词汇片段,先添加它
  869. if (currentSegment) {
  870. mergedSegments.push(currentSegment);
  871. currentSegment = null;
  872. }
  873. // 添加重点词汇
  874. mergedSegments.push(segment);
  875. } else {
  876. // 非重点词汇,合并到当前片段
  877. if (currentSegment) {
  878. currentSegment.text += segment.text;
  879. } else {
  880. currentSegment = { ...segment };
  881. }
  882. }
  883. }
  884. // 添加最后的非重点词汇片段
  885. if (currentSegment) {
  886. mergedSegments.push(currentSegment);
  887. }
  888. return mergedSegments;
  889. },
  890. // 初始化audioManager事件监听
  891. initAudioManagerListeners() {
  892. // 监听音频播放状态变化
  893. audioManager.on('play', (data) => {
  894. if (data?.audioType === 'word') {
  895. this.isWordAudioPlaying = true;
  896. }
  897. });
  898. audioManager.on('pause', (data) => {
  899. if (data?.audioType === 'word') {
  900. this.isWordAudioPlaying = false;
  901. }
  902. });
  903. audioManager.on('ended', (data) => {
  904. if (data?.audioType === 'word') {
  905. this.isWordAudioPlaying = false;
  906. }
  907. });
  908. audioManager.on('error', (data) => {
  909. if (data?.audioType === 'word') {
  910. this.isWordAudioPlaying = false;
  911. uni.showToast({
  912. title: '語音播放失敗',
  913. icon: 'none'
  914. });
  915. }
  916. });
  917. },
  918. async playWordAudio(word) {
  919. try {
  920. console.log('🎵 开始播放单词音频:', word);
  921. // 🎯 使用audioManager的全局音色设置
  922. const globalVoiceId = audioManager.getGlobalVoiceId();
  923. const voiceIdToUse = globalVoiceId || this.voiceId;
  924. if (!voiceIdToUse || voiceIdToUse === '' || voiceIdToUse === null || voiceIdToUse === undefined) {
  925. console.warn('⚠️ 音色ID未设置,无法播放音频');
  926. uni.showToast({
  927. title: '音色未加载,请稍后重试',
  928. icon: 'none',
  929. duration: 2000
  930. });
  931. return;
  932. }
  933. console.log('🎵 使用音色ID:', voiceIdToUse, '播放文本:', word);
  934. // 調用語音轉換API
  935. const audioRes = await this.$api.music.textToVoice({
  936. text: word,
  937. voiceType: voiceIdToUse
  938. });
  939. console.log('🎵 API响应:', audioRes);
  940. // 檢查響應並播放音頻
  941. if (audioRes && audioRes.result && audioRes.result.url) {
  942. console.log('✅ 获取到音频URL:', audioRes.result.url);
  943. // 使用audioManager播放音频,应用全局语速设置
  944. await audioManager.playAudio(audioRes.result.url, 'word', {
  945. playbackRate: audioManager.getGlobalPlaybackRate()
  946. });
  947. } else {
  948. console.error('❌ API响应无效:', audioRes);
  949. uni.showToast({
  950. title: '語音播放失敗',
  951. icon: 'none'
  952. });
  953. }
  954. } catch (error) {
  955. console.error('❌ 播放单词语音异常:', error);
  956. uni.showToast({
  957. title: '語音播放失敗',
  958. icon: 'none'
  959. });
  960. }
  961. },
  962. // 重複播放單詞語音(用於釋義彈窗中的揚聲器圖標)
  963. repeatWordAudio() {
  964. if (this.currentWordMeaning && this.currentWordMeaning.word) {
  965. // 将单词和解释合并后播放音频
  966. const combinedText = `${this.currentWordMeaning.word}${this.currentWordMeaning.meaning || ''}`;
  967. this.playWordAudio(combinedText);
  968. } else {
  969. console.warn('沒有當前單詞可以播放');
  970. }
  971. },
  972. // 处理单词点击事件
  973. handleWordClick(word) {
  974. const definition = this.findWordDefinition(word);
  975. if (definition) {
  976. this.currentWordMeaning = {
  977. word: definition.word,
  978. phonetic: definition.soundmark || '',
  979. partOfSpeech: '', // 可以根据需要添加词性
  980. meaning: definition.paraphrase || '',
  981. knowledgeGain: definition.knowledge || '',
  982. image: definition.image || ''
  983. };
  984. // 将单词和解释合并后播放音频
  985. const combinedText = `${word}${definition.paraphrase || ''}`;
  986. this.playWordAudio(combinedText);
  987. this.showWordMeaning();
  988. } else {
  989. // 如果没有释义,只播放单词
  990. if (word) {
  991. this.playWordAudio(word);
  992. } else {
  993. }
  994. }
  995. },
  996. // 处理中文重点词汇点击事件
  997. handleChineseKeywordClick(keywordData) {
  998. if (keywordData) {
  999. this.currentWordMeaning = {
  1000. word: keywordData.word,
  1001. phonetic: keywordData.soundmark || '',
  1002. partOfSpeech: '', // 可以根据需要添加词性
  1003. meaning: keywordData.paraphrase || '',
  1004. knowledgeGain: keywordData.knowledge || '',
  1005. image: keywordData.image || ''
  1006. };
  1007. // 将词汇和解释合并后播放音频
  1008. const combinedText = `${keywordData.word}${keywordData.paraphrase || ''}`;
  1009. this.playWordAudio(combinedText);
  1010. this.showWordMeaning();
  1011. } else {
  1012. }
  1013. },
  1014. // 计算音频总时长
  1015. async calculateTotalDuration() {
  1016. let totalDuration = 0;
  1017. for (let i = 0; i < this.currentPageAudios.length; i++) {
  1018. const audio = this.currentPageAudios[i];
  1019. // 優先使用API返回的時長信息
  1020. if (audio.duration && audio.duration > 0) {
  1021. totalDuration += audio.duration;
  1022. continue;
  1023. }
  1024. // 如果沒有API時長信息,嘗試獲取音頻時長
  1025. try {
  1026. const duration = await this.getAudioDuration(audio.url);
  1027. audio.duration = duration;
  1028. totalDuration += duration;
  1029. } catch (error) {
  1030. console.error('获取音频时长失败:', error);
  1031. // 如果无法获取时长,根據文字長度估算(更精確的估算)
  1032. const textLength = audio.text.length;
  1033. // 假設每分鐘可以讀150-200個字符,這裡用180作為平均值
  1034. const estimatedDuration = Math.max(2, textLength / 3); // 每3個字符約1秒
  1035. audio.duration = estimatedDuration;
  1036. totalDuration += estimatedDuration;
  1037. console.log(`估算音頻時長 ${i + 1}:`, estimatedDuration, '秒 (文字長度:', textLength, ')');
  1038. }
  1039. }
  1040. this.totalTime = totalDuration;
  1041. },
  1042. // 获取音频时长
  1043. getAudioDuration(audioUrl) {
  1044. return new Promise((resolve, reject) => {
  1045. const audio = uni.createInnerAudioContext();
  1046. audio.src = audioUrl;
  1047. let resolved = false;
  1048. // 监听音频加载完成事件
  1049. audio.onCanplay(() => {
  1050. if (!resolved && audio.duration && audio.duration > 0) {
  1051. resolved = true;
  1052. resolve(audio.duration);
  1053. audio.destroy();
  1054. }
  1055. });
  1056. // 监听音频元数据加载完成事件
  1057. audio.onLoadedmetadata = () => {
  1058. if (!resolved && audio.duration && audio.duration > 0) {
  1059. resolved = true;
  1060. resolve(audio.duration);
  1061. audio.destroy();
  1062. }
  1063. };
  1064. // 监听音频时长更新事件
  1065. audio.onDurationChange = () => {
  1066. if (!resolved && audio.duration && audio.duration > 0) {
  1067. resolved = true;
  1068. resolve(audio.duration);
  1069. audio.destroy();
  1070. }
  1071. };
  1072. // 如果以上方法都無法獲取時長,嘗試播放一小段來獲取時長
  1073. audio.onPlay(() => {
  1074. if (!resolved) {
  1075. setTimeout(() => {
  1076. if (!resolved && audio.duration && audio.duration > 0) {
  1077. resolved = true;
  1078. resolve(audio.duration);
  1079. audio.destroy();
  1080. }
  1081. }, 100); // 播放100ms後檢查時長
  1082. }
  1083. });
  1084. audio.onError((error) => {
  1085. console.error('音频加载失败:', error);
  1086. if (!resolved) {
  1087. resolved = true;
  1088. reject(error);
  1089. audio.destroy();
  1090. }
  1091. });
  1092. // 設置較長的超時時間,並在超時前嘗試播放
  1093. setTimeout(() => {
  1094. if (!resolved) {
  1095. audio.play();
  1096. }
  1097. }, 1000);
  1098. // 最終超時處理
  1099. setTimeout(() => {
  1100. if (!resolved) {
  1101. console.warn('獲取音頻時長超時,使用默認值');
  1102. resolved = true;
  1103. reject(new Error('获取音频时长超时'));
  1104. audio.destroy();
  1105. }
  1106. }, 5000);
  1107. });
  1108. },
  1109. // 音频控制方法 - 这些方法现在由AudioControls组件处理
  1110. // 保留一些简单的接口方法用于与AudioControls组件通信
  1111. // 判断当前文本是否应该高亮 - 这个方法需要保留,因为它用于模板渲染
  1112. isTextHighlighted(page, index) {
  1113. // 只有当前页面且是文本类型才可能高亮
  1114. if (page !== this.bookPages[this.currentPage - 1]) return false;
  1115. // 计算当前页面中text类型元素的索引
  1116. let textIndex = 0;
  1117. for (let i = 0; i <= index; i++) {
  1118. if (page[i].type === 'text') {
  1119. if (i === index) {
  1120. const shouldHighlight = textIndex === this.currentHighlightIndex;
  1121. if (shouldHighlight) {
  1122. }
  1123. return shouldHighlight;
  1124. }
  1125. textIndex++;
  1126. }
  1127. }
  1128. return false;
  1129. },
  1130. // 判断划线重点卡片中的文本是否应该高亮
  1131. isCardTextHighlighted(page, index) {
  1132. // 只有当前页面且是文本类型才可能高亮
  1133. if (page !== this.bookPages[this.currentPage - 1]) return false;
  1134. // 计算当前页面中text类型元素的索引
  1135. let textIndex = 0;
  1136. for (let i = 0; i <= index; i++) {
  1137. if (page[i].type === 'text') {
  1138. if (i === index) {
  1139. return textIndex === this.currentHighlightIndex;
  1140. }
  1141. textIndex++;
  1142. }
  1143. }
  1144. return false;
  1145. },
  1146. async previousPage() {
  1147. if (this.currentPage > 1) {
  1148. this.currentPage--;
  1149. // 获取对应页面的数据(如果还没有获取过)
  1150. if (this.courseIdList[this.currentPage - 1] && this.bookPages[this.currentPage - 1].length === 0) {
  1151. await this.getBookPages(this.courseIdList[this.currentPage - 1]);
  1152. }
  1153. }
  1154. },
  1155. async nextPage() {
  1156. if (this.currentPage < this.bookPages.length) {
  1157. this.currentPage++;
  1158. // 获取对应页面的数据(如果还没有获取过)
  1159. if (this.courseIdList[this.currentPage - 1] && this.bookPages[this.currentPage - 1].length === 0) {
  1160. await this.getBookPages(this.courseIdList[this.currentPage - 1]);
  1161. }
  1162. }
  1163. },
  1164. toggleSound() {
  1165. // 检查是否正在加载音频,如果是则阻止音色切换
  1166. if (this.isAudioLoading) {
  1167. uni.showToast({
  1168. title: '音频加载中,请稍后再试',
  1169. icon: 'none',
  1170. duration: 2000
  1171. });
  1172. return;
  1173. }
  1174. // 检查AudioControls组件是否正在加载音频
  1175. if (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls && this.$refs.customTabbar.$refs.audioControls.isAudioLoading) {
  1176. uni.showToast({
  1177. title: '音频加载中,请稍后再试',
  1178. icon: 'none',
  1179. duration: 2000
  1180. });
  1181. return;
  1182. }
  1183. console.log('音色切换')
  1184. uni.navigateTo({
  1185. url: '/subPages/home/music?voiceId=' + this.voiceId
  1186. })
  1187. },
  1188. unlockBook() {
  1189. console.log('解锁全书')
  1190. // 这里可以跳转到会员页面或者调用解锁接口
  1191. uni.navigateTo({
  1192. url: '/subPages/member/recharge'
  1193. })
  1194. },
  1195. async goToPage(page) {
  1196. this.currentPage = page
  1197. console.log('跳转到页面:', page)
  1198. // 获取对应页面的数据(如果还没有获取过)
  1199. if (this.courseIdList[this.currentPage - 1] && this.bookPages[this.currentPage - 1].length === 0) {
  1200. await this.getBookPages(this.courseIdList[this.currentPage - 1]);
  1201. }
  1202. },
  1203. async onSwiperChange(e) {
  1204. this.currentPage = e.detail.current + 1
  1205. // 获取对应页面的数据(如果还没有获取过)
  1206. if (this.courseIdList[this.currentPage - 1] && this.bookPages[this.currentPage - 1].length === 0) {
  1207. await this.getBookPages(this.courseIdList[this.currentPage - 1]);
  1208. }
  1209. },
  1210. async getCourseList(id) {
  1211. const res = await this.$api.book.coursePage({
  1212. id: id
  1213. })
  1214. if (res.code === 200) {
  1215. // 课程切换时,先清理音频控制组件的所有数据
  1216. if (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls) {
  1217. this.$refs.customTabbar.$refs.audioControls.resetForCourseChange();
  1218. }
  1219. // 清空当前页面相关数据
  1220. this.currentPage = 1; // 重置到第一页
  1221. this.currentCourse = 1; // 重置当前课程索引
  1222. this.currentWordMeaning = null; // 清空单词释义
  1223. this.currentWordAudio = null; // 清空单词音频
  1224. this.currentHighlightIndex = -1; // 清空高亮索引
  1225. // 清理单词音频缓存
  1226. this.clearWordAudioCache();
  1227. // 重新初始化课程数据
  1228. this.courseIdList = res.result.map(item => item.id)
  1229. // 初始化二维数组 换一种方式
  1230. this.bookPages = this.courseIdList.map(() => [])
  1231. // 初始化标题数组
  1232. this.pageTitles = this.courseIdList.map(() => '')
  1233. // 初始化页面类型数组
  1234. this.pageTypes = this.courseIdList.map(() => '')
  1235. // 初始化页面单词数组
  1236. this.pageWords = this.courseIdList.map(() => [])
  1237. // 初始化滚动位置数组
  1238. this.scrollTops = this.courseIdList.map(() => 0)
  1239. // 初始化第一页
  1240. if (this.courseIdList.length > 0) {
  1241. await this.getBookPages(this.courseIdList[0])
  1242. // 课程切换后,确保音频控件能正确加载新课程的音频
  1243. // 使用$nextTick确保DOM和数据都已更新
  1244. this.$nextTick(async () => {
  1245. if (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls) {
  1246. try {
  1247. // 直接调用getCurrentPageAudio方法,更可靠
  1248. await this.$refs.customTabbar.$refs.audioControls.getCurrentPageAudio();
  1249. } catch (error) {
  1250. console.error('课程切换后音频加载失败:', error);
  1251. }
  1252. }
  1253. });
  1254. // 预加载后续几页的内容(异步执行,不阻塞当前页面显示)
  1255. this.preloadNextPages()
  1256. }
  1257. }
  1258. },
  1259. async getBookPages(id) {
  1260. const res = await this.$api.book.coursesPageDetail({
  1261. id: id
  1262. })
  1263. if (res.code === 200) {
  1264. // 使用$set确保响应式更新
  1265. const rawPageData = JSON.parse(res.result.content)
  1266. console.log('获取到的原始页面数据:', rawPageData)
  1267. // 过滤掉无效的数据项
  1268. const filteredPageData = rawPageData.filter(item => {
  1269. return item && typeof item === 'object' && (item.type || item.content)
  1270. })
  1271. console.log('过滤后的页面数据:', filteredPageData)
  1272. // 确保当前页面存在
  1273. if (this.currentPage - 1 < this.bookPages.length) {
  1274. this.$set(this.bookPages, this.currentPage - 1, filteredPageData)
  1275. // 保存页面标题
  1276. this.$set(this.pageTitles, this.currentPage - 1, res.result.title || '')
  1277. // 保存页面类型
  1278. this.$set(this.pageTypes, this.currentPage - 1, res.result.type || '')
  1279. // 保存页面单词释义数据
  1280. this.$set(this.pageWords, this.currentPage - 1, res.result.words || [])
  1281. // 保存页面付费状态
  1282. this.$set(this.pagePay, this.currentPage - 1, res.result.pay || 'N')
  1283. }
  1284. }
  1285. },
  1286. // 获取课程列表
  1287. async getCoursePageList(bookId) {
  1288. const res = await this.$api.book.course({
  1289. id: bookId
  1290. })
  1291. if (res.code === 200) {
  1292. this.courseList = res.result.records
  1293. // 打上序列号
  1294. this.courseList = this.courseList.map((item, index) => ({
  1295. ...item,
  1296. index,
  1297. }))
  1298. }
  1299. },
  1300. // 清理音频缓存
  1301. clearAudioCache() {
  1302. this.audioCache = {};
  1303. },
  1304. // 清理單詞語音緩存
  1305. clearWordAudioCache() {
  1306. this.wordAudioCache = {};
  1307. },
  1308. // 限制缓存大小,保留最近访问的页面
  1309. limitCacheSize(maxSize = 10) {
  1310. const cacheKeys = Object.keys(this.audioCache);
  1311. if (cacheKeys.length > maxSize) {
  1312. // 删除最旧的缓存项
  1313. const keysToDelete = cacheKeys.slice(0, cacheKeys.length - maxSize);
  1314. keysToDelete.forEach(key => {
  1315. delete this.audioCache[key];
  1316. });
  1317. }
  1318. },
  1319. // 预加载后续页面内容
  1320. async preloadNextPages() {
  1321. try {
  1322. // 优化策略:只预加载接下来的2-3页内容,避免过多请求
  1323. const preloadCount = Math.min(3, this.courseIdList.length - 1); // 预加载3页或剩余页数
  1324. // 串行预加载,避免并发请求过多
  1325. for (let i = 1; i <= preloadCount; i++) {
  1326. if (i < this.courseIdList.length && this.bookPages[i].length === 0) {
  1327. try {
  1328. await this.preloadSinglePage(this.courseIdList[i], i);
  1329. // 每页之间间隔800ms,给服务器更多缓冲时间
  1330. if (i < preloadCount) {
  1331. await new Promise(resolve => setTimeout(resolve, 800));
  1332. }
  1333. } catch (error) {
  1334. console.error(`预加载第${i + 1}页失败:`, error);
  1335. // 继续预加载下一页
  1336. }
  1337. }
  1338. }
  1339. // 延迟1.5秒后再通知AudioControls组件开始预加载音频,避免接口冲突
  1340. setTimeout(() => {
  1341. if (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls) {
  1342. this.$refs.customTabbar.$refs.audioControls.startPreloadAudio();
  1343. }
  1344. }, 1500);
  1345. } catch (error) {
  1346. console.error('预加载页面内容失败:', error);
  1347. }
  1348. },
  1349. // 预加载单个页面
  1350. async preloadSinglePage(courseId, pageIndex) {
  1351. try {
  1352. const res = await this.$api.book.coursesPageDetail({
  1353. id: courseId
  1354. });
  1355. if (res.code === 200) {
  1356. const rawPageData = JSON.parse(res.result.content);
  1357. const filteredPageData = rawPageData.filter(item => {
  1358. return item && typeof item === 'object' && (item.type || item.content);
  1359. });
  1360. // 使用$set确保响应式更新
  1361. this.$set(this.bookPages, pageIndex, filteredPageData);
  1362. this.$set(this.pageTitles, pageIndex, res.result.title || '');
  1363. this.$set(this.pageTypes, pageIndex, res.result.type || '');
  1364. this.$set(this.pageWords, pageIndex, res.result.words || []);
  1365. this.$set(this.pagePay, pageIndex, res.result.pay || 'N');
  1366. }
  1367. } catch (error) {
  1368. console.error(`预加载第${pageIndex + 1}页失败:`, error);
  1369. throw error;
  1370. }
  1371. },
  1372. // 自動加載第一頁音頻並播放
  1373. async autoLoadAndPlayFirstPage() {
  1374. try {
  1375. // 確保當前是第一頁且需要加載音頻
  1376. if (this.currentPage === 1 && this.shouldLoadAudio) {
  1377. // 加載音頻
  1378. await this.getCurrentPageAudio();
  1379. // 檢查是否成功加載音頻
  1380. if (this.currentPageAudios && this.currentPageAudios.length > 0) {
  1381. // getCurrentPageAudio方法已經處理了第一個音頻的播放,這裡不需要再次調用playAudio
  1382. } else {
  1383. }
  1384. } else {
  1385. }
  1386. } catch (error) {
  1387. console.error('自動加載和播放音頻失敗:', error);
  1388. }
  1389. },
  1390. },
  1391. async onLoad(args) {
  1392. this.$scrollTo('imageRef')
  1393. // 初始化audioManager事件监听
  1394. this.initAudioManagerListeners();
  1395. // 监听音色切换事件,传递给AudioControls组件处理
  1396. uni.$on('selectVoice', async (voiceId) => {
  1397. if (this.voiceId === voiceId) {
  1398. return;
  1399. }
  1400. // 检查是否正在加载音频,如果是则阻止音色切换
  1401. if (this.isAudioLoading || (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls && this.$refs.customTabbar.$refs.audioControls.isAudioLoading)) {
  1402. uni.showToast({
  1403. title: '音频加载中,请稍后再试',
  1404. icon: 'none',
  1405. duration: 2000
  1406. });
  1407. return;
  1408. }
  1409. // 更新本地音色ID
  1410. this.voiceId = voiceId;
  1411. // 同步音色设置到audioManager
  1412. audioManager.setGlobalVoiceId(voiceId);
  1413. // 清理單詞語音資源
  1414. this.clearWordAudioCache();
  1415. // 停止当前播放的音频(现在由audioManager统一管理)
  1416. audioManager.stopCurrentAudio();
  1417. // 通知AudioControls组件处理音色切换
  1418. if (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls) {
  1419. try {
  1420. // 传入选项:preloadAllPages: true 表示要预加载所有页面的音频
  1421. await this.$refs.customTabbar.$refs.audioControls.handleVoiceChange(voiceId, {
  1422. preloadAllPages: true
  1423. });
  1424. } catch (error) {
  1425. console.error('音色切换处理失败:', error);
  1426. }
  1427. }
  1428. })
  1429. this.courseId = args.courseId
  1430. this.memberId = args.memberId
  1431. // 先获取点进来的课程的页面列表
  1432. await Promise.all([this.getVoiceList(), this.getMemberInfo(), this.getCourseList(this.courseId), this.getCoursePageList(args.bookId)])
  1433. // 页面加载完成后,通知AudioControls组件自动加载第一页音频
  1434. this.$nextTick(() => {
  1435. if (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls) {
  1436. this.$refs.customTabbar.$refs.audioControls.autoLoadAndPlayFirstPage();
  1437. }
  1438. });
  1439. },
  1440. // 页面卸载时清理资源
  1441. onUnload() {
  1442. uni.$off('selectVoice')
  1443. // 0. 清理滚动防抖定时器
  1444. if (this.scrollDebounceTimer) {
  1445. clearTimeout(this.scrollDebounceTimer);
  1446. this.scrollDebounceTimer = null;
  1447. }
  1448. // 1. 清理单词语音资源
  1449. if (this.currentWordAudio) {
  1450. try {
  1451. this.currentWordAudio.destroy();
  1452. } catch (error) {
  1453. console.error('销毁单词音频实例失败:', error);
  1454. }
  1455. this.currentWordAudio = null;
  1456. }
  1457. // 2. 清理单词语音缓存
  1458. this.clearWordAudioCache();
  1459. // 3. 停止单词音频播放状态
  1460. this.isWordAudioPlaying = false;
  1461. // 4. 通知AudioControls组件清理资源
  1462. if (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls) {
  1463. this.$refs.customTabbar.$refs.audioControls.destroyAudio();
  1464. }
  1465. // 5. 清理全局音频实例(防止遗漏)
  1466. try {
  1467. // 获取所有可能的音频上下文并销毁
  1468. if (typeof wx !== 'undefined' && wx.getBackgroundAudioManager) {
  1469. const bgAudio = wx.getBackgroundAudioManager();
  1470. if (bgAudio) {
  1471. bgAudio.stop();
  1472. }
  1473. }
  1474. } catch (error) {
  1475. console.error('清理背景音频失败:', error);
  1476. }
  1477. },
  1478. // 页面隐藏时暂停音频
  1479. onHide() {
  1480. // 1. 暂停单词音频
  1481. if (this.currentWordAudio && this.isWordAudioPlaying) {
  1482. try {
  1483. this.currentWordAudio.pause();
  1484. this.isWordAudioPlaying = false;
  1485. } catch (error) {
  1486. console.error('暂停单词音频失败:', error);
  1487. }
  1488. }
  1489. // 2. 通知AudioControls组件暂停音频
  1490. if (this.$refs.customTabbar && this.$refs.customTabbar.$refs.audioControls) {
  1491. this.$refs.customTabbar.$refs.audioControls.pauseOnHide();
  1492. }
  1493. }
  1494. }
  1495. </script>
  1496. <style lang="scss" scoped>
  1497. .book-container {
  1498. width: 100%;
  1499. min-height: 100vh;
  1500. background-color: #F8F8F8;
  1501. position: relative;
  1502. overflow: hidden;
  1503. }
  1504. .custom-navbar {
  1505. position: fixed;
  1506. top: 0;
  1507. left: 0;
  1508. right: 0;
  1509. background-color: #F8F8F8;
  1510. z-index: 1000;
  1511. transition: transform 0.3s ease;
  1512. &.navbar-hidden {
  1513. transform: translateY(-100%);
  1514. }
  1515. }
  1516. .navbar-content {
  1517. display: flex;
  1518. align-items: center;
  1519. justify-content: space-between;
  1520. padding: 20rpx 32rpx;
  1521. // padding-top: calc(20rpx + var(--status-bar-height, 0));
  1522. height: 60rpx;
  1523. }
  1524. .navbar-left,
  1525. .navbar-right {
  1526. width: 80rpx;
  1527. display: flex;
  1528. align-items: center;
  1529. }
  1530. .navbar-right {
  1531. justify-content: flex-end;
  1532. flex: 1;
  1533. }
  1534. .navbar-title {
  1535. transform: translateX(-50rpx);
  1536. flex: 1;
  1537. text-align: center;
  1538. font-family: PingFang SC;
  1539. font-weight: 500;
  1540. font-size: 32rpx;
  1541. color: #262626;
  1542. line-height: 48rpx;
  1543. }
  1544. .content-swiper {
  1545. flex: 1;
  1546. // min-height: calc(100vh - 100rpx);
  1547. // margin-top: 100rpx;
  1548. height: 100vh;
  1549. }
  1550. .swiper-item {
  1551. min-height: 100vh;
  1552. // background-color: red;
  1553. }
  1554. .content-area {
  1555. flex: 1;
  1556. padding: 30rpx 40rpx 100rpx;
  1557. /* #ifndef H5 */
  1558. padding: 100rpx 40rpx;
  1559. /* #endif */
  1560. // padding-top: ;
  1561. // background: linear-gradient(180deg, #DEFFFF 0%, #FBFEFF 22.65%, #F0FBFF 100%);
  1562. min-height: 100%;
  1563. box-sizing: border-box;
  1564. overflow-y: auto;
  1565. .title {
  1566. font-family: PingFang SC;
  1567. font-weight: 500;
  1568. font-size: 34rpx;
  1569. text-align: center;
  1570. color: #181818;
  1571. line-height: 48rpx;
  1572. margin-bottom: 32rpx;
  1573. }
  1574. .image-container {
  1575. width: 100%;
  1576. display: flex;
  1577. justify-content: center;
  1578. align-items: center;
  1579. margin: 30rpx 0;
  1580. /* 平板设备适配 */
  1581. @media screen and (min-width: 768px) {
  1582. margin: 40rpx 0;
  1583. }
  1584. }
  1585. .content-image {
  1586. width: 100%;
  1587. height: auto;
  1588. //max-width: 600rpx;
  1589. /* 限制最大宽度,避免在大屏设备上过大 */
  1590. display: block;
  1591. border-radius: 12rpx;
  1592. /* 添加圆角,提升视觉效果 */
  1593. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  1594. /* 添加阴影,增强层次感 */
  1595. /* 平板设备适配 */
  1596. // @media screen and (min-width: 768px) {
  1597. // max-width: 500rpx;
  1598. // }
  1599. }
  1600. .video-content {
  1601. width: 100%;
  1602. height: auto;
  1603. margin: 30rpx auto;
  1604. position: relative;
  1605. .video-player {
  1606. // height: 100%;
  1607. width: 100%;
  1608. height: 60vw;
  1609. // margin: 0 auto;
  1610. // height: auto;
  1611. }
  1612. .video-loading {
  1613. position: absolute;
  1614. top: 50%;
  1615. left: 50%;
  1616. transform: translate(-50%, -50%);
  1617. color: #666;
  1618. font-size: 28rpx;
  1619. }
  1620. }
  1621. }
  1622. .card-content {
  1623. background: linear-gradient(180deg, #DEFFFF 0%, #FBFEFF 22.65%, #F0FBFF 100%);
  1624. display: flex;
  1625. flex-direction: column;
  1626. gap: 32rpx;
  1627. min-height: 1172rpx;
  1628. margin-top: 20rpx;
  1629. border-radius: 32rpx;
  1630. // height: 100%;
  1631. padding: 20rpx;
  1632. padding-bottom: 100rpx;
  1633. // margin: 0
  1634. border: 1px solid #FFFFFF;
  1635. box-sizing: border-box;
  1636. .card-line {
  1637. display: flex;
  1638. align-items: center;
  1639. // margin-bottom: 20rpx;
  1640. padding: 20rpx;
  1641. padding-bottom: 0;
  1642. }
  1643. .card-line-image {
  1644. width: 48rpx;
  1645. height: 48rpx;
  1646. margin-right: 16rpx;
  1647. }
  1648. .card-line-text {
  1649. font-family: PingFang SC;
  1650. font-weight: 600;
  1651. font-size: 30rpx;
  1652. line-height: 48rpx;
  1653. color: #3B3D3D;
  1654. }
  1655. .card-image {
  1656. // width: 590rpx;
  1657. width: 100%;
  1658. height: 268rpx;
  1659. border-radius: 24rpx;
  1660. margin: 30rpx auto;
  1661. // margin-bottom: 20rpx;
  1662. }
  1663. // .english-text {
  1664. // display: block;
  1665. // font-family: PingFang SC;
  1666. // font-weight: 600;
  1667. // font-size: 32rpx;
  1668. // line-height: 48rpx;
  1669. // color: #3B3D3D;
  1670. // // margin-bottom: 16rpx;
  1671. // }
  1672. // .english-text-container {
  1673. // display: flex;
  1674. // flex-wrap: wrap;
  1675. // align-items: baseline;
  1676. // }
  1677. // .english-token {
  1678. // font-family: PingFang SC;
  1679. // font-weight: 600;
  1680. // font-size: 32rpx;
  1681. // line-height: 48rpx;
  1682. // color: #3B3D3D;
  1683. // margin-right: 10rpx;
  1684. // }
  1685. .clickable-word {
  1686. background: $primary-color;
  1687. text-decoration: underline;
  1688. cursor: pointer;
  1689. transition: all 0.2s ease;
  1690. padding: 0 20rpx;
  1691. }
  1692. .clickable-word:hover {
  1693. background-color: rgba(0, 122, 255, 0.1);
  1694. border-radius: 4rpx;
  1695. }
  1696. .chinese-segment {
  1697. font-family: PingFang SC;
  1698. font-weight: 400;
  1699. font-size: 28rpx;
  1700. line-height: 48rpx;
  1701. color: #3B3D3D;
  1702. }
  1703. .clickable-keyword {
  1704. background: $primary-color;
  1705. text-decoration: underline;
  1706. cursor: pointer;
  1707. color: #fff !important;
  1708. transition: all 0.2s ease;
  1709. border-radius: 4rpx;
  1710. padding: 4rpx;
  1711. }
  1712. .clickable-keyword:hover {
  1713. background-color: rgba(0, 122, 255, 0.1);
  1714. }
  1715. .chinese-text {
  1716. display: block;
  1717. font-family: PingFang SC;
  1718. font-weight: 400;
  1719. font-size: 28rpx;
  1720. line-height: 48rpx;
  1721. color: #4F4F4F;
  1722. }
  1723. }
  1724. /* 会员限制页面样式 */
  1725. .member-content {
  1726. display: flex;
  1727. flex-direction: column;
  1728. align-items: center;
  1729. justify-content: center;
  1730. height: 90%;
  1731. background-color: #F8F8F8;
  1732. padding: 40rpx;
  1733. margin: -40rpx;
  1734. box-sizing: border-box;
  1735. }
  1736. .member-title {
  1737. font-family: PingFang SC;
  1738. font-weight: 500;
  1739. font-size: 40rpx;
  1740. line-height: 1;
  1741. color: #6f6f6f;
  1742. text-align: center;
  1743. margin-bottom: 48rpx;
  1744. }
  1745. .member-button {
  1746. width: 670rpx;
  1747. height: 72rpx;
  1748. background: #06DADC;
  1749. border-radius: 200rpx;
  1750. display: flex;
  1751. align-items: center;
  1752. justify-content: center;
  1753. }
  1754. .member-button-text {
  1755. font-family: PingFang SC;
  1756. font-weight: 400;
  1757. font-size: 30rpx;
  1758. color: #FFFFFF;
  1759. }
  1760. // .video-content {
  1761. // width: 100%;
  1762. // height: auto;
  1763. // // margin: 200rpx -40rpx 0;
  1764. // // height: 500rpx;
  1765. // background-color: #FFFFFF;
  1766. // // padding: 40rpx;
  1767. // border-radius: 24rpx;
  1768. // display: flex;
  1769. // align-items: center;
  1770. // justify-content: center;
  1771. // .video-player{
  1772. // width: 100%;
  1773. // margin: 0 auto;
  1774. // height: auto;
  1775. // }
  1776. // }
  1777. .text-content {
  1778. // background-color: #F6F6F6;
  1779. box-sizing: border-box;
  1780. &>view {
  1781. padding: 20rpx;
  1782. }
  1783. }
  1784. .content-text {
  1785. font-family: PingFang SC;
  1786. // font-weight: 400;
  1787. font-size: 28rpx;
  1788. color: #3B3D3D;
  1789. line-height: 48rpx;
  1790. letter-spacing: 0;
  1791. text-align: justify;
  1792. word-break: break-all;
  1793. transition: all 0.3s ease;
  1794. }
  1795. .clickable-text {
  1796. cursor: pointer;
  1797. &:active {
  1798. background-color: rgba(6, 218, 220, 0.1);
  1799. border-radius: 4rpx;
  1800. }
  1801. }
  1802. .lead-text {
  1803. background: #06dadc12;
  1804. // background: #fffbe6;#06dadc
  1805. /* 柔和的提示背景 */
  1806. // border: 1px solid #ffe58f;
  1807. border-radius: 8px;
  1808. // padding: 10rpx 20rpx;
  1809. /* 添加平滑过渡动画 */
  1810. transition: all 0.3s ease;
  1811. }
  1812. .introduction-text {
  1813. background: #fffbe6;
  1814. border: 1px solid #ffe58f;
  1815. border-radius: 8px;
  1816. padding: 10rpx 20rpx;
  1817. }
  1818. .text-highlight {
  1819. background-color: rgba(255, 248, 220, 0.8);
  1820. /* 温暖的米黄色,对眼睛友好 */
  1821. border-left: 4rpx solid #ffd700;
  1822. /* 左侧金色边框作为朗读指示 */
  1823. padding: 4rpx 8rpx;
  1824. border-radius: 6rpx;
  1825. box-shadow: 0 2rpx 6rpx rgba(255, 215, 0, 0.15);
  1826. /* 柔和的阴影 */
  1827. /* 添加平滑过渡动画 */
  1828. transition: all 0.3s ease;
  1829. }
  1830. </style>