|
@@ -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
|
+}
|