index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. r.records && r.records.length && (this.page += 1);
  54. this.total = r.total;
  55. const list = [
  56. ...this.data.videos,
  57. ...(r.records || [])
  58. ]
  59. this.setData({
  60. videos: list
  61. })
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. onLoad(options) {
  68. this.getLiveVideo(config.meetID)
  69. },
  70. /**
  71. * 生命周期函数--监听页面初次渲染完成
  72. */
  73. onReady() {
  74. },
  75. /**
  76. * 生命周期函数--监听页面显示
  77. */
  78. onShow() {
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide() {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload() {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh() {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom() {
  99. this.getLiveVideo(config.meetID)
  100. },
  101. /**
  102. * 用户点击右上角分享
  103. */
  104. onShareAppMessage() {
  105. },
  106. onShareTimeline() {}
  107. })