From 097029128cd2749b71a445397d04a48d9ddaba1a Mon Sep 17 00:00:00 2001 From: YuanHuakk <1751826683@qq.com> Date: Mon, 23 Sep 2024 20:43:11 +0800 Subject: [PATCH] fix(custom): \! --- src/pages/goods/pay/index.vue | 25 ++++++++++++------------- src/utils/index.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/pages/goods/pay/index.vue b/src/pages/goods/pay/index.vue index 46198c5..b49eb1b 100644 --- a/src/pages/goods/pay/index.vue +++ b/src/pages/goods/pay/index.vue @@ -11,9 +11,9 @@ - {{ - itm.Store.name - }} + {{ itm.Store.name }} + - {{ - item.Goods?.name - }} + {{ item.Goods?.name }} + ¥{{ item.pay_price }}元 @@ -83,6 +83,7 @@ { }; const getData = async (oid: string, bid: string, OrderType: number) => { - const user_info = Taro.getStorageSync('userInfo'); + // const user_info = Taro.getStorageSync('userInfo'); // const data = await getUserPoint({ // phone: user_info.data.phone, // bid, @@ -173,18 +173,16 @@ const getData = async (oid: string, bid: string, OrderType: number) => { const pay = async () => { try { + if (isLoading.value) return; isLoading.value = true; if (!payVal.value) return Taro.showToast({title: '请选择支付方式', icon: 'none'}); - await confirmPay(); } catch (error) { Taro.showToast({ title: error.msg, icon: 'none', }); - } finally { - isLoading.value = false; } }; @@ -219,15 +217,16 @@ const confirmPay = async () => { url: `/pages/users/order_list/index?type=0`, }); }, 2000); + isLoading.value = false; }, }); - isLoading.value = false; } catch (err) { - isLoading.value = false; Taro.showToast({ title: err.msg, icon: 'none', }); + } finally { + isLoading.value = false; } }; diff --git a/src/utils/index.ts b/src/utils/index.ts index 5ecb32a..e885f4e 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -83,3 +83,29 @@ export function showTips(msg: string) { icon: 'none', }); } + +// 防抖函数 +export function debounce(fn: Function, delay: number = 500) { + let timer: any = null; + return function (...args: any[]) { + if (timer) { + clearTimeout(timer); + } + timer = setTimeout(() => { + fn.apply(this, args); + }, delay); + }; +} + +// 节流函数 +export function throttle(fn: Function, delay: number) { + let timer: any = null; + return function (...args: any[]) { + if (!timer) { + timer = setTimeout(() => { + fn.apply(this, args); + timer = null; + }, delay); + } + }; +}