reading.js 28 KB

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