detail.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // miniprogram/pages/detail/detail.js
  2. import {
  3. httpCloud
  4. } from "../../utils/httpFunc";
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. detail: {}
  11. },
  12. nameText: "",
  13. idText: "",
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: async function (options) {
  18. const _this = this;
  19. this.nameText = decodeURIComponent(options.title || "详情");
  20. this.idText = options.id || "";
  21. options.title && wx.setNavigationBarTitle({
  22. title: this.nameText
  23. })
  24. httpCloud({
  25. name: "server",
  26. type: "getArticle",
  27. data: {
  28. id: options.id,
  29. },
  30. call(res) {
  31. res.article_detail = res.article_detail.replace(/<img /g, "<img style='max-width:100%'");
  32. _this.setData({
  33. detail: res || {}
  34. })
  35. }
  36. })
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function () {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function () {
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function () {
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function () {
  72. return {
  73. title: "", // 分享名称
  74. path: 'pages/home/index', // 点击分享后的链接要来到的页面的路径已经对应需要的参数
  75. }
  76. },
  77. format: function (res) {
  78. if (!res) return "";
  79. let num = (res || 0) - 0;
  80. let T = new Date(num);
  81. let year = T.getFullYear();
  82. let month = T.getMonth() + 1;
  83. let day = T.getDate();
  84. let hour = T.getHours();
  85. let min = T.getMinutes() + 1;
  86. let sec = T.getSeconds();
  87. return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec);
  88. },
  89. })