guhongwei 4 years ago
parent
commit
5f2f50bd21
1 changed files with 25 additions and 2 deletions
  1. 25 2
      src/layout/index/top-right.vue

+ 25 - 2
src/layout/index/top-right.vue

@@ -25,17 +25,24 @@ export default {
       myChart: null,
       // 结点
       hyjdTotal: 0,
+      serveTime: true,
     };
   },
   async created() {
     await this.init();
   },
+  mounted() {
+    this.channel();
+    if (this.serveTime) {
+      this.searchNode();
+      this.searchNode = false;
+    }
+  },
   methods: {
-    ...topmessage(['query']),
+    ...topmessage(['query', 'querytwo']),
     async init() {
       let res = await this.query();
       if (this.$checkRes(res)) {
-        this.channel();
         this.myChart = echarts.init(document.getElementById('chart'));
         const option = {
           title: { text: '运行动态', left: 'center' },
@@ -71,6 +78,10 @@ export default {
         });
       }
     },
+    // 页面一次性请求
+    async searchNode() {
+      let res = await this.querytwo();
+    },
     channel() {
       this.$stomp({
         [`/exchange/service_count/nodes`]: this.onMessage,
@@ -78,9 +89,21 @@ export default {
     },
     onMessage(message) {
       let data = JSON.parse(message.body).filter(i => i.node != 'gpu01');
+      console.log(data.length);
       this.$set(this, 'hyjdTotal', data.length);
     },
   },
+  watch: {
+    hyjdTotal: {
+      immediate: true,
+      deep: true,
+      handler(val) {
+        if (val) {
+          this.init();
+        }
+      },
+    },
+  },
   computed: {
     ...mapState(['']),
     pageTitle() {