四零语境前端代码仓库
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.

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