index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import behavior from '~/mixins/video'
  2. import event from '~/mixins/event'
  3. import share from '~/mixins/share'
  4. import {
  5. getreadInfo
  6. } from '~/api/video'
  7. import {
  8. getPkRecord
  9. } from '~/api/works'
  10. Page({
  11. behaviors: [behavior, share,event],
  12. data: {
  13. videoInfo: '',
  14. videoId: '',
  15. isShare: false,
  16. recordList: [],
  17. // 播放的音频
  18. audioPath: ''
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. let videoId = null
  25. let params = decodeURIComponent(options.scene).split('&')
  26. videoId = !options.scene ? options.videoId : params[0]
  27. this.setData({
  28. videoId,
  29. isShare: !options.scene ? options.isShare : true
  30. })
  31. this.getreadInfo(videoId)
  32. this.getPkRecord()
  33. },
  34. async getreadInfo(videoId) {
  35. let videoInfo = await getreadInfo(videoId)
  36. wx.setNavigationBarTitle({
  37. title: !this.data.isShare ? videoInfo.userRead.title : '推荐'
  38. })
  39. if (videoInfo.userReadExtend.resourcesType == 1) {
  40. this.playAudio({
  41. currentTarget: {
  42. dataset: {
  43. id: videoId,
  44. audio: videoInfo.userRead.audioPath
  45. }
  46. }
  47. })
  48. }
  49. this.setData({
  50. videoInfo,
  51. audioPath: videoInfo.userRead.audioPath,
  52. currentId: videoId
  53. })
  54. },
  55. // pkPage页面示范朗读
  56. pkPageAudio({
  57. detail
  58. }) {
  59. this.setData({
  60. audioPath: detail.currentTarget.dataset.audio,
  61. })
  62. this.playAudio(detail)
  63. },
  64. async getPkRecord() {
  65. let recordList = await getPkRecord({
  66. userReadId: this.data.videoId
  67. })
  68. this.setData({
  69. recordList
  70. })
  71. },
  72. jumpUserInfo({
  73. currentTarget
  74. }) {
  75. wx.navigateTo({
  76. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  77. })
  78. },
  79. jumpIndex() {
  80. wx.switchTab({
  81. url: '/pages/index/index',
  82. })
  83. },
  84. addCommentNum() {
  85. this.setData({
  86. ['videoInfo.userRead.commentAmount']: ++this.data.videoInfo.userRead.commentAmount
  87. })
  88. },
  89. /* onShareTimeline: function () {
  90. return {
  91. title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
  92. query: `uid=${wx.getStorageSync('uid')}&videoId=1676021823219008`,
  93. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
  94. }
  95. }, */
  96. onUnload() {
  97. this.resetAudio()
  98. this.setData({
  99. currentId: ''
  100. })
  101. }
  102. })