Sfoglia il codice sorgente

加强结果预览,去除无用代码,

mxd 3 anni fa
parent
commit
82aa155848

+ 2 - 41
magic-editor/src/console/src/components/editor/magic-script-editor.vue

@@ -57,14 +57,6 @@
         <button class="ma-button" @click="showHsitoryDialog = false">关闭</button>
       </template>
     </magic-dialog>
-    <magic-dialog :value="showImageDialog" title="图片结果" @onClose="showImageDialog = false">
-      <template #content>
-        <p align="center"><img :src="imageUrl"/></p>
-      </template>
-      <template #buttons>
-        <button class="ma-button" @click="showImageDialog = false">OK</button>
-      </template>
-    </magic-dialog>
   </div>
 </template>
 
@@ -95,8 +87,6 @@ export default {
       selected: null,
       info: null,
       editor: null,
-      showImageDialog: false,
-      imageUrl: '',
       showHsitoryDialog: false,
       // tab拖拽的item
       draggableItem: {},
@@ -652,7 +642,7 @@ export default {
               const contentType = res.headers['content-type']
               target.ext.debugDecorations && this.editor.deltaDecorations(target.ext.debugDecorations, [])
               target.ext.debugDecorations = target.ext.debugDecoration = null
-              if (contentType.indexOf('application/json') > -1) {
+              if (!(data instanceof Blob)) {
                 target.ext.debuging = target.running = false
                 if (data.body && res.headers[contants.HEADER_RESPONSE_WITH_MAGIC_API] === 'true') {
                   let line = data.body
@@ -689,36 +679,7 @@ export default {
                 // 执行完毕
                 target.running = false
                 bus.$emit('switch-tab', 'result')
-                if (contentType === contants.HEADER_APPLICATION_STREAM) {
-                  // 下载
-                  let disposition = res.headers[contants.HEADER_CONTENT_DISPOSITION]
-                  let filename = 'output'
-                  if (disposition) {
-                    filename = decodeURIComponent(disposition.substring(disposition.indexOf('filename=') + 9))
-                  }
-                  target.responseBody = utils.formatJson({filename})
-                  bus.$emit('update-response-body-definition', target.responseBodyDefinition);
-                  bus.$emit('update-response-body', target.responseBody)
-                  let a = document.createElement('a')
-                  a.download = filename
-                  let bstr = atob(data.data)
-                  let n = bstr.length
-                  let u8arr = new Uint8Array(n)
-                  while (n--) {
-                    u8arr[n] = bstr.charCodeAt(n)
-                  }
-                  a.href = window.URL.createObjectURL(new Blob([u8arr]))
-                  a.click()
-                  bus.$emit('report', 'output_blob')
-                } else if (contentType && contentType.indexOf('image') === 0) {
-                  // 图片
-                  this.imageUrl = window.URL.createObjectURL(data)
-                  this.showImageDialog = true
-                  bus.$emit('update-response-body-definition', target.responseBodyDefinition);
-                  target.responseBody = utils.formatJson(data.data)
-                  bus.$emit('update-response-body', target.responseBody)
-                  bus.$emit('report', 'output_image')
-                }
+                bus.$emit('update-response-blob', contentType, data);
               }
             })
           })

+ 0 - 1
magic-editor/src/console/src/components/layout/magic-option.vue

@@ -67,7 +67,6 @@ export default {
       if (this.info.option[index]) {
         this.info.option[index].name = value;
         let item = this.optionsMap[value];
-        console.log(this.optionsMap,value);
         if (item) {
           if (item.description) {
             this.info.option[index].description = item.description

+ 22 - 5
magic-editor/src/console/src/components/layout/magic-run.vue

@@ -1,12 +1,13 @@
 <template>
   <div class="ma-run" style="display: flex; flex-direction: row;">
-    <div style="width: 40%">
+    <div style="width: 40%" v-show="!contentType">
       <div ref="resultEditor" class="ma-body-editor"></div>
     </div>
-    <div style="flex: 1;">
+    <div style="flex: 1;" v-show="!contentType">
       <magic-json :jsonData="responseBody || []" :forceUpdate="forceUpdate" :height="layoutHeight" type="response"></magic-json>
     </div>
-
+    <iframe v-if="contentType" class="ma-response-body-container" style="padding:5px;" :src="this.objectUrl">
+    </iframe>
   </div>
 </template>
 
@@ -31,7 +32,9 @@ export default {
       resultEditor: null,
       responseBody: [],
       forceUpdate: false,
-      layoutHeight: '255px'
+      layoutHeight: '255px',
+      contentType: '',
+      objectUrl: null
     }
   },
   watch: {
@@ -48,12 +51,21 @@ export default {
   mounted() {
     this.createEditor()
     bus.$on('update-response-body', (responseBody) => {
+      this.contentType = null
+      if(this.objectUrl){
+        URL.revokeObjectURL(this.objectUrl)
+        this.objectUrl = null
+      }
       this.resultEditor && this.resultEditor.setValue(responseBody || '')
       this.updateResponseBody(responseBody)
     })
     bus.$on('update-response-body-definition', (responseBodyDefinition) => {
       this.responseBody = responseBodyDefinition ? [responseBodyDefinition] : []
     })
+    bus.$on('update-response-blob',(contentType, blob) => {
+      this.contentType = contentType
+      this.objectUrl = URL.createObjectURL(blob)
+    })
   },
   methods: {
     createEditor() {
@@ -203,7 +215,7 @@ export default {
 </script>
 
 <style scoped>
-div.ma-run {
+div.ma-run{
   background: var(--background);
   height: 100%;
   width: 100%;
@@ -218,4 +230,9 @@ div.ma-run > div {
   width: 100%;
   height: 100%;
 }
+.ma-response-body-container{
+  width: 100%;
+  height: 100%;
+  border: none;
+}
 </style>

+ 2 - 2
magic-editor/src/console/src/components/magic-editor.vue

@@ -104,9 +104,9 @@ export default {
     } else if (contants.BASE_URL.startsWith('/')) { // / 开头的
       link = link + contants.BASE_URL
     } else {
-      // TODO ../..........
+      link = link + '/' + contants.BASE_URL
     }
-    this.websocket = new MagicWebSocket(replaceURL(link.replace(/^http/, 'ws') + '/console').replace('9999',location.hash.substring(1)))
+    this.websocket = new MagicWebSocket(replaceURL(link.replace(/^http/, 'ws') + '/console'))
     contants.DEFAULT_EXPAND = this.config.defaultExpand !== false
     this.config.version = contants.MAGIC_API_VERSION_TEXT
     this.config.title = this.config.title || 'magic-api'

+ 0 - 1
magic-editor/src/console/src/components/resources/magic-resource-choose.vue

@@ -220,7 +220,6 @@ export default {
       this.getParents(item.folder ? item.parentId : item.groupId).forEach(node => {
         node.selected = node.children.some(it => it.selected)
         node.checkedHalf = node.children.some(it => !it.selected || it.checkedHalf)
-        console.log(node.name,node)
       })
     },
     // 重新构建tree的path和name,第一个参数表示是否全部折叠

+ 0 - 2
magic-editor/src/console/src/scripts/websocket.js

@@ -2,7 +2,6 @@ import bus from "@/scripts/bus";
 import ReconnectingWebSocket from './reconnecting-websocket'
 function MagicWebSocket(url) {
     this.listeners = {};
-    console.log(url)
     this.socket = new ReconnectingWebSocket(url);
     this.socket.onmessage = this.messageReceived;
     bus.$on('message', (msgType, content) => {
@@ -34,7 +33,6 @@ MagicWebSocket.prototype.messageReceived = function (e) {
         args.push(newIndex === -1 ? payload : payload.substring(index + 1, newIndex))
         index = newIndex
     }
-    console.log(msgType, args)
     bus.$emit('ws_' + msgType, args)
 }
 MagicWebSocket.prototype.close = function () {