瀏覽代碼

format output

thomas 3 年之前
父節點
當前提交
a4052c3d3e
共有 1 個文件被更改,包括 58 次插入32 次删除
  1. 58 32
      src/components/AdminCommands.vue

+ 58 - 32
src/components/AdminCommands.vue

@@ -23,51 +23,77 @@ export default class AdminCommands extends Vue {
 
   requestCmds = [
     { keyword: 'login', label: 'getCurrentLogins' },
-    { keyword: 'conn',  label: 'getCurrentConnections' },
-    { keyword: 'sub',   label: 'getSubscriptions' },
+    // { keyword: 'conn',  label: 'getCurrentConnections' },
+    // { keyword: 'sub',   label: 'getSubscriptions' },
     { keyword: 'req',   label: 'getRequests' },
-    { keyword: 'res',   label: 'getResponses' },
+    // { keyword: 'res',   label: 'getResponses' },
   ];
   
   socket = null
   responses = []
   url = 'http://localhost:3111'
+  cnt = 0
 
-  addResponse(cnt, data) {
-    const response = JSON.stringify(data,null,3)
-    // if(Array.isArray(data) && data.length > 0 )
-    // console.log(response)
-    this.responses.unshift({cnt, data: JSON.stringify(data,null,3)})
+  setResponse(data) {
+    if(! Array.isArray(data)) {
+      data = []
+    }
+
+    this.responses = []
+    for (let index = 0; index < data.length; index++) {
+      this.responses.push({
+        cnt: this.cnt++,
+        data: JSON.stringify(
+          this.parseData(data[index]),
+          null, 3
+        )
+      })
+    }
+  }
+  
+  parseData(data) {
+    if( data?.token ) {
+      return this.parseLogin(data)
+    }
+    return this.parseRequest(data)
+  }
+
+  parseLogin(data) {
+    return {
+      "token": data.token, 
+      "lastActionOn": data.lastActionOn, 
+      "connections": data.connections.map(c => ({ 
+        "client": c.client, 
+        "transport": c.transport, 
+        "id": c.id, 
+      }))
+    }
+  }
+
+  parseRequest(data) {
+    const result = {
+      ucpId: data.Message.header.security.ucpId,
+      receivedDate: data.ReceivedDateTime,
+      messageID: data.Message.header.messageID,
+      messageType: data.Message.header.messageType,
+    }
+    if( result.messageType == 'Command' ) {
+      result['command'] = data.Message.header.command
+      if(result['command']=='Start') {
+        result['ucpId'] = null
+      }
+    } else {
+      result['query'] = data.Message.header.query
+    }
+    return result
   }
-  // parseLogin(data) {
-
-  // }
-
- x = [
-   { 
-     "id": "9z55r61", 
-     "token": "9z55r67016", 
-     "lastActionOn": "2021-07-17T13:25:04.406Z", 
-     "timeout": 10000, 
-     "connections": [ 
-       { 
-         "isDone": false, 
-         "client": { 
-           "transport": "socketio", 
-           "id": "O6vmYhBbpHiDmibmAAAE", 
-           "address": "::1", 
-           "url": "/socket.io/?EIO=3&transport=polling&t=Ngqf3qf"
-          }
-        }
-      ]
-   }
- ]
+
   connect(){
     const socket = io.connect(this.url)
     let cnt = 0;
     socket.on('admin_response', (data) => {
       cnt++;
-      this.addResponse(cnt, data);
+      this.setResponse(data?.data);
     })
 
     socket.on('connect', (ws) => {