detail.js 2.4 KB

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