Kaynağa Gözat

地图promise接口

qinhouyu 1 yıl önce
ebeveyn
işleme
5f81bd614d

+ 12 - 0
songhua-ui/src/api/ship/diqiu.js

@@ -3304,3 +3304,15 @@ export function getMap() {
 function randomData() {
   return Math.round(Math.random() * 300);
 }
+// 返回 Promise
+
+export function getMapPromise() {
+  return new Promise((resolve, reject) => {
+    try {
+      const result = getMap();
+      resolve(result);
+    } catch (error) {
+      reject(error);
+    }
+  });
+}

+ 9 - 4
songhua-ui/src/views/index/index.vue

@@ -249,7 +249,7 @@
 
 <script>
 import * as echarts from 'echarts'
-import {getMap} from "@/api/ship/diqiu";
+import {getMap, getMapPromise} from "@/api/ship/diqiu";
 import {getShipRoute} from "@/api/ship/shipMapping";
 
 export default {
@@ -858,9 +858,14 @@ export default {
       myChart.setOption(option);
     },
     getMapByPerson() {
-      let option = getMap();
-      let myChart = this.$echarts.init(document.getElementById("mapByPerson"));
-      myChart.setOption(option);
+      getMapPromise()
+        .then((result) => {
+          let myChart = this.$echarts.init(document.getElementById("mapByPerson"));
+          myChart.setOption(result);
+        })
+        .catch((error) => {
+          console.error(error);
+        });
     },
     tabClick(state) {
       if (state == 1) {