Ver Fonte

优化执行结果显示,保持`JSON`原样输出

mxd há 3 anos atrás
pai
commit
9747e7642a

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

@@ -719,7 +719,8 @@ export default {
           reader.readAsText(data)
           reader.onload = function() {
             try{
-              resolve(JSON.parse(this.result))
+              JSON.parse(this.result)
+              resolve(this.result)
             }catch(e){
               resolve(data)
             }

+ 4 - 8
magic-editor/src/console/src/scripts/utils.js

@@ -1,15 +1,11 @@
 import request from "@/api/request";
-
+const Beautifier = require('./beautifier/javascript/beautifier').Beautifier
 const replaceURL = (url) => url.replace(/:?\/+/g, e => e.indexOf(':') > -1 ? e : '/');
 const isVisible = (elem) => elem && !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length);
 const formatJson = (val, defaultVal) => {
     if (val) {
         if (typeof val == 'string') {
-            try {
-                val = JSON.parse(val);
-            } catch (ignored) {
-                return val;
-            }
+            return new Beautifier(val).beautify()
         }
         if (val) {
             return JSON.stringify(val, null, 4);
@@ -104,8 +100,8 @@ const goToAnchor = (dom) => {
 
 /**
  * 获取url中的参数
- * @param {String} variable 
- * @returns 
+ * @param {String} variable
+ * @returns
  */
 const getQueryVariable = (variable) => {
   var query = window.location.search.substring(1)