소스 검색

feat(master): add json url

yonghaohu 5 년 전
부모
커밋
876b157750
3개의 변경된 파일60개의 추가작업 그리고 0개의 파일을 삭제
  1. 34 0
      web/dist/vap.js
  2. 0 0
      web/dist/vap.min.js
  3. 26 0
      web/src/vap-frame-parser.js

+ 34 - 0
web/dist/vap.js

@@ -147,6 +147,14 @@
 
 
               return Promise.resolve().then(function () {
               return Promise.resolve().then(function () {
                   _this2.initCanvas();
                   _this2.initCanvas();
+                  if (/^(http|https):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]\.json$/.test(_this2.config)) {
+                      return Promise.resolve().then(function () {
+                          return _this2.getConfigBySrc(_this2.config);
+                      }).then(function (_resp) {
+                          _this2.config = _resp;
+                      });
+                  }
+              }).then(function () {
                   return _this2.parseSrc(_this2.config);
                   return _this2.parseSrc(_this2.config);
               }).then(function () {
               }).then(function () {
                   _this2.canvas.parentNode.removeChild(_this2.canvas);
                   _this2.canvas.parentNode.removeChild(_this2.canvas);
@@ -222,6 +230,32 @@
                   }).then(function () {});
                   }).then(function () {});
               }));
               }));
           }
           }
+
+          /**
+           * 下载json文件
+           * @param jsonUrl json外链
+           * @returns {Promise}
+           */
+
+      }, {
+          key: 'getConfigBySrc',
+          value: function getConfigBySrc(jsonUrl) {
+              return new Promise(function (resolve, reject) {
+                  var xhr = new XMLHttpRequest();
+                  xhr.open("GET", jsonUrl, true);
+                  xhr.responseType = "json";
+                  xhr.onload = function () {
+                      if (xhr.status === 200 || xhr.status === 304 && xhr.response) {
+                          var res = xhr.response;
+                          resolve(res);
+                      } else {
+                          reject(new Error("http response invalid" + xhr.status));
+                      }
+                  };
+                  xhr.send();
+              });
+          }
+
           /**
           /**
            * 文字转换图片
            * 文字转换图片
            * @param {*} param0
            * @param {*} param0

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
web/dist/vap.min.js


+ 26 - 0
web/src/vap-frame-parser.js

@@ -22,6 +22,9 @@ export default class FrameParser {
     }
     }
     async init() {
     async init() {
         this.initCanvas()
         this.initCanvas()
+        if(/^(http|https):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]\.json$/.test(this.config)){
+          this.config = await this.getConfigBySrc(this.config);
+        }
         await this.parseSrc(this.config)
         await this.parseSrc(this.config)
         this.canvas.parentNode.removeChild(this.canvas)
         this.canvas.parentNode.removeChild(this.canvas)
         this.frame = this.config.frame || []
         this.frame = this.config.frame || []
@@ -81,6 +84,29 @@ export default class FrameParser {
             })
             })
         )
         )
     }
     }
+
+    /**
+     * 下载json文件
+     * @param jsonUrl json外链
+     * @returns {Promise}
+     */
+    getConfigBySrc(jsonUrl) {
+    return new Promise((resolve, reject) => {
+      const xhr = new XMLHttpRequest();
+      xhr.open("GET", jsonUrl, true);
+      xhr.responseType = "json";
+      xhr.onload = function() {
+        if (xhr.status === 200 || xhr.status === 304 && xhr.response) {
+          const res = xhr.response;
+          resolve(res);
+        } else {
+          reject(new Error("http response invalid" + xhr.status));
+        }
+      };
+      xhr.send();
+    });
+  }
+
     /**
     /**
      * 文字转换图片
      * 文字转换图片
      * @param {*} param0
      * @param {*} param0

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.