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

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