index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. console.log(options, 'options');
  24. let videoId = options.videoId
  25. this.setData({
  26. videoId,
  27. isShare: options.isShare
  28. })
  29. this.getreadInfo(videoId)
  30. this.getPkRecord()
  31. },
  32. async getreadInfo(videoId) {
  33. let videoInfo = await getreadInfo(videoId)
  34. wx.setNavigationBarTitle({
  35. title: !this.data.isShare ? videoInfo.userRead.title : '推荐'
  36. })
  37. if (videoInfo.userReadExtend.resourcesType == 1) {
  38. this.playAudio({
  39. currentTarget: {
  40. dataset: {
  41. id: videoId,
  42. audio: videoInfo.userRead.audioPath
  43. }
  44. }
  45. })
  46. }
  47. this.setData({
  48. videoInfo,
  49. audioPath: videoInfo.userRead.audioPath,
  50. currentId: videoId
  51. })
  52. },
  53. // pkPage页面示范朗读
  54. pkPageAudio({
  55. detail
  56. }) {
  57. this.setData({
  58. audioPath: detail.currentTarget.dataset.audio,
  59. })
  60. this.playAudio(detail)
  61. },
  62. async getPkRecord() {
  63. let recordList = await getPkRecord({
  64. userReadId: this.data.videoId
  65. })
  66. this.setData({
  67. recordList
  68. })
  69. },
  70. jumpUserInfo({
  71. currentTarget
  72. }) {
  73. wx.navigateTo({
  74. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  75. })
  76. },
  77. jumpIndex() {
  78. wx.switchTab({
  79. url: '/pages/index/index',
  80. })
  81. },
  82. addCommentNum() {
  83. this.setData({
  84. ['videoInfo.userRead.commentAmount']: ++this.data.videoInfo.userRead.commentAmount
  85. })
  86. },
  87. onUnload() {
  88. this.resetAudio()
  89. this.setData({
  90. currentId: ''
  91. })
  92. }
  93. })