index.js 2.4 KB

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