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

2356 lines
70 KiB

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