index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // pages/liveVideo/index.js
  2. import api from "../../api/index";
  3. import {
  4. config
  5. } from "../../config/index"
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. videos: []
  12. },
  13. page: 1,
  14. size: 10,
  15. total: 0,
  16. toPage(e) {
  17. const item = this.data.videos[e.currentTarget.dataset.index]
  18. if (item.type == 1) {
  19. // 全屏放视频 木得办法 内容太少
  20. wx.previewMedia({
  21. sources: [{
  22. url: item.video,
  23. type: 'video',
  24. poster: item.cover
  25. }]
  26. })
  27. return
  28. }
  29. if (item.type == 2) { // 视频号视频
  30. const [finderUserName, feedId] = item.video.split(',')
  31. wx.openChannelsActivity({
  32. finderUserName,
  33. feedId,
  34. fail() {
  35. wx.showToast({
  36. title: '请稍后再试',
  37. })
  38. }
  39. })
  40. return
  41. }
  42. },
  43. getLiveVideo(id) {
  44. const {
  45. page,
  46. size
  47. } = this;
  48. api.getLiveVideo({
  49. page,
  50. size,
  51. id
  52. }).then(r => {
  53. this.page += 1;
  54. this.total = r.total;
  55. this.setData({
  56. videos: r.records || []
  57. })
  58. })
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad(options) {
  64. this.getLiveVideo(config.meetID)
  65. },
  66. /**
  67. * 生命周期函数--监听页面初次渲染完成
  68. */
  69. onReady() {
  70. },
  71. /**
  72. * 生命周期函数--监听页面显示
  73. */
  74. onShow() {
  75. },
  76. /**
  77. * 生命周期函数--监听页面隐藏
  78. */
  79. onHide() {
  80. },
  81. /**
  82. * 生命周期函数--监听页面卸载
  83. */
  84. onUnload() {
  85. },
  86. /**
  87. * 页面相关事件处理函数--监听用户下拉动作
  88. */
  89. onPullDownRefresh() {
  90. },
  91. /**
  92. * 页面上拉触底事件的处理函数
  93. */
  94. onReachBottom() {
  95. this.getLiveVideo(config.meetID)
  96. },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage() {
  101. },
  102. onShareTimeline() {}
  103. })