zhangwencui
2 天以前 a2fb35f6e7a161f080734acbc18ebca337692148
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",