From 88693372feede0ba6ba2821d8ca4243c3b2fcdc1 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期三, 11 二月 2026 16:26:45 +0800
Subject: [PATCH] APP用印管理新增后,APP页面上无记录显示
---
src/pages/humanResources/attendance/checkin.vue | 120 ++++++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 96 insertions(+), 24 deletions(-)
diff --git a/src/pages/humanResources/attendance/checkin.vue b/src/pages/humanResources/attendance/checkin.vue
index a9856f4..a3eb33a 100644
--- a/src/pages/humanResources/attendance/checkin.vue
+++ b/src/pages/humanResources/attendance/checkin.vue
@@ -14,14 +14,14 @@
<u-icon name="calendar"
color="#348fe2"
size="16"></u-icon>
- <text class="shift-text">鐧界彮: {{ workTimeDict.startAt }}-{{ workTimeDict.endAt }}</text>
+ <text class="shift-text">鐧界彮: {{ todayRecord.startAt }}-{{ todayRecord.endAt }}</text>
</view>
</view>
<!-- 鎵撳崱鎸夐挳 -->
<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 "涓婄彮鎵撳崱";
}
@@ -217,26 +236,52 @@
// #endif
});
};
+ const form = ref({
+ longitude: "",
+ latitude: "",
+ });
- // 鑾峰彇褰撳墠浣嶇疆
const getCurrentLocation = () => {
- return new Promise((resolve, reject) => {
- uni.getLocation({
- type: "wgs84",
- success: res => {
- currentLocation.value = res;
- // 妯℃嫙妫�鏌ユ槸鍚﹀湪鎵撳崱鑼冨洿鍐咃紙瀹為檯椤圭洰涓簲鏍规嵁鍏徃浣嶇疆鍜屽厑璁哥殑鍗婂緞杩涜璁$畻锛�
- // 杩欓噷绠�鍗曟ā鎷熶负濮嬬粓鍦ㄨ寖鍥村唴
- inCheckRange.value = true;
- resolve(res);
- },
- fail: err => {
- console.error("鑾峰彇浣嶇疆澶辫触:", err);
- // 澶辫触鏃堕粯璁ゅ厑璁告墦鍗★紙瀹為檯椤圭洰涓簲鏍规嵁涓氬姟闇�姹傚鐞嗭級
- inCheckRange.value = true;
- reject(err);
- },
- });
+ uni.showLoading({ title: "鑾峰彇浣嶇疆涓�..." });
+
+ uni.getLocation({
+ type: "gcj02",
+ success: res => {
+ uni.hideLoading();
+ form.value.latitude = res.latitude;
+ form.value.longitude = res.longitude;
+ },
+ fail: err => {
+ uni.hideLoading();
+ console.error("鑾峰彇浣嶇疆澶辫触:", err);
+
+ // 鏄剧ず閿欒鎻愮ず骞跺紩瀵肩敤鎴锋鏌ユ潈闄�
+ showToast("鑾峰彇浣嶇疆澶辫触锛岃妫�鏌ュ畾浣嶆潈闄�");
+
+ // 寮曞鐢ㄦ埛妫�鏌ユ潈闄愯缃�
+ uni.showModal({
+ title: "浣嶇疆鏉冮檺鎻愮ず",
+ content:
+ "鑾峰彇浣嶇疆澶辫触锛屽彲鑳芥槸鍥犱负浣嶇疆鏉冮檺鏈紑鍚紝璇峰湪璁惧璁剧疆涓鏌ュ苟寮�鍚綅缃潈闄愩��",
+ confirmText: "鐭ラ亾浜�",
+ cancelText: "鍙栨秷",
+ success: res => {
+ if (res.confirm) {
+ // 鍙互灏濊瘯鎵撳紑璁剧疆椤甸潰锛堝鏋滄敮鎸侊級
+ if (uni.openSetting) {
+ uni.openSetting({
+ success: settingRes => {
+ console.log("璁剧疆缁撴灉:", settingRes);
+ },
+ });
+ }
+ }
+ },
+ });
+
+ // 澶辫触鏃舵樉绀洪敊璇俊鎭�
+ form.value.visitAddress = "浣嶇疆鑾峰彇澶辫触";
+ },
});
};
@@ -259,6 +304,14 @@
// 鎵撳崱閫昏緫
const handleCheckInOut = async () => {
+ if (noNeedCheckIn.value) {
+ uni.showToast({
+ title: "浠婃棩鏃犻渶鎵撳崱",
+ icon: "none",
+ });
+ return;
+ }
+
if (todayRecord.value.workEndAt) {
uni.showToast({
title: "鎮ㄥ凡缁忔墦杩囧崱浜�,鏃犻渶閲嶅鎵撳崱!!!",
@@ -266,6 +319,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({
@@ -276,8 +344,13 @@
}
// 璋冪敤鎵撳崱API
- createPersonalAttendanceRecord({})
+ createPersonalAttendanceRecord({
+ ...form.value,
+ })
.then(res => {
+ // 璁板綍鎵撳崱鏃堕棿
+ lastCheckInTime.value = Date.now();
+
uni.showToast({
title: "鎵撳崱鎴愬姛锛�",
icon: "success",
@@ -286,7 +359,6 @@
fetchTodayData();
})
.catch(error => {
- console.error("鎵撳崱澶辫触:", error);
uni.showToast({
title: error.msg || "鎵撳崱澶辫触锛岃閲嶈瘯",
icon: "none",
@@ -302,7 +374,7 @@
// 鑾峰彇浣嶇疆鏉冮檺骞舵鏌ヤ綅缃�
try {
- await getLocationPermission();
+ // await getLocationPermission();
await getCurrentLocation();
} catch (error) {
console.error("浣嶇疆鏉冮檺鑾峰彇澶辫触:", error);
--
Gitblit v1.9.3