reading.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. import httpRequestApi from '../../utils/APIClient';
  2. const aiengine = require('../../utils/ChivoxAiEngine')
  3. const sha1 = require('../../utils/sha1');
  4. import {
  5. formatDate
  6. } from '../../utils/util';
  7. Page({
  8. data: {
  9. title: '',
  10. id: '',
  11. img: '',
  12. fullScreenBtn: false,
  13. playBtn: true,
  14. gesture: true,
  15. muted: false,
  16. gesture: false,
  17. centerBtn: true,
  18. recordFlag: 0,
  19. recordSource: '',
  20. videoCtr: 'recordingVideoEnd',
  21. btnFlag: false,
  22. btnImgFlag: false,
  23. microphonePng: '../../static/index/microphone.png',
  24. recordingGif: '../../static/index/readingNow.gif',
  25. videoUrl: '',
  26. readingText: '',
  27. videoList: [],
  28. pageNo: 1,
  29. totalSize: 0,
  30. nextMargin: getApp().globalData.nextMargin,
  31. lowerThresHold: 100,
  32. isVideoListShow: true,
  33. overall: '', // 评测总分
  34. integrity: '', //完成度
  35. tone: '', //语调声调
  36. fluency: '', //流利度
  37. accuracy: '', // 正确分,发音分
  38. star: [0, 0, 0, 0, 0],
  39. ifTextShow: true,
  40. ifScoreDialogShow: false,
  41. ifScoreShow: false,
  42. statusbarobj: {
  43. isshowbtn: false, //是否显示按钮
  44. title: "小学语文朗读配音", //标题
  45. },
  46. isScroll: true,
  47. noMoreWork: false
  48. },
  49. onLoad: function (option) {
  50. console.log(option);
  51. this.videoCtx = null;
  52. const uid = wx.getStorageSync('uid')
  53. this.getClassInfo(option.id);
  54. // this.getMicAuth()
  55. },
  56. getClassInfo: function (id) {
  57. httpRequestApi.getClassDetail(id).success(res => {
  58. console.log('课程信息', res)
  59. let reg = /\\n/g
  60. this.setData({
  61. title: res.data.data.userRead.title,
  62. videoUrl: res.data.data.userRead.videoPath,
  63. originVideo: res.data.data.userRead.originVideo,
  64. img: res.data.data.userRead.iconImg,
  65. id: res.data.data.userRead.id,
  66. readingText: res.data.data.userRead.lessonText,
  67. grade: res.data.data.userRead.grade,
  68. exampleId: res.data.data.userRead.exampleId,
  69. summary: res.data.data.userRead.summary,
  70. coverImg: res.data.data.userRead.coverImg,
  71. shareImg: res.data.data.userRead.shareImg,
  72. })
  73. this.getReadInfo(id)
  74. httpRequestApi.userIntoPage('pages/reading/reading', '朗读页面').success((res) => {
  75. })
  76. })
  77. },
  78. onHide: function () {
  79. console.log('onhide')
  80. if (this.data.btnImgFlag) {
  81. this.recorderManager.stop();
  82. }
  83. if (this.innerAudioContext) {
  84. this.innerAudioContext.stop();
  85. }
  86. // this.ss.destroyEngine();
  87. this.setData({
  88. recordFlag: 0
  89. })
  90. },
  91. onUnload: function () {
  92. console.log('onUnload')
  93. if (this.data.btnImgFlag) {
  94. this.recorderManager.stop();
  95. }
  96. if (this.innerAudioContext) {
  97. this.innerAudioContext.stop();
  98. }
  99. },
  100. onShow: function () {
  101. this.videoCtx = wx.createVideoContext('myVideo', this);
  102. let data = requirePlugin("myPlugin");
  103. const obj = {
  104. appid: 'a415',
  105. userid: wx.getStorageSync('uid'),
  106. getEvalMessage: (res) => {
  107. this.getRecordScore(res)
  108. // console.log('评测结果',res)
  109. },
  110. recorderCallback: (type, data) => {
  111. // 录音测评监控回调
  112. this.ssRecorderCallback(type, data)
  113. }
  114. }
  115. // this.ss = new data.ssEngine(obj);
  116. this.recorderManager = wx.getRecorderManager();
  117. this.recorderManager.onStop((res) => {
  118. // wx.showToast({
  119. // title: 'onStop',
  120. // icon: 'fail',
  121. // duration: 500
  122. // })
  123. this.videoCtx.seek(0);
  124. this.videoCtx.stop();
  125. console.log('recorder stop', res)
  126. const recordFile = res.tempFilePath;
  127. this.setData({
  128. recordFlag: 0,
  129. recordSource: recordFile,
  130. btnFlag: true,
  131. btnImgFlag: false
  132. })
  133. this.wsEngine.stop({
  134. success: () => {
  135. console.log('====== wsEngine stop success ======');
  136. wx.showLoading({
  137. title: '作品评测中',
  138. mask: true
  139. })
  140. // TODO: add your code here
  141. },
  142. fail: (res) => {
  143. console.log("====== wsEngine stop fail ======");
  144. console.log(JSON.stringify(res)); //请关注res.errId, res.error
  145. // TODO: add your code here
  146. },
  147. complete: () => {
  148. // TODO: add your code here
  149. // clearInterval(recordTimeInterval);
  150. console.log("====== wsEngine stop complete ======");
  151. }
  152. });
  153. })
  154. this.recorderManager.onStart(() => {
  155. // this.saveVideo();
  156. this.setData({
  157. btnImgFlag: true,
  158. btnFlag: false
  159. })
  160. console.log('recorder start')
  161. });
  162. //监听已录制完指定帧大小的文件事件。如果设置了 frameSize,则会回调此事件。
  163. this.recorderManager.onFrameRecorded((res) => {
  164. const {
  165. frameBuffer
  166. } = res
  167. console.log('frameBuffer.byteLength', frameBuffer.byteLength)
  168. //TODO 调用feed接口传递音频片给驰声评测引擎
  169. this.wsEngine.feed({
  170. data: frameBuffer, // frameBuffer为微信录音机回调的音频数据
  171. success: () => {
  172. // feed 成功
  173. console.log('feed success.')
  174. },
  175. fail: (res) => {
  176. // feed 失败, 请关注res.errId, res.error
  177. console.log('feed fail:', JSON.stringify(res))
  178. },
  179. complete: () => {
  180. // feed 完成
  181. }
  182. });
  183. });
  184. },
  185. ssRecorderCallback: function (type, data) {
  186. console.log('录音测评监控回调', type)
  187. console.log('录音测评监控回调', data)
  188. /* 录音开始 */
  189. if (type === 'onStart') {
  190. this.setData({
  191. btnImgFlag: true,
  192. btnFlag: false
  193. })
  194. console.log('recorder start')
  195. }
  196. if (type === 'onStop') {
  197. this.videoCtx.stop();
  198. this.setData({
  199. recordFlag: 0,
  200. recordSource: data.tempFilePath,
  201. btnFlag: true,
  202. btnImgFlag: false
  203. })
  204. console.log('recorder start')
  205. }
  206. },
  207. // 录音中视频播放结束 (控制录音同时结束)
  208. recordingVideoEnd: function () {
  209. console.log(this.data.videoCtr)
  210. console.log('recordingVideoEnd');
  211. //
  212. if (this.data.recordFlag === 0) {
  213. // this.recordStop();
  214. this.playingVideoEnd();
  215. return;
  216. }
  217. // 录音结束
  218. if (this.data.recordFlag === 1) {
  219. this.recordStop();
  220. }
  221. },
  222. // 播放中视频播放结束 (控制录音同时结束)
  223. playingVideoEnd: function () {
  224. console.log('playingVideoEnd')
  225. // this.ss.stopPlay();
  226. },
  227. /***
  228. * recordFlag:
  229. * 0 初始状态
  230. * 1 录音中
  231. * 2 录音结束
  232. ***/
  233. audioRecord: function () {
  234. console.log('111111111111111recordFlag', this.data.recordFlag)
  235. if (this.recorderManager) {
  236. this.recorderManager.stop();
  237. }
  238. if (this.innerAudioContext) {
  239. this.innerAudioContext.stop();
  240. }
  241. if (this.data.recordFlag === 0) {
  242. this.wsEngine = aiengine.createWsEngine({});
  243. this.wsEngine.onResult(res => {
  244. wx.hideLoading();
  245. this.getRecordScore(res)
  246. })
  247. this.wsEngine.onErrorResult(res => {
  248. wx.hideLoading();
  249. console.log('驰声createWsEngine失败', res);
  250. })
  251. this.videoComplete();
  252. // this.getMicAuth()
  253. return;
  254. }
  255. // 录音结束后
  256. if (this.data.recordFlag === 1) {
  257. wx.showLoading({
  258. title: '作品转码中',
  259. mask: true
  260. })
  261. this.recordStop();
  262. }
  263. },
  264. // 录音开始
  265. /**
  266. * duration: 时长 最长10分钟
  267. sampleRate: 44100, 采样率
  268. numberOfChannels: 1, 录音通道
  269. encodeBitRate: 192000, 码率
  270. format: 'mp3', 格式
  271. frameSize: 50 制定帧大小
  272. */
  273. recordStart: function () {
  274. console.log('录音开始');
  275. const options = {
  276. duration: 600000,
  277. sampleRate: 44100,
  278. numberOfChannels: 1,
  279. encodeBitRate: 192000,
  280. format: 'mp3',
  281. frameSize: 50
  282. }
  283. this.recorderManager.start(options);
  284. // this.ss.startRecord({
  285. // coreType: 'cn.sent.score', //测评题型
  286. // evalTime: 300000, //测评的录音时间,时间到自动停止测评
  287. // refText: this.data.readingText, //测评文本
  288. // warrantId: 'c11163aa6c834a028da4a4b30955be96', //鉴权id
  289. // })
  290. // 驰声测评
  291. let timeStamp = new Date().getTime()
  292. let sig = sha1(`16075689600000da${timeStamp}caa8e60da6042731c230fe431ac9c7fd`)
  293. console.log('加密串', sig)
  294. // return
  295. let app = {
  296. applicationId: '16075689600000da',
  297. sig, //签名字符串 通过签名算法alg(appkey + timestamp + secretKey)生成
  298. alg: 'sha1',
  299. timestamp: timeStamp + '',
  300. userId: wx.getStorageSync('uid')
  301. }
  302. console.log('app数据', app)
  303. let lessonText = this.data.readingText;
  304. console.log('课文课文课文', lessonText)
  305. this.wsEngine.start({
  306. app,
  307. request: {
  308. coreType: "cn.pred.raw",
  309. refText: lessonText,
  310. rank: 100,
  311. attachAudioUrl: 1,
  312. result: {
  313. details: {
  314. gop_adjust: 1
  315. }
  316. }
  317. },
  318. audio: {
  319. audioType: "mp3",
  320. channel: 1,
  321. sampleBytes: 2,
  322. sampleRate: 16000
  323. },
  324. success: (res) => {
  325. // 调用成功
  326. console.log('驰声start成功', res)
  327. },
  328. fail: (res) => {
  329. // start失败,请关注res.errId, res.error
  330. console.log('驰声start失败', res)
  331. }
  332. })
  333. },
  334. getMicAuth() {
  335. let _this = this;
  336. wx.getSetting({
  337. success(res) {
  338. if (res.authSetting['scope.record']) {
  339. _this.videoComplete();
  340. } else {
  341. _this.getMicSetAuth();
  342. return;
  343. }
  344. }
  345. })
  346. },
  347. getMicSetAuth() {
  348. let _this = this;
  349. wx.authorize({
  350. scope: 'scope.record',
  351. success() {
  352. // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
  353. _this.audioRecord();
  354. },
  355. fail() {
  356. wx.showModal({
  357. title: '录音前请打开麦克风权限',
  358. content: '',
  359. confirmText: '我知道了',
  360. showCancel: false,
  361. success(res) {
  362. // console.log('用户点击确定')
  363. wx.openSetting({
  364. success(res) {
  365. console.log('跳转到设置页', res.authSetting)
  366. // res.authSetting = {
  367. // "scope.userInfo": true,
  368. // "scope.userLocation": true
  369. // }
  370. }
  371. })
  372. }
  373. })
  374. }
  375. })
  376. },
  377. // 录音结束
  378. recordStop: function () {
  379. this.setData({
  380. muted: false
  381. })
  382. // this.ss.stopRecord();
  383. console.log('录音结束')
  384. this.recorderManager.stop();
  385. wx.hideLoading()
  386. },
  387. // 获取测评结果
  388. getRecordScore(res) {
  389. console.log('测评结果', JSON.stringify(res))
  390. const result = res.result;
  391. const overall = result.overall; // 总分
  392. const integrity = result.integrity; //完成度
  393. const tone = result.tone; // 语调声调
  394. // const accuracy = result.accuracy; // 准确度 发音分
  395. const accuracy = result.overall; // 准确度 发音分
  396. const fluency = result.fluency.overall; //流利度
  397. let starArray = [];
  398. let myOverall = integrity * 0.3 + accuracy * 0.5 + fluency * 0.1 + tone * 0.1;
  399. // let myOverall = 80;
  400. console.log('我的总分', myOverall)
  401. if (myOverall < 5) {
  402. starArray = [0, 0, 0, 0, 0]
  403. } else if (5 <= myOverall && myOverall < 30) {
  404. starArray = [1, 0, 0, 0, 0]
  405. } else if (30 <= myOverall && myOverall < 50) {
  406. starArray = [1, 1, 0, 0, 0]
  407. } else if (50 <= myOverall && myOverall < 70) {
  408. starArray = [1, 1, 1, 0, 0]
  409. } else if (70 <= myOverall && myOverall < 90) {
  410. starArray = [1, 1, 1, 1, 0]
  411. } else if (90 <= myOverall) {
  412. starArray = [1, 1, 1, 1, 1]
  413. }
  414. // let score = myOverall / 20;
  415. // if (score <= 0) {
  416. // starArray = [0, 0, 0, 0, 0]
  417. // } else {
  418. // for (let i = 1; i < 5; i += 0.9) {
  419. // if (i <= score) {
  420. // starArray.push(1);
  421. // } else {
  422. // starArray.push(0)
  423. // }
  424. // }
  425. // }
  426. this.setData({
  427. overall,
  428. integrity,
  429. tone,
  430. accuracy,
  431. fluency,
  432. ifScoreDialogShow: true,
  433. star: starArray
  434. })
  435. },
  436. closeScoreDialog() {
  437. this.setData({
  438. ifScoreDialogShow: false,
  439. ifScoreShow: true,
  440. ifTextShow: false
  441. })
  442. },
  443. // 播放录音
  444. audioPlay: function () {
  445. /* 用了先声智能以后录音播放由先声只能接管 */
  446. if (this.innerAudioContext) {
  447. this.innerAudioContext.stop();
  448. this.videoCtx.stop();
  449. }
  450. this.innerAudioContext = wx.createInnerAudioContext();
  451. this.innerAudioContext.src = this.data.recordSource; // 这里可以是录音的临时路径
  452. console.log('音频路径', this.data.recordSource)
  453. this.setData({
  454. videoUrl: this.data.videoUrl,
  455. muted: true
  456. })
  457. console.log(this.innerAudioContext.src);
  458. this.videoCtx.play();
  459. this.innerAudioContext.play();
  460. /* if (this.data.audioPath) {
  461. if (this.data.audioPlaying) {
  462. // this.ss.stopPlay();
  463. }
  464. // this.ss.startPlay(this.data.audioPath);
  465. this.videoCtx.stop();
  466. this.videoCtx.play();
  467. } else {
  468. const recordSource = this.data.recordSource
  469. wx.uploadFile({
  470. url: 'https://reader-api.ai160.com/file/upload',
  471. filePath: recordSource,
  472. name: '朗读录音',
  473. header: {
  474. uid: wx.getStorageSync('uid')
  475. },
  476. success: (res) => {
  477. const formateRes = JSON.parse(res.data);
  478. let audioPath = formateRes.data;
  479. this.setData({
  480. audioPath,
  481. audioPlaying: true
  482. })
  483. // this.ss.startPlay(audioPath);
  484. // this.videoCtx.seek(0);
  485. this.videoCtx.stop();
  486. console.log('播放器归0')
  487. this.videoCtx.play();
  488. console.log('播放器播放')
  489. }
  490. })
  491. } */
  492. },
  493. videoComplete: function () {
  494. this.setData({
  495. recordFlag: 1,
  496. videoUrl: this.data.originVideo,
  497. centerBtn: false,
  498. playBtn: false,
  499. isVideoListShow: false,
  500. muted: false,
  501. ifTextShow: true,
  502. ifScoreShow: false
  503. }, () => {
  504. console.log('播放视频播放视频播放视频')
  505. // this.videoCtx.seek(1);
  506. this.videoCtx.stop();
  507. this.videoCtx.play();
  508. this.recordStart();
  509. })
  510. },
  511. // 上传
  512. upload: function () {
  513. if (this.videoCtx) {
  514. this.videoCtx.stop();
  515. }
  516. if (this.data.audioPlaying) {
  517. // this.ss.stopPlay();
  518. this.setData({
  519. audioPlaying: false
  520. })
  521. }
  522. wx.showLoading({
  523. title: '作品上传中',
  524. mask: true
  525. })
  526. const recordSource = this.data.recordSource;
  527. wx.uploadFile({
  528. // url: 'https://reader-api.ai160.com/file/upload',
  529. url: 'https://reader-api.efunbox.cn//file/upload',
  530. filePath: recordSource,
  531. name: '朗读录音',
  532. header: {
  533. uid: wx.getStorageSync('uid')
  534. },
  535. success: (res) => {
  536. const formateRes = JSON.parse(res.data);
  537. let audioPath = formateRes.data;
  538. console.log('音频上传成功')
  539. this.shareWorks(audioPath);
  540. }
  541. })
  542. },
  543. shareWorks: function (audio) {
  544. const data = {
  545. "lessonId": this.data.id,
  546. "originVideo": this.data.videoUrl,
  547. "audioPath": audio,
  548. "title": this.data.title,
  549. "iconImg": this.data.img,
  550. "summary": this.data.summary,
  551. "productId": this.data.productId,
  552. "grade": this.data.grade,
  553. "exampleId": this.data.exampleId,
  554. "coverImg": this.data.coverImg,
  555. "shareImg": this.data.shareImg
  556. };
  557. httpRequestApi.postWork(data).success(res => {
  558. wx.hideLoading({
  559. success: () => {
  560. wx.showToast({
  561. title: '作品已上传正在审核中',
  562. icon: 'none',
  563. duration: 1000,
  564. success: () => {
  565. console.log('上传成功', res);
  566. if (res.data.count > 0) {
  567. this.setData({
  568. flowerNum: res.data.count
  569. })
  570. this.flowerAnimationHandler();
  571. }
  572. const _data = this.data;
  573. const scoreData = {
  574. "userReadId": res.data.data.id,
  575. "complete": _data.integrity,
  576. "accuracy": _data.accuracy,
  577. "speed": _data.fluency,
  578. "intonation": _data.tone,
  579. "score": _data.overall
  580. }
  581. // 上传评分
  582. httpRequestApi.postWorksScore(scoreData).success(res => {
  583. console.log(res)
  584. });
  585. const pages = getCurrentPages();
  586. const prevPage = pages[pages.length - 2];
  587. prevPage.setData({
  588. // workId: res.data.data.id, // 有id就塞到第一位
  589. fromReading: true
  590. }, () => {
  591. wx.navigateBack({
  592. delta: 1
  593. })
  594. })
  595. }
  596. })
  597. }
  598. });
  599. }).fail(res => {
  600. wx.hideLoading({
  601. success: () => {
  602. wx.showToast({
  603. title: '上传超时',
  604. icon: 'fail',
  605. duration: 1000
  606. })
  607. }
  608. });
  609. })
  610. },
  611. // 获取本课朗读内容
  612. getReadInfo: function (id, pageNo, pageSize) {
  613. // const uid = wx.getStorageSync('uid');
  614. const data = {
  615. exampleId: this.data.id || id,
  616. pageNo: this.data.pageNo,
  617. pageSize: 3,
  618. type: 'READ'
  619. };
  620. httpRequestApi.getClassRead(data).success(res => {
  621. const readInfo = res.data.data.list;
  622. console.log(res)
  623. readInfo.forEach(item => {
  624. const temp = {};
  625. temp.title = item.userRead ? item.userRead.title : '';
  626. temp.img = item.userRead.iconImg;
  627. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  628. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  629. temp.shareAmount = item.userRead.shareAmount;
  630. temp.favoritesAmount = item.userRead.favoritesAmount;
  631. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  632. temp.classId = item.userRead.exampleId;
  633. temp.time = formatDate(item.userRead.gmtCreated, 3);
  634. temp.avatar = item.user ? item.user.avatar : '';
  635. temp.uid = item.user ? item.user.uid : '';
  636. temp.url = item.userRead.videoPath;
  637. // temp.avatar = item.user.avatar;
  638. temp.nickName = item.user ? item.user.wechatName : '';
  639. temp.id = item.userRead.id;
  640. temp.noReading = true;
  641. temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
  642. temp.coverImg = item.userRead.coverImg;
  643. temp.videoShow = false;
  644. temp.grade = item.userRead.grade;
  645. temp.type = item.userRead.type;
  646. temp.shareImg = item.userRead.shareImg;
  647. // recommendWorks.push(temp);
  648. // that.data.hotData.hotWorks.push(temp);
  649. this.data.videoList.push(temp);
  650. });
  651. this.setData({
  652. videoList: this.data.videoList,
  653. totalSize: res.data.data.totalSize,
  654. noMoreWork: readInfo.length <= 0 ? true : false
  655. })
  656. });
  657. },
  658. // 评论区点击
  659. commentTap: function (e) {
  660. console.log('点击评论区', e)
  661. if (e.target.dataset.type === 'blank') {
  662. if (this.data.commentShow && this.data.commentId) {
  663. httpRequestApi.getClassDetail(this.data.commentId).success(res => {
  664. console.log('评论回显', res.data.data.userRead.commentAmount)
  665. let str = `videoList[${this.data.commentIndex}].commentAmount`;
  666. this.setData({
  667. [str]:res.data.data.userRead.commentAmount
  668. })
  669. })
  670. }
  671. this.setData({
  672. commentShow: false
  673. })
  674. }
  675. },
  676. scrollToLower: function (e) {
  677. console.log('滑动到底部', e)
  678. this.setData({
  679. pageNo: this.data.pageNo + 1
  680. }, () => {
  681. this.getReadInfo()
  682. })
  683. },
  684. onReachBottom: function (e) {
  685. console.log('滑动到底部', e)
  686. this.setData({
  687. pageNo: this.data.pageNo + 1
  688. }, () => {
  689. this.getReadInfo()
  690. })
  691. },
  692. scrollToUpper: function (e) {
  693. console.log('滑动到顶部', e)
  694. },
  695. // 打开评论
  696. openComment: function (e) {
  697. console.log('id', e.detail.activeId)
  698. this.setData({
  699. commentShow: !this.data.commentShow,
  700. commentId: e.detail.activeId,
  701. commentIndex: e.detail.activeIndex
  702. });
  703. },
  704. goToReading: function (e) {
  705. this.setData({
  706. pageNo: 1,
  707. videoList: []
  708. })
  709. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  710. this.getClassInfo(id)
  711. },
  712. onShareAppMessage: function (res) {
  713. console.log('点击分享按钮', res)
  714. console.log('onShareAppMessage', this.data.shareTitle)
  715. console.log('onShareAppMessage', this.data.shareId)
  716. console.log('onShareAppMessage', this.data.shareImg)
  717. if (res.from === 'button') {
  718. return {
  719. title: '请欣赏我的课文朗读作品,点赞+评论。',
  720. path: `/pages/index/index?readId=${this.data.shareId}`,
  721. imageUrl: this.data.shareImg
  722. }
  723. } else {
  724. return {
  725. title: '课文朗读,从未如此有趣。',
  726. path: '/pages/index/index',
  727. }
  728. }
  729. },
  730. touchMove: function () {
  731. return
  732. },
  733. openShare: function (e) {
  734. console.log('用户点击分享按钮回调', e)
  735. this.setData({
  736. shareTitle: e.detail.currentTarget.dataset.title,
  737. shareId: e.detail.currentTarget.dataset.id,
  738. shareImg: e.detail.currentTarget.dataset.shareimg
  739. })
  740. },
  741. onPlay: function (e) {
  742. // 下边视频列表onplay
  743. console.log('视频播放视频播放')
  744. if (this.videoCtx) {
  745. this.videoCtx.stop();
  746. } else {
  747. this.videoCtx = wx.createVideoContext('myVideo', this);
  748. this.videoCtx.stop();
  749. }
  750. },
  751. collectTap: function (e) {
  752. const index = e.detail.index;
  753. let str = `videoList[${index}].isFavorite`;
  754. let str2 = `videoList[${index}].favoritesAmount`;
  755. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  756. this.setData({
  757. [str]: e.detail.isCollect,
  758. [str2]: favoritesAmount
  759. })
  760. },
  761. likeTap: function (e) {
  762. console.log('点赞', e)
  763. const index = e.detail.index;
  764. let likeStr = `videoList[${index}].isLike`;
  765. let likeNumStr = `videoList[${index}].likes`;
  766. this.setData({
  767. [likeStr]: true,
  768. [likeNumStr]: this.data.videoList[index].likes + 1
  769. })
  770. },
  771. flowerAnimationHandler: function () {
  772. this.flowerBox = this.selectComponent("#flower-toast");
  773. console.log('this.flower', this.flowerBox)
  774. this.flowerBox.comeOut();
  775. },
  776. // 获取焦点事件
  777. inputFocus(e) {
  778. this.setData({
  779. isScroll: false
  780. })
  781. this.triggerEvent('inputFocus');
  782. },
  783. // 失去焦点事件
  784. inputBlur(e) {
  785. this.setData({
  786. isScroll: true
  787. })
  788. this.triggerEvent('inputBlur');
  789. },
  790. addShareAmount: function (e) {
  791. console.log('+++++1', e)
  792. let str = `videoList[${e.detail.index}].shareAmount`;
  793. this.setData({
  794. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  795. })
  796. }
  797. })