detail.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // miniprogram/pages/detail/detail.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. detail: {}
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: async function (options) {
  13. wx.setNavigationBarTitle({
  14. title: options.title || "详情"
  15. })
  16. const db = wx.cloud.database();
  17. const _ = db.command;
  18. const _this = this;
  19. let list = await db.collection('data_news').where({
  20. _id: _.eq(options.id)
  21. }).get();
  22. if (!list.data.length) return wx.showToast({
  23. title: '数据走丢了',
  24. icon: "error"
  25. })
  26. let D = list.data[0] || {};
  27. if (D.type !== 2 && D.content) {
  28. D.content = D.content.replace(/<p>/gi, '<p style="text-indent: 2em">').replace(/<img/gi, "<img style='width:100%'")
  29. }
  30. _this.setData({
  31. detail: D
  32. })
  33. },
  34. /**
  35. * 生命周期函数--监听页面初次渲染完成
  36. */
  37. onReady: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面显示
  41. */
  42. onShow: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面隐藏
  46. */
  47. onHide: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面卸载
  51. */
  52. onUnload: function () {
  53. },
  54. /**
  55. * 页面相关事件处理函数--监听用户下拉动作
  56. */
  57. onPullDownRefresh: function () {
  58. },
  59. /**
  60. * 页面上拉触底事件的处理函数
  61. */
  62. onReachBottom: function () {
  63. },
  64. /**
  65. * 用户点击右上角分享
  66. */
  67. onShareAppMessage: function () {
  68. }
  69. })