reading.js 31 KB

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