liyongli 3 anni fa
parent
commit
d8c3e25271
1 ha cambiato i file con 14 aggiunte e 5 eliminazioni
  1. 14 5
      miniprogram/pages/detail/detail.js

+ 14 - 5
miniprogram/pages/detail/detail.js

@@ -5,7 +5,9 @@ Page({
    * 页面的初始数据
    */
   data: {
-    detail: {}
+    detail: {},
+    name: "",
+    id: ""
   },
 
   /**
@@ -13,7 +15,7 @@ Page({
    */
   onLoad: async function (options) {
     wx.setNavigationBarTitle({
-      title: options.title || "详情"
+      title: decodeURIComponent(options.title) || "详情"
     })
     const db = wx.cloud.database();
     const _ = db.command;
@@ -26,12 +28,16 @@ Page({
       icon: "error"
     })
     let D = list.data[0] || {};
-    console.log(D.content.match(/style=\"([a-z|A-Z|-|:|;|0-9]*)\"/g))
     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"')
     if (D.creat_time) D.creat_time = this.format(D.creat_time);
     _this.setData({
-      detail: D
+      detail: D,
+      id: options.id,
+      name: decodeURIComponent(options.title)
     })
+    wx.showShareMenu({
+      withShareTicket: true,
+    });
   },
   /**
    * 生命周期函数--监听页面初次渲染完成
@@ -79,7 +85,10 @@ Page({
    * 用户点击右上角分享
    */
   onShareAppMessage: function () {
-
+    return {
+      title: this.data.name,  // 分享名称
+      path: 'pages/detail/detail?title=' + this.data.name + '&id=' + this.data.id,  // 点击分享后的链接要来到的页面的路径已经对应需要的参数
+    }
   },
 
   format: function (res) {