index.js 2.7 KB

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