index.js 2.2 KB

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