feat: 修复商品下单节流
This commit is contained in:
4
.npmrc
Normal file
4
.npmrc
Normal file
@@ -0,0 +1,4 @@
|
||||
registry=https://registry.npmmirror.com
|
||||
sass_binary_site=https://cdn.npmmirror.com/binaries/node-sass
|
||||
shamefully-hoist=true
|
||||
|
||||
12097
package-lock.json
generated
Normal file
12097
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -70,6 +70,7 @@ import {
|
||||
commodityDailyPriceList,
|
||||
orderPay,
|
||||
} from "@/request/api/GoodsApi";
|
||||
import { ThrottleUtils } from "@/utils";
|
||||
import TopNavBar from "@/components/TopNavBar/index.vue";
|
||||
import ImageSwiper from "@/components/ImageSwiper/index.vue";
|
||||
import GoodInfo from "./components/GoodInfo/index.vue";
|
||||
@@ -164,7 +165,7 @@ const showConfirmPopup = () => {
|
||||
};
|
||||
|
||||
// 处理确认订单
|
||||
const handleConfirmOrder = async (orderData) => {
|
||||
const handleConfirmOrder = ThrottleUtils.createThrottle(async (orderData) => {
|
||||
console.log("确认订单---1:", orderData);
|
||||
const { goodsData } = orderData;
|
||||
// 购买的商品id
|
||||
@@ -260,7 +261,7 @@ const handleConfirmOrder = async (orderData) => {
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
}, 1000);
|
||||
|
||||
// 处理关闭弹窗
|
||||
const handleCloseConfirm = () => {
|
||||
|
||||
@@ -250,10 +250,61 @@ export class TimerUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 防抖工具类
|
||||
* 提供防抖功能,防止函数在短时间内被重复调用
|
||||
*/
|
||||
export class DebounceUtils {
|
||||
/**
|
||||
* 创建防抖函数
|
||||
* @param {Function} func - 要防抖的函数
|
||||
* @param {number} delay - 防抖延迟时间
|
||||
* @returns {Function} 防抖后的函数
|
||||
*/
|
||||
static createDebounce(func, delay) {
|
||||
let timerId = null;
|
||||
|
||||
return function (...args) {
|
||||
if (timerId) {
|
||||
clearTimeout(timerId);
|
||||
}
|
||||
|
||||
timerId = setTimeout(() => func.apply(this, args), delay);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 节流工具类
|
||||
* 提供节流功能,防止函数在短时间内被重复调用
|
||||
*/
|
||||
export class ThrottleUtils {
|
||||
/**
|
||||
* 创建节流函数
|
||||
* @param {Function} func - 要节流的函数
|
||||
* @param {number} delay - 节流延迟时间
|
||||
* @returns {Function} 节流后的函数
|
||||
*/
|
||||
static createThrottle(func, delay) {
|
||||
let prev = Date.now();
|
||||
|
||||
return function (...args) {
|
||||
let now = Date.now();
|
||||
|
||||
if (now - prev >= delay) {
|
||||
func.apply(this, args);
|
||||
prev = now;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 默认导出所有工具类
|
||||
export default {
|
||||
IdUtils,
|
||||
CallbackUtils,
|
||||
MessageUtils,
|
||||
TimerUtils,
|
||||
DebounceUtils,
|
||||
ThrottleUtils,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user