Jelajahi Sumber

feat(master): add json url

yonghaohu 5 tahun lalu
induk
melakukan
876b157750
3 mengubah file dengan 60 tambahan dan 0 penghapusan
  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 () {
                   _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);
               }).then(function () {
                   _this2.canvas.parentNode.removeChild(_this2.canvas);
@@ -222,6 +230,32 @@
                   }).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

File diff ditekan karena terlalu besar
+ 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() {
         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)
         this.canvas.parentNode.removeChild(this.canvas)
         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

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini