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

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