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

1963 lines
56 KiB

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