index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // pages/imgController/index.js
  2. import {
  3. httpCloud
  4. } from "../../utils/httpFunc";
  5. import {
  6. dateFormmat
  7. } from "../../utils/tool"
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. mediaList: [],
  14. },
  15. nameText: "",
  16. page: 0,
  17. limit: 100,
  18. getDate() {
  19. const _this = this;
  20. httpCloud({
  21. name: "server",
  22. type: "getMediaController",
  23. data: {
  24. typeMedia: this.mediaType,
  25. page: this.page,
  26. limit: this.limit
  27. },
  28. call(res) {
  29. if (!res.length) {
  30. this.page = -1;
  31. return
  32. }
  33. _this.setData({
  34. mediaList: (res || []).map(v => {
  35. const date = dateFormmat(v.date);
  36. return {
  37. ...v,
  38. date: [date.year, date.month, date.day].join("-"),
  39. mediaType: _this.mediaType,
  40. }
  41. })
  42. })
  43. }
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad(options) {
  50. this.nameText = decodeURIComponent(options.title || "详情");
  51. this.mediaType = options.mediaType || 'image';
  52. wx.setNavigationBarTitle({
  53. title: this.nameText
  54. })
  55. this.page = 0;
  56. this.getDate()
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady() {},
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow() {},
  66. /**
  67. * 生命周期函数--监听页面隐藏
  68. */
  69. onHide() {},
  70. /**
  71. * 生命周期函数--监听页面卸载
  72. */
  73. onUnload() {},
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh() {},
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom() {
  82. if (this.page === -1) return;
  83. this.page += 1;
  84. this.getDate();
  85. },
  86. onShareAppMessage: function () {
  87. return {
  88. title: this.nameText, // 分享名称
  89. path: 'pages/home/index', // 点击分享后的链接要来到的页面的路径已经对应需要的参数
  90. }
  91. },
  92. })