index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/media/index.js
  2. import api from "../../api/index";
  3. const {
  4. globalData: {
  5. systemInfo
  6. }
  7. } = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. actMeet: '',
  14. top: {
  15. height: 0,
  16. width: systemInfo.windowWidth
  17. },
  18. phone: {
  19. width: (systemInfo.windowWidth - 20) / 3,
  20. height: 0
  21. },
  22. tabs: [],
  23. images: [],
  24. cover: ""
  25. },
  26. page: 1,
  27. size: 10,
  28. total: 0,
  29. changeMeet(e) {
  30. this.page = 1;
  31. this.getPhone(e.detail.name);
  32. },
  33. imageLoad(e) {
  34. const {
  35. width,
  36. height
  37. } = e.detail;
  38. const image = e.currentTarget.dataset.image || 'top';
  39. const p = {};
  40. p[image] = {
  41. ...this.data[image]
  42. }
  43. p[image].height = height / width * p[image].width
  44. this.setData(p);
  45. },
  46. showImage(e) {
  47. wx.previewMedia({
  48. sources: this.data.images.map(v => {
  49. return {
  50. url: v.photo
  51. }
  52. }),
  53. current: e.currentTarget.dataset.index
  54. })
  55. },
  56. // 获取图片直播
  57. getPhone(id) {
  58. const {
  59. page,
  60. size
  61. } = this;
  62. api.getLivePhone({
  63. page,
  64. size,
  65. id
  66. }).then(res => {
  67. this.page += 1;
  68. this.total = res.total;
  69. this.setData({
  70. images: res.records || []
  71. })
  72. })
  73. },
  74. /**
  75. * 生命周期函数--监听页面加载
  76. */
  77. onLoad(options) {
  78. this.setData({
  79. cover: options.cover
  80. })
  81. api.getStroke().then(strokeList => {
  82. const item = strokeList[0] || {}
  83. this.setData({
  84. actMeet: item.id + "",
  85. tabs: strokeList
  86. })
  87. this.getPhone(item.id);
  88. })
  89. },
  90. /**
  91. * 生命周期函数--监听页面初次渲染完成
  92. */
  93. onReady() {
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow() {
  99. },
  100. /**
  101. * 生命周期函数--监听页面隐藏
  102. */
  103. onHide() {
  104. },
  105. /**
  106. * 生命周期函数--监听页面卸载
  107. */
  108. onUnload() {
  109. },
  110. /**
  111. * 页面相关事件处理函数--监听用户下拉动作
  112. */
  113. onPullDownRefresh() {
  114. },
  115. /**
  116. * 页面上拉触底事件的处理函数
  117. */
  118. onReachBottom() {
  119. if (this.total <= this.data.images.length) return
  120. this.getPhone(this.data.actMeet);
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage() {
  126. },
  127. onShareTimeline() {}
  128. })