|
@@ -0,0 +1,105 @@
|
|
1
|
+let privacyHandler
|
|
2
|
+let privacyResolves = new Set()
|
|
3
|
+let closeOtherPagePopUpHooks = new Set()
|
|
4
|
+
|
|
5
|
+if (wx.onNeedPrivacyAuthorization) {
|
|
6
|
+ wx.onNeedPrivacyAuthorization(resolve => {
|
|
7
|
+ if (typeof privacyHandler === 'function') {
|
|
8
|
+ privacyHandler(resolve)
|
|
9
|
+ }
|
|
10
|
+ })
|
|
11
|
+}
|
|
12
|
+
|
|
13
|
+const closeOtherPagePopUp = (closePopUp) => {
|
|
14
|
+ closeOtherPagePopUpHooks.forEach(hook => {
|
|
15
|
+ if (closePopUp !== hook) {
|
|
16
|
+ hook()
|
|
17
|
+ }
|
|
18
|
+ })
|
|
19
|
+}
|
|
20
|
+
|
|
21
|
+Component({
|
|
22
|
+ data: {
|
|
23
|
+ title: "用户隐私保护提示",
|
|
24
|
+ desc1: "感谢您使用本小程序,您使用本小程序前应当阅井同意",
|
|
25
|
+ urlTitle: "《用户隐私保护指引》",
|
|
26
|
+ desc2: "当您点击同意并开始时用产品服务时,即表示你已理解并同息该条款内容,该条款将对您产生法律约束力。如您拒绝,将无法继续访问小程序。",
|
|
27
|
+ innerShow: false,
|
|
28
|
+ height: 0,
|
|
29
|
+ },
|
|
30
|
+ lifetimes: {
|
|
31
|
+ attached: function() {
|
|
32
|
+ const closePopUp = () => {
|
|
33
|
+ this.disPopUp()
|
|
34
|
+ }
|
|
35
|
+ privacyHandler = resolve => {
|
|
36
|
+ privacyResolves.add(resolve)
|
|
37
|
+ this.popUp()
|
|
38
|
+ // 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
|
39
|
+ closeOtherPagePopUp(closePopUp)
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ this.closePopUp = closePopUp
|
|
43
|
+ closeOtherPagePopUpHooks.add(this.closePopUp)
|
|
44
|
+ },
|
|
45
|
+ detached: function() {
|
|
46
|
+ closeOtherPagePopUpHooks.delete(this.closePopUp)
|
|
47
|
+ }
|
|
48
|
+ },
|
|
49
|
+ methods: {
|
|
50
|
+ handleAgree(e) {
|
|
51
|
+ this.disPopUp()
|
|
52
|
+ // 这里演示了同时调用多个wx隐私接口时要如何处理:让隐私弹窗保持单例,点击一次同意按钮即可让所有pending中的wx隐私接口继续执行 (看page/index/index中的 wx.getClipboardData 和 wx.startCompass)
|
|
53
|
+ privacyResolves.forEach(resolve => {
|
|
54
|
+ resolve({
|
|
55
|
+ event: 'agree',
|
|
56
|
+ buttonId: 'agree-btn'
|
|
57
|
+ })
|
|
58
|
+ })
|
|
59
|
+ privacyResolves.clear()
|
|
60
|
+ },
|
|
61
|
+ handleDisagree(e) {
|
|
62
|
+ this.disPopUp()
|
|
63
|
+ privacyResolves.forEach(resolve => {
|
|
64
|
+ resolve({
|
|
65
|
+ event: 'disagree',
|
|
66
|
+ })
|
|
67
|
+ })
|
|
68
|
+ privacyResolves.clear()
|
|
69
|
+ },
|
|
70
|
+ popUp() {
|
|
71
|
+ if (this.data.innerShow === false) {
|
|
72
|
+ this.setData({
|
|
73
|
+ innerShow: true
|
|
74
|
+ })
|
|
75
|
+ }
|
|
76
|
+ },
|
|
77
|
+ disPopUp() {
|
|
78
|
+ if (this.data.innerShow === true) {
|
|
79
|
+ this.setData({
|
|
80
|
+ innerShow: false
|
|
81
|
+ })
|
|
82
|
+ }
|
|
83
|
+ },
|
|
84
|
+ openPrivacyContract() {
|
|
85
|
+ wx.openPrivacyContract({
|
|
86
|
+ success: res => {
|
|
87
|
+ console.log('openPrivacyContract success')
|
|
88
|
+ },
|
|
89
|
+ fail: res => {
|
|
90
|
+ console.error('openPrivacyContract fail', res)
|
|
91
|
+ }
|
|
92
|
+ })
|
|
93
|
+ },
|
|
94
|
+ tabBarPageShow() {
|
|
95
|
+ if (this.closePopUp) {
|
|
96
|
+ privacyHandler = resolve => {
|
|
97
|
+ privacyResolves.add(resolve)
|
|
98
|
+ this.popUp()
|
|
99
|
+ // 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗
|
|
100
|
+ closeOtherPagePopUp(this.closePopUp)
|
|
101
|
+ }
|
|
102
|
+ }
|
|
103
|
+ }
|
|
104
|
+ }
|
|
105
|
+})
|