From d58f654e54a32185f0e6979d81584b31a51faaa8 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期一, 22 六月 2026 16:42:00 +0800
Subject: [PATCH] fix:班次打卡位置
---
src/views/personnelManagement/attendanceCheckin/checkinRules/components/form.vue | 108 +++++++++++++++++++++++++++++++++---------------------
1 files changed, 66 insertions(+), 42 deletions(-)
diff --git a/src/views/personnelManagement/attendanceCheckin/checkinRules/components/form.vue b/src/views/personnelManagement/attendanceCheckin/checkinRules/components/form.vue
index b17b234..f83de68 100644
--- a/src/views/personnelManagement/attendanceCheckin/checkinRules/components/form.vue
+++ b/src/views/personnelManagement/attendanceCheckin/checkinRules/components/form.vue
@@ -53,27 +53,24 @@
<el-form-item label="鎵撳崱浣嶇疆"
prop="longitude">
<div class="map-container">
- <div class="map-header"
- style="margin-bottom: 10px">
- <!-- <el-button @click="getCurrentLocation">
- <el-icon>
- <Position />
- </el-icon>
- 褰撳墠浣嶇疆
- </el-button> -->
- <!-- <span style="margin-left: 10px; color: #909399;font-size: 12px;">鐐瑰嚮鍦板浘閫夋嫨浣嶇疆</span> -->
- </div>
+ <el-button @click="getCurrentLocation"
+ style="margin-bottom: 10px">
+ <el-icon>
+ <Position />
+ </el-icon>
+ 褰撳墠浣嶇疆
+ </el-button>
<div id="map-container"
class="map"
ref="mapContainer"></div>
<div class="coordinates-info mt10">
<el-input v-model="form.longitude"
- readonly
placeholder="缁忓害"
+ @change="handleCoordinateChange"
style="width: 140px; margin-right: 10px" />
<el-input v-model="form.latitude"
- readonly
placeholder="绾害"
+ @change="handleCoordinateChange"
style="width: 140px; margin-right: 10px" />
<!-- <el-input v-model="form.locationName"
placeholder="鍦扮偣鍚嶇О"
@@ -348,39 +345,66 @@
}
};
- // 鑾峰彇褰撳墠浣嶇疆
+ // 鑾峰彇褰撳墠浣嶇疆 - 浣跨敤娴忚鍣ㄥ畾浣嶏紙鏇寸簿鍑嗭級
const getCurrentLocation = () => {
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(
- position => {
- const { longitude, latitude } = position.coords;
- form.longitude = longitude;
- form.latitude = latitude;
- if (map) {
- map.setCenter([longitude, latitude]);
- updateMarker([longitude, latitude]);
- updateCircle([longitude, latitude]);
- }
+ const handlePosition = (lng, lat, name) => {
+ form.longitude = lng;
+ form.latitude = lat;
+ if (name) form.locationName = name;
+ const position = [lng, lat];
+ if (map) {
+ map.setCenter(position);
+ map.setZoom(16);
+ updateMarker(position);
+ updateCircle(position);
+ }
+ };
- // 閫嗗湴鐞嗙紪鐮佽幏鍙栧湴鍧�
- if (window.AMap) {
- // 鍔犺浇Geocoder鎻掍欢
- window.AMap.plugin("AMap.Geocoder", function () {
- const geocoder = new window.AMap.Geocoder();
- geocoder.getAddress([longitude, latitude], (status, result) => {
- if (status === "complete" && result.regeocode) {
- form.locationName = result.regeocode.formattedAddress;
- }
- });
- });
- }
- },
- error => {
- ElMessage.error("鑾峰彇浣嶇疆澶辫触锛岃鎵嬪姩閫夋嫨");
+ if (!navigator.geolocation) {
+ ElMessage.warning("娴忚鍣ㄤ笉鏀寔瀹氫綅锛岃鎵嬪姩閫夋嫨浣嶇疆");
+ return;
+ }
+
+ ElMessage.info("姝e湪瀹氫綅涓�...");
+
+ navigator.geolocation.getCurrentPosition(
+ (position) => {
+ const { longitude, latitude } = position.coords;
+ handlePosition(longitude, latitude, "");
+ ElMessage.success("瀹氫綅鎴愬姛");
+ },
+ (error) => {
+ let msg = "瀹氫綅澶辫触";
+ switch (error.code) {
+ case error.PERMISSION_DENIED:
+ msg = "瀹氫綅鏉冮檺琚嫆缁濓紝璇峰湪娴忚鍣ㄨ缃腑鍏佽瀹氫綅";
+ break;
+ case error.POSITION_UNAVAILABLE:
+ msg = "瀹氫綅淇℃伅涓嶅彲鐢�";
+ break;
+ case error.TIMEOUT:
+ msg = "瀹氫綅瓒呮椂锛岃閲嶈瘯";
+ break;
}
- );
- } else {
- ElMessage.error("娴忚鍣ㄤ笉鏀寔鍦扮悊瀹氫綅");
+ ElMessage.warning(msg + "锛岃鎵嬪姩閫夋嫨浣嶇疆");
+ },
+ {
+ enableHighAccuracy: true,
+ timeout: 15000,
+ maximumAge: 0
+ }
+ );
+ };
+
+ // 鎵嬪姩杈撳叆缁忕含搴︽椂鍚屾鍦板浘
+ const handleCoordinateChange = () => {
+ const lng = parseFloat(form.longitude);
+ const lat = parseFloat(form.latitude);
+ if (!isNaN(lng) && !isNaN(lat) && map) {
+ const position = [lng, lat];
+ map.setCenter(position);
+ updateMarker(position);
+ updateCircle(position);
}
};
--
Gitblit v1.9.3