detail.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // miniprogram/pages/detail/detail.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. detail: {}
  8. },
  9. nameText: "",
  10. idText: "",
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: async function (options) {
  15. this.nameText = decodeURIComponent(options.title || "详情");
  16. this.idText = options.id || "";
  17. wx.setNavigationBarTitle({
  18. title: this.nameText
  19. })
  20. // const db = wx.cloud.database();
  21. // const _ = db.command;
  22. // let list = await db.collection('data_news').where({
  23. // _id: _.eq(options.id)
  24. // }).get();
  25. // let D = list.data[0] || {};
  26. // D.content = D.content.replace(/style=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/width=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/height=\"([a-z|A-Z|-|:|;|0-9|\.]*)\"/g, "").replace(/<img/g, "<img style='width: 100%'").replace(/<p/gi, '<p style="text-indent: 2em;min-height: 1em"')
  27. // if (D.creat_time) D.creat_time = this.format(D.creat_time);
  28. // _this.setData({
  29. // detail: D,
  30. // })
  31. wx.showShareMenu({
  32. withShareTicket: true,
  33. });
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面隐藏
  47. */
  48. onHide: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面卸载
  52. */
  53. onUnload: function () {
  54. },
  55. /**
  56. * 页面相关事件处理函数--监听用户下拉动作
  57. */
  58. onPullDownRefresh: function () {
  59. },
  60. /**
  61. * 页面上拉触底事件的处理函数
  62. */
  63. onReachBottom: function () {
  64. },
  65. /**
  66. * 用户点击右上角分享
  67. */
  68. onShareAppMessage: function () {
  69. return {
  70. title: this.nameText, // 分享名称
  71. path: 'pages/detail/detail?title=' + this.nameText + '&id=' + this.data.id, // 点击分享后的链接要来到的页面的路径已经对应需要的参数
  72. }
  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. })