index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // miniprogram/pages/marvellous/index.js;
  2. const app = getApp();
  3. Page({
  4. imgList: [],
  5. downCount: 0,
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. pageList: [],
  11. select: { count: 0 },
  12. pageType: "",
  13. showVideo: "",
  14. showAnVideo: true
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. wx.setNavigationBarTitle({
  21. title: options.title || "精彩瞬间"
  22. })
  23. this.init(options);
  24. },
  25. init(options) {
  26. app.globalData.origin[options.type].map(v=> this.imgList.push(v.url))
  27. console.log( app.globalData.origin,options.type)
  28. this.setData({
  29. pageList: app.globalData.origin[options.type],
  30. pageType: options.type || "img",
  31. showAnVideo: options.type === "video"
  32. })
  33. },
  34. /**
  35. * 生命周期函数--监听页面初次渲染完成
  36. */
  37. onReady: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面显示
  41. */
  42. onShow: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面隐藏
  46. */
  47. onHide: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面卸载
  51. */
  52. onUnload: function () {
  53. },
  54. /**
  55. * 页面相关事件处理函数--监听用户下拉动作
  56. */
  57. onPullDownRefresh: function () {
  58. },
  59. /**
  60. * 页面上拉触底事件的处理函数
  61. */
  62. onReachBottom: function () {
  63. },
  64. /**
  65. * 用户点击右上角分享
  66. */
  67. onShareAppMessage: function () {
  68. },
  69. showImg(e) {
  70. if (this.data.pageType === "video") return this.showVideo(e);
  71. if (this.data.pageType === "img") return this.showImage(e);
  72. },
  73. showVideo: function (e) {
  74. this.setData({
  75. showVideo: this.imgList[e.currentTarget.dataset.o]
  76. })
  77. },
  78. showImage: function (e) {
  79. wx.previewImage({
  80. urls: this.imgList,
  81. current: this.imgList[e.currentTarget.dataset.o],
  82. })
  83. },
  84. longtap: function (e) {
  85. // this.setData({
  86. // showSelect: true
  87. // })
  88. },
  89. longClose: function (e) {
  90. let pageList = this.data.pageList;
  91. let select = this.data.select;
  92. let keys = Object.keys(select);
  93. for (let i = 0; i < keys.length; i++) {
  94. let v = keys[i];
  95. if (v === 'count') continue;
  96. let li = v.split("-");
  97. pageList[li[0]].list[li[1]].select = false;
  98. }
  99. this.setData({
  100. pageList,
  101. select: {
  102. count: 0
  103. }
  104. })
  105. },
  106. format: function (res) {
  107. if (!res) return ""
  108. let T = new Date(res || 0);
  109. let year = T.getFullYear();
  110. let month = T.getMonth() + 1;
  111. let day = T.getDate();
  112. let hour = T.getHours();
  113. let min = T.getMinutes() + 1;
  114. let sec = T.getSeconds();
  115. return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec);
  116. },
  117. downEnd: function () {
  118. this.downCount--;
  119. if (this.downCount <= 0) {
  120. wx.hideLoading();
  121. }
  122. },
  123. closeVideo: function () {
  124. this.setData({
  125. showVideo: ""
  126. })
  127. },
  128. closeAnvido: function () {
  129. this.setData({
  130. showAnVideo: false
  131. })
  132. }
  133. })