reading.js 32 KB

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