Browse Source

设置数据的防抖处理

wangxiangwen/feature-20250716103042-周年活动+众筹前台页面
wangxiangwen 3 weeks ago
parent
commit
1015925936
  1. 100
      activitylink/src/views/zhongchou/activity/set/index.vue

100
activitylink/src/views/zhongchou/activity/set/index.vue

@ -262,50 +262,63 @@ const cancelset = () => {
//
//
const confirmInitialData = async () => {
try {
const id = activityStone.selectactivityId
const time = setinitiaData.value
if (!id) {
ElMessage.warning('未获取到活动ID')
return
}
if (time === null || time <= 0) {
ElMessage.warning('请输入有效的分钟数')
return
}
const response = await setTime(
{
activityId: id,
time: time
}
)
if (response.code === 200) {
await fetchData()
showInitialConfirmDialog.value = false
setinitiaData.value=0
ElMessage.success('设置成功')
ifshow();
} else {
ElMessage.error(response.message || '设置失败')
}
} catch (error) {
console.error('设置初始数据失败:', error)
ElMessage.error('请求失败,请重试')
}
}
// const confirmInitialData = async () => {
// try {
// const id = activityStone.selectactivityId
// const time = setinitiaData.value
// if (!id) {
// ElMessage.warning('ID')
// return
// }
// if (time === null || time <= 0) {
// ElMessage.warning('')
// return
// }
// const response = await setTime(
// {
// activityId: id,
// time: time
// }
// )
// if (response.code === 200) {
// await fetchData()
// showInitialConfirmDialog.value = false
// setinitiaData.value=0
// ElMessage.success('')
// ifshow();
// } else {
// ElMessage.error(response.message || '')
// }
// } catch (error) {
// console.error(':', error)
// ElMessage.error('')
// }
// }
//
//
const isAdding = ref(false);
const addCooldown = 1500; // 1.5
const confirmAdd = async () => {
//
if (isAdding.value) {
ElMessage.warning('操作过于频繁,请稍后再试');
return;
}
const type = pendingAction.value;
// > 0
if (type === 'one' && addCountOne.value !== null && addCountOne.value !== 0) {
//
isAdding.value = true;
markerOneTotal.value += parseInt(addCountOne.value);
showOne.value = markerOneTotal.value;
@ -334,12 +347,20 @@ const confirmAdd = async () => {
//
markerOneTotal.value -= parseInt(addCountOne.value);
showOne.value = markerOneTotal.value;
} finally {
// 1.5
setTimeout(() => {
isAdding.value = false;
}, addCooldown);
}
addCountOne.value = null;
// > 0
} else if (type === 'two' && addCountTwo.value !== null && addCountTwo.value !== 0) {
//
isAdding.value = true;
markerTwoTotal.value += parseInt(addCountTwo.value);
showTwo.value = markerTwoTotal.value;
@ -367,6 +388,11 @@ const confirmAdd = async () => {
//
markerTwoTotal.value -= parseInt(addCountTwo.value);
showTwo.value = markerTwoTotal.value;
} finally {
// 1.5
setTimeout(() => {
isAdding.value = false;
}, addCooldown);
}
addCountTwo.value = null;

Loading…
Cancel
Save