瀏覽代碼

fix location

wenhongquan 3 年之前
父節點
當前提交
2d527e4282
共有 4 個文件被更改,包括 142 次插入104 次删除
  1. 二進制
      src/assets/icons/incident/location.png
  2. 11 1
      src/service/login.ts
  3. 3 1
      src/utils/constant.ts
  4. 128 102
      src/views/IncidentManagementReport/index.tsx

二進制
src/assets/icons/incident/location.png


+ 11 - 1
src/service/login.ts

@@ -1,5 +1,5 @@
 import request from "@/utils/request";
-import { BASE_USER_URL } from "@/utils/constant";
+import { BASE_USER_URL,BASE_USER_LOCATION_URL } from "@/utils/constant";
 
 
 
@@ -9,6 +9,16 @@ export const api_gettokenByTicket = (ticket:string) => {
    });
 }
 
+export const api_getusergps = () => {
+   var tokenkjson = window.localStorage.getItem('userdata');
+   tokenkjson = tokenkjson == null ? '{}' : tokenkjson;
+   tokenkjson = tokenkjson == undefined ? '{}' : tokenkjson;
+   tokenkjson = JSON.parse(tokenkjson);
+  return request<Object>('GET', {
+    url: `${BASE_USER_LOCATION_URL}?userId=${tokenkjson["userId"]+""}`,
+  });
+};
+
 
   
 function docheck() { 

+ 3 - 1
src/utils/constant.ts

@@ -1,6 +1,8 @@
 
 export const BASE_URL = (import.meta.env.VITE_API_SERVER as string)+'/YJZH-SQ/api';
-export const BASE_USER_URL = (import.meta.env.VITE_API_SERVER as string)+'/tpbd-cas';
+export const BASE_USER_URL = (import.meta.env.VITE_API_SERVER as string) + '/tpbd-cas';
+export const BASE_USER_LOCATION_URL =
+  (import.meta.env.VITE_API_SERVER as string) + '/user-gps/api/business/user-gps/realtime';
 export const BASE_RESOURCE_URL =
   BASE_URL + '/common/download/resource?resource=';
 export const LOGIN_URL =

+ 128 - 102
src/views/IncidentManagementReport/index.tsx

@@ -12,11 +12,14 @@ import cloneDeep from 'lodash/cloneDeep';
 import div from '@/components/div';
 import { useCommonStore, useIncidentStore } from '@/store';
 import QueryMap from '@/components/QueryMap';
-import { BaseMediaUrl} from '@/utils/index';
+import { BaseMediaUrl } from '@/utils/index';
+import { api_getusergps } from '@/service/login';
 // import MediaUpload from '@/components/MediaUpload';
 
 /** @ts-ignore */
 import icon_map_location from '@/assets/icons/home/icon_map_location@2x.png';
+/** @ts-ignore */
+import icon_location from '@/assets/icons/incident/location.png';
 import './index.scss';
 import {
   DropdownItemOption,
@@ -112,98 +115,114 @@ export default defineComponent({
     };
 
     const getLocation = () => {
-      if (navigator.geolocation) {
-        navigator.geolocation.getCurrentPosition(
-          (position: GeolocationPosition) => {
-            console.log(position.coords.longitude);
-            console.log(position.coords.latitude);
-            // var location = '118.28,33.97';
-            var location = `${position.coords.longitude},${position.coords.latitude}`;
-             fetch(
-               `https://minedata.cn/service/lbs/reverse/v1/regeo?location=${location}&key=${window.key}`,
-             )
-               .then((res) => res.json())
-               .then((data) => {
-                //  console.log(data)
-                //  console.log(data.regeocodes[0].formatted_address);
-                 var ll = data.regeocodes[0].formatted_address;
-                  if (!window.map) {
-                    Notify({
-                      type: 'danger',
-                      message: '地图插件初始化异常, 请刷新页面 (Ctrl + R)',
-                    });
-
-                    return;
-                  }
-               window.map.flyTo({
-                 center: [
-                   Number(location.split(',')[0]),
-                   Number(location.split(',')[1]),
-                 ],
-                 zoom: 14,
-                 bearing: 0,
-                 pitch: 0,
-                 duration: 2000,
-               });
-                  if (window.map && window._marker) {
-                    window._marker.remove();
-                    window._marker = null;
-                  }
-                 if (window.map) {
-                   var el = document.createElement('div');
-                   el.id = 'marker';
-                   el.style.backgroundImage = `url(${icon_map_location})`;
-                   el.style.backgroundSize = 'cover';
-                   el.style.width = '24px';
-                   el.style.height = '24px';
-                   el.style.borderRadius = '50%';
-
-                   const popup = new window.minemap.Popup({
-                     closeOnClick: false,
-                     closeButton: false,
-                     offset: [0, -15],
-                   }).setText(ll);
-
-                   window._marker = new window.minemap.Marker(el, {
-                     offset: [-12, -12],
-                   })
-                     .setLngLat([
+
+      api_getusergps().then((res) => { 
+        var lat = null;
+        var lon = null;
+        var iserror = false;
+        try {
+            lat = res.result[0].lat;
+          lon = res.result[0].lon;
+          if (lat == null || lat == undefined) iserror = true;
+        } catch (e) { 
+          iserror = true;
+        }
+         if (!iserror) {      
+               var location = `${lon},${lat}`;
+               fetch(
+                 `https://minedata.cn/service/lbs/reverse/v1/regeo?location=${location}&key=${window.key}`,
+                 {
+                   method: 'GET',
+                   headers: new Headers({
+                     'Content-Type': 'application/json',
+                   }),
+                 },
+               )
+                 .then((res) => res.json())
+                 .then((data) => {
+                   //  console.log(data)
+                   //  console.log(data.regeocodes[0].formatted_address);
+                   var ll = data.regeocodes[0].formatted_address;
+                   if (!window.map) {
+                     Notify({
+                       type: 'danger',
+                       message: '地图插件初始化异常, 请刷新页面 (Ctrl + R)',
+                     });
+
+                     return;
+                   }
+                   window.map.flyTo({
+                     center: [
                        Number(location.split(',')[0]),
                        Number(location.split(',')[1]),
-                     ])
-                     .setPopup(popup)
-                     .addTo(window.map);
-                 }
-                 window._marker.togglePopup();
-                //  var ll =
-                //    data.regeocodes[0].formatted_address.replaceAll(
-                //      '江苏省宿迁市',
-                //    "");
-                 
-                 form.value.locations = location;
-                 form.value.addr = ll;
-               });
-            // minemap.service
-            //   .adminByPointData({
-            //     location: `${position.coords.longitude},${position.coords.latitude}`,
-            //   })
-            //   .then(function (response) {
-            //     console.log(response.data);
-            //   })
-            //   .catch(function (error) {
-            //     console.error(error);
-            //   });
-          },
-          (ee) => {
-            console.log(ee);
-          },
-        );
-      } else {
-        Notify({
-          type: 'danger',
-          message: 'App不支持地理定位。',
-        });
-      }
+                     ],
+                     zoom: 14,
+                     bearing: 0,
+                     pitch: 0,
+                     duration: 2000,
+                   });
+                   if (window.map && window._marker) {
+                     window._marker.remove();
+                     window._marker = null;
+                   }
+                   if (window.map) {
+                     var el = document.createElement('div');
+                     el.id = 'marker';
+                     el.style.backgroundImage = `url(${icon_map_location})`;
+                     el.style.backgroundSize = 'cover';
+                     el.style.width = '24px';
+                     el.style.height = '24px';
+                     el.style.borderRadius = '50%';
+
+                     const popup = new window.minemap.Popup({
+                       closeOnClick: false,
+                       closeButton: false,
+                       offset: [0, -15],
+                     }).setText(ll);
+
+                     window._marker = new window.minemap.Marker(el, {
+                       offset: [-12, -12],
+                     })
+                       .setLngLat([
+                         Number(location.split(',')[0]),
+                         Number(location.split(',')[1]),
+                       ])
+                       .setPopup(popup)
+                       .addTo(window.map);
+                   }
+                   window._marker.togglePopup();
+                   //  var ll =
+                   //    data.regeocodes[0].formatted_address.replaceAll(
+                   //      '江苏省宿迁市',
+                   //    "");
+
+                   form.value.locations = location;
+                   form.value.addr = ll;
+                 });
+               // minemap.service
+               //   .adminByPointData({
+               //     location: `${position.coords.longitude},${position.coords.latitude}`,
+               //   })
+               //   .then(function (response) {
+               //     console.log(response.data);
+               //   })
+               //   .catch(function (error) {
+               //     console.error(error);
+               //   });
+             
+            //  (ee) => {
+            //    console.log(ee);
+            //  },
+           
+         } else {
+           Notify({
+             type: 'danger',
+             message: 'App不支持地理定位。',
+           });
+         }
+      })
+
+     
     };
 
     onMounted(async () => {
@@ -374,17 +393,24 @@ export default defineComponent({
               type="textarea"
               placeholder="请输入"
             />
-            <Field
-              v-model={form.value.addr}
-              name="事件地点"
-              label="事件地点"
-              placeholder="请输入"
-              required
-              onChange={(add: string) => {
-                addr.value = add.target.value;
-              }}
-              rules={[{ required: true, message: '事件地点必填' }]}
-            />
+            <div style={"position:relative"}>
+              <Field
+                v-model={form.value.addr}
+                name="事件地点"
+                label="事件地点"
+                placeholder="请输入"
+                required
+                style={'width:85%'}
+                onChange={(add: string) => {
+                  addr.value = add.target.value;
+                }}
+                rules={[{ required: true, message: '事件地点必填' }]}
+              />
+              <Button style={'border:none;position:absolute;right:10px;top:0'} onClick={() => { getLocation();}}>
+                <img style={'width:20px;height:20px'} src={icon_location} />
+              </Button>
+            </div>
+
             <QueryMap
               address={addr.value}
               v-model:locations={form.value.locations}