gemercheung 1 год назад
Родитель
Сommit
5013688de3
4 измененных файлов с 31 добавлено и 4 удалено
  1. 1 0
      package.json
  2. 8 0
      pnpm-lock.yaml
  3. 2 2
      src/locales/lang/json/zh-CN.json
  4. 20 2
      src/views/map/index.vue

+ 1 - 0
package.json

@@ -54,6 +54,7 @@
     "moment": "^2.29.1",
     "nprogress": "^0.2.0",
     "path-to-regexp": "^6.2.0",
+    "ping.js": "^0.3.0",
     "pinia": "2.0.9",
     "print-js": "^1.6.0",
     "qrcode": "^1.5.0",

+ 8 - 0
pnpm-lock.yaml

@@ -88,6 +88,9 @@ importers:
       path-to-regexp:
         specifier: ^6.2.0
         version: 6.2.0
+      ping.js:
+        specifier: ^0.3.0
+        version: 0.3.0
       pinia:
         specifier: 2.0.9
         version: 2.0.9(typescript@4.5.4)(vue@3.2.26)
@@ -4965,6 +4968,9 @@ packages:
     resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==}
     engines: {node: '>=6'}
 
+  ping.js@0.3.0:
+    resolution: {integrity: sha512-qisFwio7j0cwYbOcRL4BlTdxKALcpGPTkpl8ichGASgkrVqfI3sZfQDsP8wETR5rfutXZJLjlJ117aLkRnk2mA==}
+
   pinia@2.0.9:
     resolution: {integrity: sha512-iuYdxLJKQ07YPyOHYH05wNG9eKWqkP/4y4GE8+RqEYtz5fwHgPA5kr6zQbg/DoEJGnR2XCm1w1vdt6ppzL9ATg==}
     peerDependencies:
@@ -12260,6 +12266,8 @@ snapshots:
 
   pify@4.0.1: {}
 
+  ping.js@0.3.0: {}
+
   pinia@2.0.9(typescript@4.5.4)(vue@3.2.26):
     dependencies:
       '@vue/devtools-api': 6.0.0-beta.21.1

+ 2 - 2
src/locales/lang/json/zh-CN.json

@@ -629,6 +629,6 @@
   "layout.map.addScene": "添加场景",
   "layout.map.projectScene": "项目场景",
   "layout.map.mapSelect": "地图选择",
-  "layout.map.mapSearch": "地图搜索"
-  
+  "layout.map.mapSearch": "地图搜索",
+  "layout.map.mapOfflineService": "地图服务访问超时,请检查网络"
 }

+ 20 - 2
src/views/map/index.vue

@@ -130,7 +130,7 @@
 
 <script lang="ts" setup>
   // import { SearchOutlined } from '@ant-design/icons-vue';
-  import { ref, onMounted, watch, computed, watchEffect } from 'vue';
+  import { ref, onMounted, watch, computed, watchEffect, h } from 'vue';
   import {
     GoogleMap,
     AdvancedMarker,
@@ -150,12 +150,14 @@
   import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
   import { useMessage } from '/@/hooks/web/useMessage';
   import shareImage from '/@/assets/images/share.png';
+  import Ping from 'ping.js';
+
   const { t } = useI18n();
   const router = useRouter();
   import { useLocaleStore } from '/@/store/modules/locale';
   const googleKey = computed(() => import.meta.env.VITE_GOOGLE_KEY);
   const center = { lat: 35.717, lng: 139.731 };
-  const { createMessage } = useMessage();
+  const { createMessage, createConfirm } = useMessage();
   // const options = ref([]);
   // const pinOptions = { background: '#FBBC04' };
   const shareOpen = ref(false);
@@ -209,6 +211,22 @@
   );
 
   onMounted(async () => {
+    var p = new Ping();
+    p.ping('http://google.com', function (err, _) {
+      // Also display error if err is returned.
+      if (err) {
+        console.error('error loading resource');
+        createConfirm({
+          iconType: 'warning',
+          title: () => h('span', t('sys.app.logoutTip')),
+          content: () => h('span', t('layout.map.mapOfflineService')),
+          onOk: async () => {},
+        });
+        // data = data + ' ' + err;
+      }
+      // document.getElementById('ping-google').innerHTML = data;
+    });
+
     watchEffect(() => {
       console.log(projectId.value);
       if (projectId.value) {