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. res.records && res.records.length && (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. actMeet: id + ''
  79. })
  80. })
  81. },
  82. /**
  83. * 生命周期函数--监听页面加载
  84. */
  85. onLoad(options) {
  86. this.setData({
  87. cover: options.cover
  88. })
  89. api.getStroke().then(strokeList => {
  90. const item = strokeList[0] || {}
  91. this.setData({
  92. actMeet: item.id + "",
  93. tabs: strokeList
  94. })
  95. this.getPhone(item.id);
  96. })
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady() {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow() {
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide() {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload() {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh() {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom() {
  127. this.getPhone(this.data.actMeet);
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage() {
  133. },
  134. onShareTimeline() {}
  135. })