reading.js 32 KB

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