reading.js 30 KB

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