interList.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // miniprogram/pages/interList/interList.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. newsList: []
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: async function (options) {
  13. console.log(options.type)
  14. if (options.type == "news") {
  15. wx.setNavigationBarTitle({
  16. title: '新闻列表'
  17. })
  18. } else {
  19. wx.setNavigationBarTitle({
  20. title: '视频列表'
  21. })
  22. }
  23. const db = wx.cloud.database();
  24. let list = await db.collection('data_news').where({
  25. type: 1
  26. }).get();
  27. for (let i = 0; i < list.data.length; i++) {
  28. const v = list.data[i];
  29. if (v.creat_time) v.creat_time = this.format(v.creat_time || 0)
  30. }
  31. console.log(list.data)
  32. this.setData({
  33. newsList: list.data || []
  34. })
  35. },
  36. /**
  37. * 生命周期函数--监听页面初次渲染完成
  38. */
  39. onReady: function () {
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面隐藏
  48. */
  49. onHide: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面卸载
  53. */
  54. onUnload: function () {
  55. },
  56. /**
  57. * 页面相关事件处理函数--监听用户下拉动作
  58. */
  59. onPullDownRefresh: function () {
  60. },
  61. /**
  62. * 页面上拉触底事件的处理函数
  63. */
  64. onReachBottom: function () {
  65. },
  66. /**
  67. * 用户点击右上角分享
  68. */
  69. onShareAppMessage: function () {
  70. },
  71. tolist: function (e) {
  72. console.log(e)
  73. },
  74. format: function (res) {
  75. if (!res) return ""
  76. let num = (res || 0) -0
  77. let T = new Date(num);
  78. let year = T.getFullYear();
  79. let month = T.getMonth() + 1;
  80. let day = T.getDate();
  81. let hour = T.getHours();
  82. let min = T.getMinutes() + 1;
  83. let sec = T.getSeconds();
  84. return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec);
  85. },
  86. toDetail:function(e){
  87. let title = e.currentTarget.dataset.title, id = e.currentTarget.dataset.id;
  88. wx.navigateTo({
  89. url: '/pages/detail/detail?title=' + title + "&id=" + id,
  90. })
  91. }
  92. })