detail.js 2.1 KB

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