reading.js 25 KB

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