From a2fb35f6e7a161f080734acbc18ebca337692148 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期三, 11 二月 2026 14:23:51 +0800
Subject: [PATCH] 打卡添加防抖
---
src/pages/humanResources/attendance/checkin.vue | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/src/pages/humanResources/attendance/checkin.vue b/src/pages/humanResources/attendance/checkin.vue
index e358edc..e5f4e6e 100644
--- a/src/pages/humanResources/attendance/checkin.vue
+++ b/src/pages/humanResources/attendance/checkin.vue
@@ -21,7 +21,7 @@
<view class="checkin-button-container">
<view class="checkin-button-wrapper">
<view class="checkin-button"
- :class="{ 'disabled': todayRecord.workEndAt }"
+ :class="{ 'disabled': todayRecord.workEndAt || noNeedCheckIn }"
@click="handleCheckInOut">
<text class="checkin-button-text">{{ checkInOutText }}</text>
<text class="checkin-time">{{ nowTime.split(' ')[1] }}</text>
@@ -114,6 +114,12 @@
// 褰撳墠鏃堕棿灞曠ず
const nowTime = ref("");
let timer = null;
+
+ // 涓婃鎵撳崱鏃堕棿
+ const lastCheckInTime = ref(null);
+
+ // 鎵撳崱鍐峰嵈鏃堕棿锛堟绉掞級
+ const CHECKIN_COOLDOWN = 5000;
// 杩斿洖涓婁竴椤�
const goBack = () => {
uni.navigateBack();
@@ -121,12 +127,22 @@
// 鏌ヨ浠婃棩鎵撳崱淇℃伅
const fetchTodayData = () => {
findTodayPersonalAttendanceRecord({}).then(res => {
- todayRecord.value = res.data;
+ if (res.data) {
+ todayRecord.value = res.data;
+ noNeedCheckIn.value = false;
+ } else {
+ // 椤甸潰鏄剧ず鈥滄棤闇�鎵撳崱鈥�
+ todayRecord.value = {};
+ noNeedCheckIn.value = true;
+ }
});
};
// 鎵撳崱鑼冨洿鐘舵��
const inCheckRange = ref(true);
+
+ // 鏄惁鏃犻渶鎵撳崱
+ const noNeedCheckIn = ref(false);
// 褰撳墠浣嶇疆
const currentLocation = ref(null);
@@ -147,6 +163,9 @@
// 鎵撳崱鎸夐挳鏂囨湰
const checkInOutText = computed(() => {
+ if (noNeedCheckIn.value) {
+ return "鏃犻渶鎵撳崱";
+ }
if (!todayRecord.value || !todayRecord.value.workStartAt) {
return "涓婄彮鎵撳崱";
}
@@ -259,6 +278,14 @@
// 鎵撳崱閫昏緫
const handleCheckInOut = async () => {
+ if (noNeedCheckIn.value) {
+ uni.showToast({
+ title: "浠婃棩鏃犻渶鎵撳崱",
+ icon: "none",
+ });
+ return;
+ }
+
if (todayRecord.value.workEndAt) {
uni.showToast({
title: "鎮ㄥ凡缁忔墦杩囧崱浜�,鏃犻渶閲嶅鎵撳崱!!!",
@@ -266,6 +293,21 @@
});
return;
}
+
+ // 妫�鏌ユ槸鍚﹀湪鎵撳崱鍐峰嵈鏃堕棿鍐�
+ if (lastCheckInTime.value) {
+ const currentTime = Date.now();
+ const timeDiff = currentTime - lastCheckInTime.value;
+ if (timeDiff < CHECKIN_COOLDOWN) {
+ const remainingTime = Math.ceil((CHECKIN_COOLDOWN - timeDiff) / 1000);
+ uni.showToast({
+ title: `璇�${remainingTime}绉掑悗鍐嶈瘯`,
+ icon: "none",
+ });
+ return;
+ }
+ }
+
// 妫�鏌ユ槸鍚﹀湪鎵撳崱鑼冨洿鍐�
if (!inCheckRange.value) {
uni.showToast({
@@ -278,6 +320,9 @@
// 璋冪敤鎵撳崱API
createPersonalAttendanceRecord({})
.then(res => {
+ // 璁板綍鎵撳崱鏃堕棿
+ lastCheckInTime.value = Date.now();
+
uni.showToast({
title: "鎵撳崱鎴愬姛锛�",
icon: "success",
--
Gitblit v1.9.3