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

2335 lines
70 KiB

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