reading.js 32 KB

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