Przeglądaj źródła

异步加载功能优化

jqh 4 lat temu
rodzic
commit
2aaf9c91bb

+ 13 - 0
resources/assets/dcat/js/extensions/Helpers.js

@@ -244,4 +244,17 @@ export default class Helpers {
             Dcat.warning('预览失败');
         };
     }
+
+    // 异步加载
+    asyncRender(url, callback) {
+        let Dcat = this.dcat;
+
+        $.ajax(url).then(function (data) {
+            callback(
+                Dcat.assets.executeScripts(data, function () {
+                    Dcat.triggerReady();
+                }).render()
+            );
+        })
+    }
 }

Plik diff jest za duży
+ 0 - 0
resources/dist/adminlte/adminlte.js.map


Plik diff jest za duży
+ 0 - 0
resources/dist/dcat/extra/action.js.map


Plik diff jest za duży
+ 0 - 0
resources/dist/dcat/extra/resource-selector.js.map


Plik diff jest za duży
+ 0 - 0
resources/dist/dcat/js/dcat-app.js


Plik diff jest za duży
+ 0 - 0
resources/dist/dcat/js/dcat-app.js.map


+ 2 - 6
src/Grid/Displayers/Expand.php

@@ -101,13 +101,9 @@ $('.grid-expand').off('click').on('click', function () {
             collapse.find('div').loading();
             $('.dcat-loading').css({position: 'inherit', 'padding-top': '70px'});
         
-            $.ajax(url+'&key='+rowKey).then(function (data) {
-                var html = Dcat.assets.executeScripts(data, function () {
-                    Dcat.triggerReady();
-                }).render();
-            
+            Dcat.helpers.asyncRender(url+'&key='+rowKey, function (html) {
                 collapse.html(html);
-            });
+            })
         }
 
         $(this).data('inserted', 1);

+ 1 - 1
src/Grid/Displayers/Modal.php

@@ -17,7 +17,7 @@ class Modal extends AbstractDisplayer
 
     protected function setUpLazyRenderable(LazyRenderable $renderable)
     {
-        return $renderable->with('key', $this->getKey());
+        return clone $renderable->with('key', $this->getKey());
     }
 
     public function display($callback = null)

+ 2 - 24
src/Traits/AsyncRenderable.php

@@ -14,11 +14,11 @@ trait AsyncRenderable
     /**
      * 获取请求地址
      *
-     * @return string
+     * @return string|null
      */
     public function getRequestUrl()
     {
-        return $this->getRenderable()->getUrl();
+        return optional($this->getRenderable())->getUrl();
     }
 
     /**
@@ -40,26 +40,4 @@ trait AsyncRenderable
     {
         return $this->renderable;
     }
-
-    /**
-     * @return string
-     */
-    protected function getRenderableScript()
-    {
-        if (! $this->getRenderable()) {
-            return;
-        }
-
-        return <<<JS
-function render(callback) {
-    $.ajax('{$this->getRequestUrl()}').then(function (data) {
-        callback(
-            Dcat.assets.executeScripts(data, function () {
-                Dcat.triggerReady();
-            }).render()
-        );
-    })
-}
-JS;
-    }
 }

+ 2 - 7
src/Widgets/Modal.php

@@ -14,8 +14,6 @@ class Modal extends Widget
 {
     use AsyncRenderable;
 
-    protected $view = 'admin::widgets.modal';
-
     /**
      * @var string
      */
@@ -254,8 +252,7 @@ JS;
 
     protected function addRenderableScript()
     {
-        $script = $this->getRenderableScript();
-        if (! $script) {
+        if (! $url = $this->getRequestUrl()) {
             return;
         }
 
@@ -264,9 +261,7 @@ var modal = $(this).find('.modal-body');
 
 modal.html('<div style="min-height:150px"></div>').loading();
         
-{$script}
-
-render(function (html) {
+Dcat.helpers.asyncRender('{$url}', function (html) {
     modal.html(html);
 });
 JS

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików