detail.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // miniprogram/pages/detail/detail.js
  2. import { httpCloud } from "../../utils/httpFunc";
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. detail: {}
  9. },
  10. nameText: "",
  11. idText: "",
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: async function (options) {
  16. const _this = this;
  17. this.nameText = decodeURIComponent(options.title || "详情");
  18. this.idText = options.id || "";
  19. wx.setNavigationBarTitle({
  20. title: this.nameText
  21. })
  22. httpCloud({
  23. name: "server",
  24. type: "getArticle",
  25. data: {
  26. id: options.id,
  27. },
  28. call(res) {
  29. _this.setData({
  30. detail: res || {}
  31. })
  32. }
  33. })
  34. wx.showShareMenu({
  35. withShareTicket: true,
  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: this.nameText, // 分享名称
  74. path: 'pages/detail/detail?title=' + this.nameText + '&id=' + this.data.id, // 点击分享后的链接要来到的页面的路径已经对应需要的参数
  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. })