Преглед на файлове

feat: support tcm constitution webview sharing

danyshen преди 1 седмица
родител
ревизия
7b0e6757a2
променени са 2 файла, в които са добавени 35 реда и са изтрити 7 реда
  1. 34 6
      pages/web/web.js
  2. 1 1
      pages/web/web.wxml

+ 34 - 6
pages/web/web.js

@@ -1,7 +1,10 @@
 var _request = require('../../utils/request.js')
 Page({
   data: {
-    url: ''
+    url: '',
+    shareTitle: '凤凰菁选商城',
+    sharePath: '',
+    shareImageUrl: ''
   },
   onLoad: function (options) {
     console.log(options)
@@ -13,18 +16,43 @@ Page({
 		links = url;
 	}
     this.setData({
-      url: links
+      url: links,
+      sharePath: links
     })
     // wx.setNavigationBarTitle({
     //   title: 'sdsd'
     // })
   },
+  onWebMessage: function (event) {
+    var list = event && event.detail && event.detail.data
+    if (!Array.isArray(list) || !list.length) {
+      return
+    }
+    var data = list[list.length - 1] || {}
+    if (data.shareSource !== 'tcm_constitution') {
+      return
+    }
+    var next = {}
+    if (data.shareTitle) {
+      next.shareTitle = data.shareTitle
+    }
+    if (data.shareUrl) {
+      next.sharePath = data.shareUrl
+    }
+    if (data.shareImageUrl) {
+      next.shareImageUrl = data.shareImageUrl
+    }
+    if (Object.keys(next).length) {
+      this.setData(next)
+    }
+  },
   onShareAppMessage: function (val) {
+    var shareUrl = this.data.sharePath || this.data.url
     return _request.share({
-      title: '凤凰菁选商城',
-      path: '/pages/start/start?url=pages/web/web&id=' + this.data.url,
-      imageUrl: '',
-      sc: 'cxc_web'
+      title: this.data.shareTitle || '凤凰菁选商城',
+      path: '/pages/start/start?url=pages/web/web&id=' + encodeURIComponent(shareUrl),
+      imageUrl: this.data.shareImageUrl || '',
+      sc: this.data.shareTitle === '九型体质评测' ? 'tcm_constitution_share' : 'cxc_web'
     })
   }
 })

+ 1 - 1
pages/web/web.wxml

@@ -3,5 +3,5 @@
     <view class="about-title">关于我们</view>
     <view class="about-time"></view>
   </view> -->
-  <web-view class="web" src="{{url}}" ></web-view>
+  <web-view class="web" src="{{url}}" bindmessage="onWebMessage"></web-view>
 </view>