Commit b27f8720 authored by 郭志伟's avatar 郭志伟

fix: 修复签到多次点击问题

parent 6e4d57c7
This diff is collapsed.
/*
* @Description:
* @Date: 2020-07-09 11:14:06
* @LastEditors: gzw
* @LastEditTime: 2020-07-09 11:14:26
*/
/**
* 延时函数
* @param {Function} func 方法
* @param {Number} wait 等待时间
* @param {Boolean} immediate 是否立即执行
* @return: {Function} result 方法执行
*/
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result;
const later = function () {
// 据上一次触发时间间隔
const last = +new Date() - timestamp;
// 上次被包装函数被调用时间间隔last小于设定时间间隔wait
if (last < wait && last > 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
if (!immediate) {
result = func.apply(context, args);
if (!timeout) context = args = null;
}
}
};
return function (...args) {
context = this;
timestamp = +new Date();
const callNow = immediate && !timeout;
// 如果延时不存在,重新设定延时
if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
}
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import Notify from '../components/vant/notify/notify'; import Notify from '../components/vant/notify/notify';
const env = 'prod'; // 每次上线手动切换成 prod/test const env = 'test'; // 每次上线手动切换成 prod/test
let baseUrl = 'https://api-luckii.q-gp.com'; let baseUrl = 'https://api-luckii.q-gp.com';
if (env === 'test') { if (env === 'test') {
baseUrl = 'https://luckii-qa.liangkebang.net'; baseUrl = 'https://luckii-qa.liangkebang.net';
......
...@@ -233,6 +233,7 @@ ...@@ -233,6 +233,7 @@
import store from '../store'; import store from '../store';
import { mapState, mapActions } from '@wepy/x'; import { mapState, mapActions } from '@wepy/x';
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import { debounce } from "../common/utils";
import Notify from '../components/vant/notify/notify'; import Notify from '../components/vant/notify/notify';
import Dialog from '../components/vant/dialog/dialog'; import Dialog from '../components/vant/dialog/dialog';
import { login, register, getMainInfo, addGold, getPrizeList, signIn, getActivityFeed, checkCornCode } from '../common/api.js'; import { login, register, getMainInfo, addGold, getPrizeList, signIn, getActivityFeed, checkCornCode } from '../common/api.js';
...@@ -311,6 +312,10 @@ ...@@ -311,6 +312,10 @@
return; return;
} }
} }
wepy.wx.showLoading({
title: "请稍候...",
mask: true
});
wx.requestSubscribeMessage({ wx.requestSubscribeMessage({
tmplIds, tmplIds,
success (res) { success (res) {
...@@ -320,7 +325,7 @@ ...@@ -320,7 +325,7 @@
const rs = tmplIds.every(v => res[v] === undefined || res[v] === 'accept'); const rs = tmplIds.every(v => res[v] === undefined || res[v] === 'accept');
if (rs) { if (rs) {
that.sign = true; that.sign = true;
setTimeout(async () => { debounce(async () => {
const innerAudioContext = wx.createInnerAudioContext(); const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.autoplay = true; innerAudioContext.autoplay = true;
innerAudioContext.src = '/static/audio/supermarie.mp3'; innerAudioContext.src = '/static/audio/supermarie.mp3';
...@@ -330,14 +335,20 @@ ...@@ -330,14 +335,20 @@
console.log(res.errCode); console.log(res.errCode);
}); });
const { coins } = await signIn(); const { coins } = await signIn();
wepy.wx.hideLoading();
if (coins === 0) return; if (coins === 0) return;
that.mainInfo.account.quantity = coins; that.mainInfo.account.quantity = coins;
}, 1500); }, 700)();
} else {
wepy.wx.hideLoading();
} }
} else {
wepy.wx.hideLoading();
} }
}, },
fail (res) { fail (res) {
console.log('requestSubscribeMessage fail', res); console.log('requestSubscribeMessage fail', res);
wepy.wx.hideLoading();
} }
}); });
}, },
......
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