1.摇一摇防抖 2.coop码重置
Showing
4 changed files
with
110 additions
and
39 deletions
... | @@ -30,8 +30,23 @@ App({ | ... | @@ -30,8 +30,23 @@ App({ |
30 | coopOptions: null, // 协作页 onload入参 | 30 | coopOptions: null, // 协作页 onload入参 |
31 | }, | 31 | }, |
32 | onLaunch: function (options) { | 32 | onLaunch: function (options) { |
33 | console.log("app q:", decodeURIComponent(options.query.q)); | 33 | // console.log("app q:", decodeURIComponent(options.query.q)); |
34 | console.log("onLaunch options:", options) | ||
35 | this.globalData.coopOptions = null; | ||
34 | this.share(); | 36 | this.share(); |
37 | this.shake(); | ||
38 | }, | ||
39 | shake() { | ||
40 | wx.onAccelerometerChange(function (res) { | ||
41 | let pages = getCurrentPages(); | ||
42 | let view = pages[pages.length - 1]; | ||
43 | if (view) { | ||
44 | let data = view.data; | ||
45 | if (data.isShake) { | ||
46 | view.onShakeHandler(res); | ||
47 | } | ||
48 | } | ||
49 | }); | ||
35 | }, | 50 | }, |
36 | //重写分享方法 | 51 | //重写分享方法 |
37 | share: function () { | 52 | share: function () { |
... | @@ -53,11 +68,12 @@ App({ | ... | @@ -53,11 +68,12 @@ App({ |
53 | title: '弹弹弹 看你有多弹', | 68 | title: '弹弹弹 看你有多弹', |
54 | path: 'pages/index/index', | 69 | path: 'pages/index/index', |
55 | // imageUrl: './image/share.png', | 70 | // imageUrl: './image/share.png', |
56 | // imageUrl: 'https://kd.cdn.xyiyang.com/weapp/marubi/wish-list/share.png' | 71 | imageUrl: 'https://kd.cdn.xyiyang.com/weapp/marubi/wish-list/share.png' |
57 | imageUrl: 'https://kdcdn.oss-cn-shenzhen.aliyuncs.com/weapp/marubi/wish-list/share.png' | 72 | // imageUrl: 'https://kdcdn.oss-cn-shenzhen.aliyuncs.com/weapp/marubi/wish-list/share.png' |
58 | }; | 73 | }; |
59 | }; | 74 | }; |
60 | } | 75 | } |
76 | |||
61 | } | 77 | } |
62 | }) | 78 | }) |
63 | }, | 79 | }, | ... | ... |
1 | import { | 1 | import { |
2 | getBindtapData, | 2 | getBindtapData, |
3 | getObjByListKeyValue | 3 | getObjByListKeyValue, |
4 | debounce, | ||
4 | } from '../../utils/util'; | 5 | } from '../../utils/util'; |
5 | 6 | ||
6 | import { | 7 | import { |
... | @@ -27,7 +28,10 @@ Page({ | ... | @@ -27,7 +28,10 @@ Page({ |
27 | animationShake: {}, // 摇一摇动画 | 28 | animationShake: {}, // 摇一摇动画 |
28 | aniTimeoutIndex: 0, | 29 | aniTimeoutIndex: 0, |
29 | initComplete: false, | 30 | initComplete: false, |
31 | initShakeComplete: false, | ||
32 | isShake: true, | ||
30 | }, | 33 | }, |
34 | |||
31 | onShareAppMessage() {}, | 35 | onShareAppMessage() {}, |
32 | showAuth() { | 36 | showAuth() { |
33 | this.setData({ | 37 | this.setData({ |
... | @@ -38,13 +42,18 @@ Page({ | ... | @@ -38,13 +42,18 @@ Page({ |
38 | this.setData({ | 42 | this.setData({ |
39 | options | 43 | options |
40 | }) | 44 | }) |
45 | console.log("coop options:", options); | ||
41 | // 注册回调的入参 | 46 | // 注册回调的入参 |
42 | if (app.globalData.coopOptions) { | 47 | if (!options.code) { |
43 | this.setData({ | 48 | if (app.globalData.coopOptions) { |
44 | options: app.globalData.coopOptions | 49 | this.setData({ |
45 | }) | 50 | options: app.globalData.coopOptions |
51 | }) | ||
52 | console.log("app.globalData.coopOptions:", app.globalData.coopOptions); | ||
53 | app.globalData.coopOptions = null; | ||
54 | } | ||
46 | } | 55 | } |
47 | 56 | // this.initData(); | |
48 | console.log("onLoad"); | 57 | console.log("onLoad"); |
49 | }, | 58 | }, |
50 | onHide() {}, | 59 | onHide() {}, |
... | @@ -77,24 +86,60 @@ Page({ | ... | @@ -77,24 +86,60 @@ Page({ |
77 | tipsGuideRegisterVisible: true | 86 | tipsGuideRegisterVisible: true |
78 | }) | 87 | }) |
79 | } | 88 | } |
89 | this.initShake(); | ||
80 | }) | 90 | }) |
81 | this.initShake(); | ||
82 | }) | 91 | }) |
83 | }, | 92 | }, |
84 | // 添加摇一摇 | 93 | // 添加摇一摇 |
94 | // initShake() { | ||
95 | // console.log("initShake start"); | ||
96 | // if (this.data.initShakeComplete) { | ||
97 | // return; | ||
98 | // } | ||
99 | // console.log("initShake completed"); | ||
100 | // this.data.initShakeComplete = true; | ||
101 | // let _this = this; | ||
102 | // wx.onAccelerometerChange(function (res) { | ||
103 | // if (!_this.data.canShake || _this.data.tipsCommonVisible) { | ||
104 | // return | ||
105 | // } | ||
106 | // let shakeValue = 2; | ||
107 | // if (res.x > shakeValue || res.y > shakeValue || res.z > shakeValue) { //偏移量为2时触发,有的使用1 | ||
108 | // // 触发摇一摇 | ||
109 | // console.log("摇一摇"); | ||
110 | // // 加防抖函数 100毫秒 | ||
111 | // debounce(_this.queryWishbillAssist.bind(_this), 1000)() | ||
112 | // } | ||
113 | // }); | ||
114 | // }, | ||
115 | |||
116 | // 添加摇一摇 | ||
85 | initShake() { | 117 | initShake() { |
118 | return; | ||
119 | console.log("initShake start"); | ||
120 | if (this.data.initShakeComplete) { | ||
121 | return; | ||
122 | } | ||
123 | console.log("initShake completed"); | ||
124 | this.data.initShakeComplete = true; | ||
86 | let _this = this; | 125 | let _this = this; |
87 | wx.onAccelerometerChange(function (res) { | 126 | wx.onAccelerometerChange(_this.onShakeHandler.bind(_this)); |
88 | if (!_this.data.canShake || _this.data.tipsCommonVisible) { | 127 | }, |
89 | return | 128 | |
90 | } | 129 | onShakeHandler(res) { |
91 | let shakeValue = 2; | 130 | let _this = this; |
92 | if (res.x > shakeValue || res.y > shakeValue || res.z > shakeValue) { //偏移量为2时触发,有的使用1 | 131 | if (!_this.data.canShake || _this.data.tipsCommonVisible) { |
93 | // 触发摇一摇 | 132 | return |
94 | _this.queryWishbillAssist(); | 133 | } |
95 | } | 134 | let shakeValue = 2; |
96 | }); | 135 | if (res.x > shakeValue || res.y > shakeValue || res.z > shakeValue) { //偏移量为2时触发,有的使用1 |
136 | // 触发摇一摇 | ||
137 | console.log("摇一摇"); | ||
138 | // 加防抖函数 100毫秒 | ||
139 | debounce(_this.queryWishbillAssist.bind(this), 1000)() | ||
140 | } | ||
97 | }, | 141 | }, |
142 | |||
98 | // 我也要玩 | 143 | // 我也要玩 |
99 | onPlayTooHandler() { | 144 | onPlayTooHandler() { |
100 | app.router.push({ | 145 | app.router.push({ |
... | @@ -136,21 +181,22 @@ Page({ | ... | @@ -136,21 +181,22 @@ Page({ |
136 | if (wishInfo.isSelfWishBill == 1) { | 181 | if (wishInfo.isSelfWishBill == 1) { |
137 | return; | 182 | return; |
138 | } | 183 | } |
139 | // 已经助力 | 184 | // 已经助力过这张表单 |
140 | // if (wishInfo.isAssist == 1) { | 185 | if (wishInfo.isAssistThisBill == 1) { |
141 | // return; | 186 | return; |
142 | // } | 187 | } |
143 | 188 | ||
144 | this.setData({ | 189 | this.data.canShake = false; |
145 | canShake: false | 190 | |
146 | }) | 191 | console.log("app.api.wishbillAssist"); |
147 | this.playShakeSound(); | ||
148 | app.post({ | 192 | app.post({ |
193 | toast: false, | ||
149 | url: app.api.wishbillAssist, | 194 | url: app.api.wishbillAssist, |
150 | data: { | 195 | data: { |
151 | billCode: this.data.options.code | 196 | billCode: this.data.options.code |
152 | } | 197 | } |
153 | }).then((result) => { | 198 | }).then((result) => { |
199 | this.playShakeSound(); | ||
154 | let status = result.status; | 200 | let status = result.status; |
155 | if (status != 1) { | 201 | if (status != 1) { |
156 | this.setData({ | 202 | this.setData({ |
... | @@ -212,9 +258,7 @@ Page({ | ... | @@ -212,9 +258,7 @@ Page({ |
212 | tipsCommonVisible: true, | 258 | tipsCommonVisible: true, |
213 | tipsInnerText: "助力失败" | 259 | tipsInnerText: "助力失败" |
214 | }) | 260 | }) |
215 | this.setData({ | 261 | this.data.canShake = false; |
216 | canShake: false | ||
217 | }) | ||
218 | } | 262 | } |
219 | }) | 263 | }) |
220 | }, | 264 | }, |
... | @@ -256,13 +300,7 @@ Page({ | ... | @@ -256,13 +300,7 @@ Page({ |
256 | }, | 300 | }, |
257 | 301 | ||
258 | // 触发摇一摇测试入口 | 302 | // 触发摇一摇测试入口 |
259 | queryWishbillAssistTest() { | 303 | queryWishbillAssistTest() {}, |
260 | let isTest = app.globalData.isTest; | ||
261 | if (!isTest) { | ||
262 | return; | ||
263 | } | ||
264 | this.queryWishbillAssist(); | ||
265 | }, | ||
266 | 304 | ||
267 | hideMask() { | 305 | hideMask() { |
268 | this.setData({ | 306 | this.setData({ | ... | ... |
... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
14 | <!-- 摇一摇 --> | 14 | <!-- 摇一摇 --> |
15 | <!-- bindtap="queryWishbillAssist" --> | 15 | <!-- bindtap="queryWishbillAssist" --> |
16 | <!-- 点自己链接未助力 --> | 16 | <!-- 点自己链接未助力 --> |
17 | <view bindtap="queryWishbillAssistTest" wx:if="{{wishInfo.isSelfWishBill == 1 || wishInfo.isAssistThisBill == 0}}" class="shake"> | 17 | <view bindtap="queryWishbillAssistTest" wx:if="{{wishInfo.isSelfWishBill == 1 || wishInfo.isAssistThisBill == 0}}" class="shake"> |
18 | <image class="ebg" mode="widthFix" src="../../image/oss/coop/coop-c2.png" /> | 18 | <image class="ebg" mode="widthFix" src="../../image/oss/coop/coop-c2.png" /> |
19 | <image class="coop-shake animated infinite {{animationPassVisible || !initComplete ?'':'tada'}}" mode="widthFix" src="../../image/oss/coop/coop-shake.png" /> | 19 | <image class="coop-shake animated infinite {{animationPassVisible || !initComplete ?'':'tada'}}" mode="widthFix" src="../../image/oss/coop/coop-shake.png" /> |
20 | <view class="space1"></view> | 20 | <view class="space1"></view> | ... | ... |
... | @@ -32,6 +32,7 @@ Page({ | ... | @@ -32,6 +32,7 @@ Page({ |
32 | userInfo: {}, | 32 | userInfo: {}, |
33 | // canShake:false, | 33 | // canShake:false, |
34 | guideIndex: 0, | 34 | guideIndex: 0, |
35 | isShake: true, | ||
35 | }, | 36 | }, |
36 | onShareAppMessage() {}, | 37 | onShareAppMessage() {}, |
37 | showAuth() { | 38 | showAuth() { |
... | @@ -78,6 +79,7 @@ Page({ | ... | @@ -78,6 +79,7 @@ Page({ |
78 | }, | 79 | }, |
79 | // 添加摇一摇 | 80 | // 添加摇一摇 |
80 | initShake() { | 81 | initShake() { |
82 | return; | ||
81 | let _this = this; | 83 | let _this = this; |
82 | wx.onAccelerometerChange(function (res) { | 84 | wx.onAccelerometerChange(function (res) { |
83 | if (!_this.data.tipsShakeVisible) { | 85 | if (!_this.data.tipsShakeVisible) { |
... | @@ -94,6 +96,21 @@ Page({ | ... | @@ -94,6 +96,21 @@ Page({ |
94 | }); | 96 | }); |
95 | }, | 97 | }, |
96 | 98 | ||
99 | onShakeHandler(res) { | ||
100 | let _this = this; | ||
101 | if (!_this.data.tipsShakeVisible) { | ||
102 | return | ||
103 | } | ||
104 | let shakeValue = 2; | ||
105 | if (res.x > shakeValue || res.y > shakeValue || res.z > shakeValue) { //偏移量为2时触发,有的使用1 | ||
106 | _this.setData({ | ||
107 | tipsShakeVisible: false, | ||
108 | tipsCreateCompleteVisible: true | ||
109 | }) | ||
110 | _this.playShakeSound(); | ||
111 | } | ||
112 | }, | ||
113 | |||
97 | /** | 114 | /** |
98 | * 播放摇动声音 | 115 | * 播放摇动声音 |
99 | */ | 116 | */ | ... | ... |
-
Please register or sign in to post a comment