Commit bbcc9ec3 authored by 慕轻风's avatar 慕轻风

wnf-增加防连点

parent bcd09660
No preview for this file type
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"pages/endPage/endPage" "pages/endPage/endPage"
], ],
"window": { "window": {
"defaultTitle": "C端模板" "defaultTitle": "C端模板",
"enableSkia":"true"
} }
} }
...@@ -4,11 +4,9 @@ import API from "/api"; ...@@ -4,11 +4,9 @@ import API from "/api";
const app = getApp(); const app = getApp();
const { tbcc } = app; const { tbcc } = app;
const { commonToast, navigateToOutside, getUserAddress, setClipboard } = tbcc.tb; const { commonToast, navigateToOutside, getUserAddress, setClipboard } = tbcc.tb;
const { dateFormatter } = tbcc.utils; const { dateFormatter, throttleHandle } = tbcc.utils;
const { PRIZE_TYPE_MAP, PRIZE_DRAW_STATUS_MAP } = tbcc.constants; const { PRIZE_TYPE_MAP, PRIZE_DRAW_STATUS_MAP } = tbcc.constants;
let flag = false;
Page({ Page({
data: { data: {
PRIZE_TYPE_MAP, PRIZE_TYPE_MAP,
...@@ -41,7 +39,6 @@ Page({ ...@@ -41,7 +39,6 @@ Page({
} }
}, },
onShow() { onShow() {
flag = false
this.getMyPrize(); this.getMyPrize();
}, },
// 到期时间 // 到期时间
...@@ -85,7 +82,7 @@ Page({ ...@@ -85,7 +82,7 @@ Page({
}, },
//领取奖品 //领取奖品
async handleClick(e) { handleClick: throttleHandle(async function(e) {
const { item } = e.target.dataset; const { item } = e.target.dataset;
// 领取权益 // 领取权益
if (item.type === PRIZE_TYPE_MAP.EQUITY) return this.handleGetEquity(e) if (item.type === PRIZE_TYPE_MAP.EQUITY) return this.handleGetEquity(e)
...@@ -93,13 +90,9 @@ Page({ ...@@ -93,13 +90,9 @@ Page({
if (item.type === PRIZE_TYPE_MAP.ENTITY) return this.handleGetEntity(e) if (item.type === PRIZE_TYPE_MAP.ENTITY) return this.handleGetEntity(e)
// 领取积分 // 领取积分
if (item.type === PRIZE_TYPE_MAP.INTEGRATION) return this.handleGetIntergation(e) if (item.type === PRIZE_TYPE_MAP.INTEGRATION) return this.handleGetIntergation(e)
}, },20000),
// 优惠券 // 优惠券
async handleGetEquity(e) { async handleGetEquity(e) {
if (flag) {
return
}
flag = true;
const { activityId } = app; const { activityId } = app;
const { item } = e.target.dataset; const { item } = e.target.dataset;
console.log(item, '领取权益') console.log(item, '领取权益')
...@@ -111,17 +104,10 @@ Page({ ...@@ -111,17 +104,10 @@ Page({
commonToast('领取成功') commonToast('领取成功')
this.getMyPrize() this.getMyPrize()
} }
setTimeout(() => {
flag = false
}, 500)
}, },
// 领取实物前询问 // 领取实物前询问
async handleGetEntity(e) { async handleGetEntity(e) {
if (flag) {
return
}
my.showLoading(); my.showLoading();
flag = true;
const { activityId } = app; const { activityId } = app;
const { item } = e.target.dataset; const { item } = e.target.dataset;
const userAddress = await getUserAddress().catch(err => { const userAddress = await getUserAddress().catch(err => {
...@@ -157,7 +143,6 @@ Page({ ...@@ -157,7 +143,6 @@ Page({
} }
}, },
}); });
flag = false
}, },
// 领取实物 // 领取实物
async receiveObjectPrize(params) { async receiveObjectPrize(params) {
...@@ -171,10 +156,6 @@ Page({ ...@@ -171,10 +156,6 @@ Page({
}, },
// 积分 // 积分
async handleGetIntergation(e) { async handleGetIntergation(e) {
if (flag) {
return
}
flag = true;
// 判断是否为会员 // 判断是否为会员
await this.getUserInfo() await this.getUserInfo()
const { isVip, vipLink } = app; const { isVip, vipLink } = app;
...@@ -183,7 +164,6 @@ Page({ ...@@ -183,7 +164,6 @@ Page({
setTimeout(() => { setTimeout(() => {
navigateToOutside(vipLink) navigateToOutside(vipLink)
}, 1000) }, 1000)
flag = false
return return
} }
const { activityId } = app; const { activityId } = app;
...@@ -195,7 +175,6 @@ Page({ ...@@ -195,7 +175,6 @@ Page({
if (success && data) { if (success && data) {
commonToast('领取成功') commonToast('领取成功')
} }
flag = false
this.getMyPrize() this.getMyPrize()
}, },
......
...@@ -93,3 +93,22 @@ export const generateAPI = (apiList, request) => { ...@@ -93,3 +93,22 @@ export const generateAPI = (apiList, request) => {
api.fn = capiFn(apiList, request); api.fn = capiFn(apiList, request);
return api; return api;
}; };
/**
* 防连点
* @param {fn} fn 函数
* @param {wait} wait 时间
*/
export const throttleHandle = (fn, wait = 500) => {
let lastTime = 0
return function cb(...args) {
let nowTime = Date.now()
if(nowTime - lastTime > wait) {
fn.call(this,...args)
lastTime = nowTime
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment