From 435f6e023163ccee35dda99e9c07c187c8f0b9c6 Mon Sep 17 00:00:00 2001 From: wzp <2040239371@qq.com> Date: 星期四, 08 五月 2025 18:20:03 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ruoyi-ui/src/views/system/gps/map.vue | 176 ++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 110 insertions(+), 66 deletions(-) diff --git a/ruoyi-ui/src/views/system/gps/map.vue b/ruoyi-ui/src/views/system/gps/map.vue index c659550..bd09c70 100644 --- a/ruoyi-ui/src/views/system/gps/map.vue +++ b/ruoyi-ui/src/views/system/gps/map.vue @@ -104,7 +104,7 @@ </template> <script> -import { listGps } from "@/api/system/gps"; +import { anonymousList } from "@/api/system/gps"; export default { name: "GpsMap", @@ -126,9 +126,12 @@ dateRange: [], // 鏌ヨ鍙傛暟 queryParams: { - vehicleNo: undefined, - orderByColumn: "collect_time", - isAsc: "desc", + pageNum: 1, + pageSize: 10, + deviceId: null, + appId: null, + sign: null, + timestamp: null }, // 鍦板浘瀵硅薄 map: null, @@ -156,16 +159,38 @@ if (query.vehicleNo) { this.queryParams.vehicleNo = query.vehicleNo; } - // 璁剧疆鏃堕棿鑼冨洿 - if (query.startTime && query.endTime) { - this.dateRange = [query.startTime, query.endTime]; + // 璁剧疆璁よ瘉鍙傛暟 + if (query.appId) { + this.queryParams.appId = query.appId; } + if (query.sign) { + this.queryParams.sign = query.sign; + } + if (query.timestamp) { + this.queryParams.timestamp = query.timestamp; + } + + // 璁剧疆榛樿鏃堕棿鑼冨洿 + const today = new Date(); + const startTime = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0); + const endTime = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59); + this.dateRange = [this.parseTime(startTime), this.parseTime(endTime)]; + + // 濡傛灉URL涓湁鏃堕棿鍙傛暟锛屽垯浣跨敤URL涓殑鏃堕棿 + if (query.beginTime && query.endTime) { + this.dateRange = [query.beginTime, query.endTime]; + } + this.getList(); }, mounted() { // 鍔ㄦ�佸姞杞界櫨搴﹀湴鍥続PI this.loadBMapScript().then(() => { this.initMap(); + window.initMapFlag=true; + if(window.loadGpsList){ + this.drawTrack() + } }); }, methods: { @@ -203,17 +228,45 @@ }; }); }, + /** 鏍煎紡鍖栨椂闂� */ + parseTime(time) { + const year = time.getFullYear(); + const month = String(time.getMonth() + 1).padStart(2, '0'); + const day = String(time.getDate()).padStart(2, '0'); + const hours = String(time.getHours()).padStart(2, '0'); + const minutes = String(time.getMinutes()).padStart(2, '0'); + const seconds = String(time.getSeconds()).padStart(2, '0'); + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; + }, /** 鏌ヨGPS鍒楄〃 */ getList() { - this.loading = true; - listGps(this.addDateRange(this.queryParams, this.dateRange)).then( - (response) => { - this.gpsList = response.rows; - this.total = response.total; - this.loading = false; + this.loading = true; + // 鏋勫缓鏌ヨ鍙傛暟 + const params = { + ...this.queryParams + }; + + // 濡傛灉娌℃湁閫夋嫨鏃堕棿鑼冨洿锛屽垯榛樿浣跨敤褰撳ぉ + if (!this.dateRange || this.dateRange.length === 0) { + const today = new Date(); + const startTime = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0); + const endTime = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59); + params.beginTime = this.parseTime(startTime); + params.endTime = this.parseTime(endTime); + } else { + params.beginTime = this.dateRange[0]; + params.endTime = this.dateRange[1]; + } + + anonymousList(params).then(response => { + this.gpsList = response.rows; + this.total = response.total; + this.loading = false; + window.loadGpsList=true; + if(window.initMapFlag){ this.drawTrack(); } - ); + }); }, async translatePoints(points) { // 灏哤GS84鍧愭爣杞崲涓虹櫨搴﹀潗鏍� @@ -234,7 +287,11 @@ }, /** 閲嶇疆鎸夐挳鎿嶄綔 */ resetQuery() { - this.dateRange = []; + // 閲嶇疆涓哄綋澶╂椂闂磋寖鍥� + const today = new Date(); + const startTime = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0); + const endTime = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59); + this.dateRange = [this.parseTime(startTime), this.parseTime(endTime)]; this.resetForm("queryForm"); this.handleQuery(); }, @@ -246,6 +303,7 @@ this.map.centerAndZoom(new BMap.Point(116.404, 39.915), 11); // 鍚敤婊氳疆鏀惧ぇ缂╁皬 this.map.enableScrollWheelZoom(); + console.log("initMap 鍒濆鍖栧湴鍥�") }, /** 璁$畻涓ょ偣涔嬮棿鐨勮窛绂伙紙绫筹級 */ getDistance(point1, point2) { @@ -258,34 +316,7 @@ return Math.atan2(dy, dx) * 180 / Math.PI; }, - /** 鍦ㄤ袱鐐逛箣闂存彃鍏ュ钩婊戠偣 */ - getSmoothPoints(point1, point2) { - const distance = this.getDistance(point1, point2); - if (distance < this.minDistance) { - return [point1, point2]; - } - - const angle = this.getAngle(point1, point2); - const midPoint = new BMap.Point( - (point1.lng + point2.lng) / 2, - (point1.lat + point2.lat) / 2 - ); - - // 璁$畻鎺у埗鐐� - const controlPoint = new BMap.Point( - midPoint.lng + this.smoothFactor * distance * Math.cos((angle + 90) * Math.PI / 180), - midPoint.lat + this.smoothFactor * distance * Math.sin((angle + 90) * Math.PI / 180) - ); - - // 浣跨敤浜屾璐濆灏旀洸绾跨敓鎴愬钩婊戠偣 - const points = []; - for (let t = 0; t <= 1; t += 0.1) { - const x = Math.pow(1 - t, 2) * point1.lng + 2 * (1 - t) * t * controlPoint.lng + Math.pow(t, 2) * point2.lng; - const y = Math.pow(1 - t, 2) * point1.lat + 2 * (1 - t) * t * controlPoint.lat + Math.pow(t, 2) * point2.lat; - points.push(new BMap.Point(x, y)); - } - return points; - }, + /** 缁樺埗杞ㄨ抗 */ async drawTrack() { @@ -333,11 +364,18 @@ translatePoints.forEach((item, index) => { const bdPoint = item; - // 鍙湪璧风偣鍜岀粓鐐瑰垱寤烘爣璁� - if (index === 0 || index === translatePoints.length - 1) { + // 鍒ゆ柇璧风偣鍜岀粓鐐规槸鍚︾浉鍚� + const isStartPoint = index === 0; + const isEndPoint = index === translatePoints.length - 1; + const isStartEndSame = isStartPoint && isEndPoint && + translatePoints[0].lng === translatePoints[translatePoints.length - 1].lng && + translatePoints[0].lat === translatePoints[translatePoints.length - 1].lat; + + // 鍙湪璧风偣鍜岀粓鐐瑰垱寤烘爣璁帮紝涓旇捣鐐瑰拰缁堢偣涓嶅悓鏃舵墠鏄剧ず璧风偣鏍囪 + if ((isStartPoint && !isStartEndSame) || isEndPoint) { let marker; let direction=currentSegment[index].direction; - if (index === 0) { + if (isStartPoint && !isStartEndSame) { // 璧风偣鏄剧ず"璧�"瀛� const label = new BMap.Label("璧�", { offset: new BMap.Size(0, 0), @@ -356,7 +394,6 @@ marker.setLabel(label); } else { // 缁堢偣鏄剧ず杞﹁締鍥炬爣 - const myIcon = new BMap.Icon( "/car_blue.png", new BMap.Size(20, 20), @@ -384,7 +421,6 @@ borderRadius: "3px", }); marker.setLabel(label); - // 鑾峰彇鍦板潃淇℃伅 const geoc = new BMap.Geocoder(); @@ -397,13 +433,14 @@ addComp.street + addComp.streetNumber; - // 娣诲姞淇℃伅绐楀彛 - const infoWindow = new BMap.InfoWindow( - `鏃堕棿锛�${item.collectTime}<br/>閫熷害锛�${ - item.speed - }km/h<br/>鏂瑰悜锛�${item.direction}掳<br/>鍦板潃锛�${address}` - ); + // 娣诲姞鐐瑰嚮浜嬩欢鐩戝惉鍣� marker.addEventListener("click", () => { + // 鍒涘缓淇℃伅绐楀彛 + const infoWindow = new BMap.InfoWindow( + `杞︾墝鍙凤細${currentSegment[index].vehicleNo}<br/>鏃堕棿锛�${currentSegment[index].collectTime}<br/>閫熷害锛�${ + currentSegment[index].speed + }km/h<br/>鏂瑰悜锛�${currentSegment[index].direction}掳<br/>鍦板潃锛�${address}` + ); this.map.openInfoWindow(infoWindow, bdPoint); }); }); @@ -411,12 +448,6 @@ this.map.addOverlay(marker); this.markers.push(marker); } - // const smoothPoints = []; - // for (let i = 0; i < points.length - 1; i++) { - // const segmentPoints = this.getSmoothPoints(points[i], points[i + 1]); - // smoothPoints.push(...segmentPoints); - // } - // smoothPoints.push(points[points.length - 1]); // 濡傛灉鏄渶鍚庝竴涓偣锛岀粯鍒惰建杩圭嚎 if (index === currentSegment.length - 1) { @@ -475,12 +506,25 @@ }); marker.setLabel(label); - // 娣诲姞淇℃伅绐楀彛 - const infoWindow = new BMap.InfoWindow( - `鏃堕棿锛�${row.collectTime}<br/>閫熷害锛�${row.speed}km/h<br/>鏂瑰悜锛�${row.direction}掳<br/>鍦板潃锛�${row.address}` - ); - marker.addEventListener("click", () => { - this.map.openInfoWindow(infoWindow, data.points[0]); + // 鑾峰彇鍦板潃淇℃伅 + const geoc = new BMap.Geocoder(); + geoc.getLocation(data.points[0], (rs) => { + const addComp = rs.addressComponents; + const address = + addComp.province + + addComp.city + + addComp.district + + addComp.street + + addComp.streetNumber; + + // 娣诲姞鐐瑰嚮浜嬩欢鐩戝惉鍣� + marker.addEventListener("click", () => { + // 鍒涘缓淇℃伅绐楀彛 + const infoWindow = new BMap.InfoWindow( + `杞︾墝鍙凤細${row.vehicleNo}<br/>鏃堕棿锛�${row.collectTime}<br/>閫熷害锛�${row.speed}km/h<br/>鏂瑰悜锛�${row.direction}掳<br/>鍦板潃锛�${address}` + ); + this.map.openInfoWindow(infoWindow, data.points[0]); + }); }); // 淇濆瓨褰撳墠鏍囪鐐瑰紩鐢� -- Gitblit v1.9.1