fix: 支付防抖

This commit is contained in:
2025-12-22 18:51:28 +08:00
parent 8be21f8307
commit 37192b0ba4
4 changed files with 6 additions and 34 deletions

View File

@@ -16,7 +16,6 @@ app.$mount();
import { createSSRApp } from "vue"; import { createSSRApp } from "vue";
import * as Pinia from "pinia"; import * as Pinia from "pinia";
import { createUnistorage } from "pinia-plugin-unistorage"; import { createUnistorage } from "pinia-plugin-unistorage";
import noclick from "./utils/noclick";
export function createApp() { export function createApp() {
const app = createSSRApp(App); const app = createSSRApp(App);
@@ -25,7 +24,6 @@ export function createApp() {
pinia.use(createUnistorage()); pinia.use(createUnistorage());
app.use(pinia); app.use(pinia);
app.use(share); app.use(share);
app.use(noclick);
return { return {
app, app,

View File

@@ -29,6 +29,7 @@
<script setup> <script setup>
import { computed, defineProps, defineEmits } from "vue"; import { computed, defineProps, defineEmits } from "vue";
import { DebounceUtils } from "@/utils";
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@@ -59,9 +60,9 @@ const totalAmt = computed(() => {
return count.value * Number(specificationPrice) * totalDays; return count.value * Number(specificationPrice) * totalDays;
}); });
const handleBooking = () => { const handleBooking = DebounceUtils.createDebounce(() => {
emit("payClick", props.orderData); emit("payClick", props.orderData);
}; }, 1000);
</script> </script>

View File

@@ -27,6 +27,7 @@
<script setup> <script setup>
import { defineProps, defineEmits, computed } from "vue"; import { defineProps, defineEmits, computed } from "vue";
import { orderPayNow } from "@/request/api/OrderApi"; import { orderPayNow } from "@/request/api/OrderApi";
import { DebounceUtils } from "@/utils";
const props = defineProps({ const props = defineProps({
orderData: { orderData: {
@@ -64,7 +65,7 @@ const buttonText = computed(() => {
const emit = defineEmits(["refund", "refresh"]); const emit = defineEmits(["refund", "refresh"]);
// 处理按钮点击事件 // 处理按钮点击事件
const handleButtonClick = async (orderData) => { const handleButtonClick = DebounceUtils.createDebounce(async (orderData) => {
try { try {
// 再次预定跳转商品详情 // 再次预定跳转商品详情
if (["1", "2", "3", "4", "5", "6"].includes(statusCode.value)) { if (["1", "2", "3", "4", "5", "6"].includes(statusCode.value)) {
@@ -130,7 +131,7 @@ const handleButtonClick = async (orderData) => {
console.error("操作失败:", error); console.error("操作失败:", error);
uni.hideLoading(); uni.hideLoading();
} }
}; }, 1000);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -1,28 +0,0 @@
// 防止处理多次点击
// methods是需要点击后需要执行的函数 info是点击需要传的参数
export function noMultipleClicks(fn, info, delay = 2000) {
if (typeof fn !== 'function') return;
// this 会是组件实例(因为通过 globalProperties 调用时 Vue 会把组件实例作为上下文)
const ctx = this || {};
if (!ctx.__noClickMap) ctx.__noClickMap = new WeakMap();
const map = ctx.__noClickMap;
if (map.get(fn)) {
console.log('请勿重复点击:', fn.name);
return;
}
map.set(fn, true);
// 保留组件上下文调用方法
fn.call(ctx, info);
setTimeout(() => {
map.set(fn, false);
}, delay);
}
export default {
install(app) {
app.config.globalProperties.$noMultipleClicks = noMultipleClicks;
}
}