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

Merge branch 'dev' of http://git.ycjcjy.com/zhiyuxing/miniapp-v3 into dev

xujing преди 5 години
родител
ревизия
29292cc638
променени са 2 файла, в които са добавени 64 реда и са изтрити 1 реда
  1. 3
    1
      src/pages/news/detail/index.js
  2. 61
    0
      src/utils/page.js

+ 3
- 1
src/pages/news/detail/index.js Целия файл

@@ -24,8 +24,10 @@ import {
24 24
   cancelFavorNews
25 25
 } from '@services/news'
26 26
 import { connect } from '@tarojs/redux'
27
+import { withUtils } from '@utils/page'
27 28
 
28 29
 @connect(state => state.user)
30
+// @withUtils()
29 31
 export default class NewsDetail extends Component {
30 32
   config = {
31 33
     navigationBarTitleText: '资讯详情'
@@ -47,7 +49,7 @@ export default class NewsDetail extends Component {
47 49
   }
48 50
 
49 51
   componentWillMount(options) {
50
-    console.info('ready status3', ready)
52
+    console.info('=====news ========>', this)
51 53
     ready.queue(() => {
52 54
       const router = Taro.getStorageSync('router') || { query: {} }
53 55
       console.info('news-1:', router)

+ 61
- 0
src/utils/page.js Целия файл

@@ -0,0 +1,61 @@
1
+import Taro from '@tarojs/taro'
2
+import { getQrCodeParams } from '@utils/qrcode'
3
+import { savePoint, updatePoint } from '@services/common'
4
+
5
+function isFunction(fn) {
6
+  return typeof fn === 'function'
7
+}
8
+
9
+export function withUtils(opts = {}) {
10
+  let trackEnd;
11
+
12
+  return function (OrigComp) {  
13
+    class WrapperComponent extends OrigComp {
14
+      async componentWillMount() {
15
+        if (this.$router.params.scene) {
16
+          this._$_scene = await getQrCodeParams(this.$router.params.scene)
17
+        }
18
+  
19
+        if (super.componentWillMount) {
20
+          super.componentWillMount();
21
+        }
22
+      }
23
+  
24
+      async componentDidShow() {
25
+        // 埋点
26
+        if (isFunction(this._$_track)) {
27
+          const { recordId } = await savePoint(this._$_track())
28
+
29
+          trackEnd = () => updatePoint(recordId)
30
+        }
31
+  
32
+        if (super.componentDidShow) {
33
+          super.componentDidShow();
34
+        }
35
+      }
36
+  
37
+      componentDidHide() {
38
+        // 埋点
39
+        if (isFunction(trackEnd)) {
40
+          trackEnd()
41
+        }
42
+  
43
+        if (super.componentDidHide) {
44
+          super.componentDidHide();
45
+        }
46
+      }
47
+  
48
+      onShareAppMessage() {
49
+        const { title, path, image }  = isFunction(this._$shareContent) ? this._$shareContent() : {}
50
+
51
+        return {
52
+          title,
53
+          path,
54
+          imageUrl: image,
55
+        }
56
+      }
57
+    }
58
+
59
+    return WrapperComponent
60
+  }
61
+}