detail.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. wx.showShareMenu({
  38. withShareTicket: true,
  39. });
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload: function () {
  60. },
  61. /**
  62. * 页面相关事件处理函数--监听用户下拉动作
  63. */
  64. onPullDownRefresh: function () {
  65. },
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom: function () {
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function () {
  75. return {
  76. title: this.nameText, // 分享名称
  77. path: 'pages/detail/detail?title=' + this.nameText + '&id=' + this.data.id, // 点击分享后的链接要来到的页面的路径已经对应需要的参数
  78. }
  79. },
  80. format: function (res) {
  81. if (!res) return "";
  82. let num = (res || 0) - 0;
  83. let T = new Date(num);
  84. let year = T.getFullYear();
  85. let month = T.getMonth() + 1;
  86. let day = T.getDate();
  87. let hour = T.getHours();
  88. let min = T.getMinutes() + 1;
  89. let sec = T.getSeconds();
  90. return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec);
  91. },
  92. })