From 244c42d87ed2ee45f339101a377f7d897124aea4 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期四, 05 十一月 2026 16:36:07 +0800
Subject: [PATCH] 打卡规则变动
---
src/pages/humanResources/attendance/checkin.vue | 181 +++++++++++++++++++++-----------------------
1 files changed, 86 insertions(+), 95 deletions(-)
diff --git a/src/pages/humanResources/attendance/checkin.vue b/src/pages/humanResources/attendance/checkin.vue
index cc113a1..6e08664 100644
--- a/src/pages/humanResources/attendance/checkin.vue
+++ b/src/pages/humanResources/attendance/checkin.vue
@@ -21,9 +21,9 @@
<view class="checkin-button-container">
<view class="checkin-button-wrapper">
<view class="checkin-button"
- :class="{ 'disabled': todayRecord.workEndAt || noNeedCheckIn }"
+ :class="{ 'disabled': todayRecord.workEndAt || noNeedCheckIn || locating || submitting }"
@click="handleCheckInOut">
- <text class="checkin-button-text">{{ checkInOutText }}</text>
+ <text class="checkin-button-text">{{ locating ? '瀹氫綅涓�...' : (submitting ? '鎻愪氦涓�...' : checkInOutText) }}</text>
<text class="checkin-time">{{ nowTime.split(' ')[1] }}</text>
</view>
</view>
@@ -117,6 +117,8 @@
// 鎵撳崱鍐峰嵈鏃堕棿锛堟绉掞級
const CHECKIN_COOLDOWN = 5000;
+ const locating = ref(false);
+ const submitting = ref(false);
// 杩斿洖涓婁竴椤�
const goBack = () => {
uni.navigateBack();
@@ -208,82 +210,68 @@
});
};
- // 鑾峰彇浣嶇疆鏉冮檺
- const getLocationPermission = () => {
- return new Promise((resolve, reject) => {
- // #ifdef APP-PLUS
- uni.getAppAuthorizeSetting({
- success: res => {
- if (res.authSetting["scope.userLocation"]) {
- resolve(true);
- } else {
- uni.requestAppAuthorize({
- scope: "scope.userLocation",
- success: res => {
- resolve(res.authSetting["scope.userLocation"]);
- },
- fail: err => {
- reject(err);
- },
- });
- }
- },
- fail: err => {
- reject(err);
- },
- });
- // #else
- // 闈濧PP鐜鐩存帴杩斿洖鎴愬姛
- resolve(true);
- // #endif
- });
- };
const form = ref({
longitude: "",
latitude: "",
});
- const getCurrentLocation = () => {
- uni.showLoading({ title: "鑾峰彇浣嶇疆涓�..." });
-
- uni.getLocation({
- type: "gcj02",
+ const showLocationError = err => {
+ const errorMessage = err?.errMsg || err?.message || "鏈煡閿欒";
+ console.error("鑾峰彇浣嶇疆澶辫触:", err);
+ uni.showModal({
+ title: "鏃犳硶鑾峰彇浣嶇疆",
+ content: `璇峰紑鍚墜鏈哄畾浣嶆湇鍔★紝骞跺厑璁稿簲鐢ㄤ娇鐢ㄧ簿纭綅缃悗閲嶈瘯銆俓n\n${errorMessage}`,
+ confirmText: "鍘昏缃�",
+ cancelText: "鍙栨秷",
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);
- },
- });
- }
- }
+ if (!res.confirm) return;
+ // #ifdef APP-PLUS
+ uni.openAppAuthorizeSetting({
+ fail: settingError => {
+ console.error("鎵撳紑搴旂敤鏉冮檺璁剧疆澶辫触:", settingError);
},
});
-
- // 澶辫触鏃舵樉绀洪敊璇俊鎭�
- form.value.visitAddress = "浣嶇疆鑾峰彇澶辫触";
+ // #endif
+ // #ifndef APP-PLUS
+ if (uni.openSetting) uni.openSetting({});
+ // #endif
},
+ });
+ };
+
+ const getCurrentLocation = (showError = true) => {
+ if (locating.value) {
+ return Promise.reject(new Error("姝e湪鑾峰彇浣嶇疆锛岃绋嶅��"));
+ }
+ locating.value = true;
+ form.value.latitude = "";
+ form.value.longitude = "";
+
+ return new Promise((resolve, reject) => {
+ uni.getLocation({
+ // 浣跨敤绯荤粺 WGS84 瀹氫綅锛屾寮忓寘涓嶄緷璧栭珮寰� Android Key銆佸寘鍚嶅拰绛惧悕 SHA1銆�
+ type: "wgs84",
+ isHighAccuracy: true,
+ highAccuracyExpireTime: 10000,
+ success: res => {
+ const latitude = Number(res.latitude);
+ const longitude = Number(res.longitude);
+ if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) {
+ reject(new Error("瀹氫綅缁撴灉涓殑缁忕含搴︽棤鏁�"));
+ return;
+ }
+ form.value.latitude = latitude;
+ form.value.longitude = longitude;
+ resolve({ latitude, longitude });
+ },
+ fail: reject,
+ complete: () => {
+ locating.value = false;
+ },
+ });
+ }).catch(err => {
+ if (showError) showLocationError(err);
+ throw err;
});
};
@@ -306,6 +294,8 @@
// 鎵撳崱閫昏緫
const handleCheckInOut = async () => {
+ if (locating.value || submitting.value) return;
+
if (noNeedCheckIn.value) {
uni.showToast({
title: "浠婃棩鏃犻渶鎵撳崱",
@@ -345,27 +335,31 @@
return;
}
- // 璋冪敤鎵撳崱API
- createPersonalAttendanceRecord({
- ...form.value,
- })
- .then(res => {
- // 璁板綍鎵撳崱鏃堕棿
- lastCheckInTime.value = Date.now();
-
+ try {
+ // 姣忔鎵撳崱閮介噸鏂板畾浣嶏紝閬垮厤鎻愪氦杩涘叆椤甸潰鏃剁紦瀛樼殑鏃т綅缃��
+ await getCurrentLocation();
+ if (form.value.latitude === "" || form.value.longitude === "") {
+ throw new Error("鏈幏鍙栧埌鏈夋晥浣嶇疆");
+ }
+ submitting.value = true;
+ await createPersonalAttendanceRecord({ ...form.value });
+ lastCheckInTime.value = Date.now();
+ uni.showToast({
+ title: "鎵撳崱鎴愬姛锛�",
+ icon: "success",
+ });
+ fetchTodayData();
+ } catch (error) {
+ // 瀹氫綅澶辫触宸茬敱 getCurrentLocation 缁欏嚭鏉冮檺寮曞锛岃繖閲屽彧鎻愮ず鎺ュ彛閿欒銆�
+ if (form.value.latitude !== "" && form.value.longitude !== "") {
uni.showToast({
- title: "鎵撳崱鎴愬姛锛�",
- icon: "success",
- });
- // 閲嶆柊鑾峰彇浠婃棩鎵撳崱淇℃伅
- fetchTodayData();
- })
- .catch(error => {
- uni.showToast({
- title: error.msg || "鎵撳崱澶辫触锛岃閲嶈瘯",
+ title: error.msg || error.message || "鎵撳崱澶辫触锛岃閲嶈瘯",
icon: "none",
});
- });
+ }
+ } finally {
+ submitting.value = false;
+ }
};
onMounted(async () => {
@@ -374,13 +368,10 @@
timer = setInterval(updateNowTime, 1000);
getWorkTimeDict();
- // 鑾峰彇浣嶇疆鏉冮檺骞舵鏌ヤ綅缃�
- try {
- // await getLocationPermission();
- await getCurrentLocation();
- } catch (error) {
- console.error("浣嶇疆鏉冮檺鑾峰彇澶辫触:", error);
- }
+ // 杩涘叆椤甸潰鏃堕瀹氫綅锛涚湡姝f墦鍗″墠杩樹細鍐嶆鑾峰彇锛岄瀹氫綅澶辫触涓嶆墦鎵扮敤鎴枫��
+ getCurrentLocation(false).catch(error => {
+ console.error("椤甸潰棰勫畾浣嶅け璐�:", error);
+ });
});
onBeforeUnmount(() => {
@@ -799,4 +790,4 @@
.attendance-records {
animation-delay: 0.2s;
}
-</style>
\ No newline at end of file
+</style>
--
Gitblit v1.9.3