Просмотр исходного кода

网络加载 回调函数失败的情况下 加载不取消问题优化

wuxw лет назад: 6
Родитель
Сommit
49ee2d1199
1 измененных файлов с 45 добавлено и 15 удалено
  1. 45 15
      java110-front/src/main/resources/static/js/core.js

+ 45 - 15
java110-front/src/main/resources/static/js/core.js

@@ -62,11 +62,21 @@
             vc.loading('open');
             vc.loading('open');
             Vue.http.post('/callComponent/' + componentCode + "/" + componentMethod, param, options)
             Vue.http.post('/callComponent/' + componentCode + "/" + componentMethod, param, options)
                 .then(function (res) {
                 .then(function (res) {
-                    successCallback(res.bodyText, res);
-                    vc.loading('close');
+                    try {
+                        successCallback(res.bodyText, res);
+                    } catch (e) {
+                        console.error(e);
+                    } finally {
+                        vc.loading('close');
+                    }
                 }, function (error) {
                 }, function (error) {
-                    errorCallback(error.bodyText, error);
-                    vc.loading('close');
+                    try {
+                        errorCallback(error.bodyText, error);
+                    } catch (e) {
+                        console.error(e);
+                    } finally {
+                        vc.loading('close');
+                    }
                 });
                 });
         },
         },
         get: function (componentCode, componentMethod, param, successCallback, errorCallback) {
         get: function (componentCode, componentMethod, param, successCallback, errorCallback) {
@@ -83,25 +93,45 @@
             vc.loading('open');
             vc.loading('open');
             Vue.http.get('/callComponent/' + componentCode + "/" + componentMethod, param)
             Vue.http.get('/callComponent/' + componentCode + "/" + componentMethod, param)
                 .then(function (res) {
                 .then(function (res) {
-                    successCallback(res.bodyText, res);
-                    if (vc.constant.GET_CACHE_URL.includes(_getPath) && res.status == 200) {
-                        vc.saveData(_getPath, JSON.parse(res.bodyText));
+                    try {
+                        successCallback(res.bodyText, res);
+                        if (vc.constant.GET_CACHE_URL.includes(_getPath) && res.status == 200) {
+                            vc.saveData(_getPath, JSON.parse(res.bodyText));
+                        }
+                    } catch (e) {
+                        console.error(e);
+                    } finally {
+                        vc.loading('close');
                     }
                     }
-                    vc.loading('close');
                 }, function (error) {
                 }, function (error) {
-                    errorCallback(error.bodyText, error);
-                    vc.loading('close');
+                    try {
+                        errorCallback(error.bodyText, error);
+                    } catch (e) {
+                        console.error(e);
+                    } finally {
+                        vc.loading('close');
+                    }
                 });
                 });
         },
         },
         upload: function (componentCode, componentMethod, param, options, successCallback, errorCallback) {
         upload: function (componentCode, componentMethod, param, options, successCallback, errorCallback) {
             vc.loading('open');
             vc.loading('open');
             Vue.http.post('/callComponent/upload/' + componentCode + "/" + componentMethod, param, options)
             Vue.http.post('/callComponent/upload/' + componentCode + "/" + componentMethod, param, options)
                 .then(function (res) {
                 .then(function (res) {
-                    successCallback(res.bodyText, res);
-                    vc.loading('close');
+                    try {
+                        successCallback(res.bodyText, res);
+                    } catch (e) {
+                        console.error(e);
+                    } finally {
+                        vc.loading('close');
+                    }
                 }, function (error) {
                 }, function (error) {
-                    errorCallback(error.bodyText, error);
-                    vc.loading('close');
+                    try {
+                        errorCallback(error.bodyText, error);
+                    } catch (e) {
+                        console.error(e);
+                    } finally {
+                        vc.loading('close');
+                    }
                 });
                 });
 
 
         },
         },
@@ -411,7 +441,7 @@
  toast
  toast
  **/
  **/
 (function (vc) {
 (function (vc) {
-    vc.urlToBase64 = function urlToBase64(_url,_callFun) {
+    vc.urlToBase64 = function urlToBase64(_url, _callFun) {
         var imgData;
         var imgData;
         var reader = new FileReader();
         var reader = new FileReader();
         getImageBlob(_url, function (blob) {
         getImageBlob(_url, function (blob) {