index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // pages/platform/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list: {},
  9. keys: []
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. const that = this;
  16. wx.request({
  17. url: app.baseUrl + '/article-list?platform=' + options.type + '&topic_name=' + options.title,
  18. success(res) {
  19. let lists = {};
  20. let keys = [];
  21. (res.data || []).map(v => {
  22. let time = new Date(v.create_time);
  23. let year = time.getFullYear();
  24. let month = time.getMonth();
  25. let day = time.getDate();
  26. let T = year;
  27. month + 1 > 9 ? T += '-' + (month + 1) : T += '-' + '0' + (month + 1);
  28. day + 1 > 9 ? T += '-' + (day + 1) : T += '-' + '0' + day;
  29. !lists[T] && keys.push(T);
  30. lists[T] ? lists[T].push(v) : lists[T] = [v]
  31. })
  32. that.setData({
  33. list: lists,
  34. keys
  35. })
  36. },
  37. fail(err) {
  38. }
  39. })
  40. },
  41. formatter: function (val) {
  42. let out = val;
  43. if (val >= 1000 && val < 10000) {
  44. out = (val / 1000).toFixed(2) - 0 + "千"
  45. } else if (val >= 10000 && val < 100000000) {
  46. out = (val / 10000).toFixed(0) - 0 + "万"
  47. } else if (val >= 100000000) {
  48. out = (val / 100000000).toFixed(2) - 0 + "亿"
  49. }
  50. return out
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload: function () {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom: function () {
  81. },
  82. /**
  83. * 用户点击右上角分享
  84. */
  85. onShareAppMessage: function () {
  86. }
  87. })