Explorar el Código

文件上传功能增加配合单测功能

jqh hace 5 años
padre
commit
fc082ec110

+ 10 - 8
resources/assets/dcat/extra/upload.js

@@ -557,12 +557,12 @@
                     if (!uploader) {
                         return;
                     }
-                    var ofl = uploader.option('fileNumLimit'),
+                    var fileLimit = uploader.option('fileNumLimit'),
                         num = args.num || 1;
 
-                    if (ofl == '-1') ofl = 0;
+                    if (fileLimit == '-1') fileLimit = 0;
 
-                    num = ofl >= num ? ofl - num : 0;
+                    num = fileLimit >= num ? fileLimit - num : 0;
 
                     if (num == 0) num = '-1';
 
@@ -573,12 +573,12 @@
                     if (!uploader) {
                         return;
                     }
-                    var ofl = uploader.option('fileNumLimit'),
+                    var fileLimit = uploader.option('fileNumLimit'),
                         num = args.num || 1;
 
-                    if (ofl == '-1') ofl = 0;
+                    if (fileLimit == '-1') fileLimit = 0;
 
-                    num = ofl + num;
+                    num = fileLimit + num;
 
                     uploader.option('fileNumLimit', num);
                     break;
@@ -779,7 +779,7 @@
             supportIe();
 
             // 实例化
-            uploader = WebUploader.create(opts.upload);
+            this.uploader = uploader = WebUploader.create(opts.upload);
 
             // 拖拽时不接受 js, txt 文件。
             uploader.on('dndAccept', function (items) {
@@ -1031,6 +1031,8 @@
         return this;
     }
 
-    Dcat.Uploader = Uploader;
+    Dcat.Uploader = function (options) {
+        return new Uploader(options)
+    };
 
 })(window, jQuery);

+ 1 - 1
resources/dist/css/plugins/loaders/animations/ball-grid-beat.css

@@ -1 +1 @@
-@-webkit-keyframes ball-grid-beat{50%{opacity:.7}to{opacity:1}}@keyframes ball-grid-beat{50%{opacity:.7}to{opacity:1}}.ball-grid-beat{width:57px}.ball-grid-beat>div:first-child{-webkit-animation-delay:.44s;animation-delay:.44s;-webkit-animation-duration:1.57s;animation-duration:1.57s}.ball-grid-beat>div:nth-child(2){-webkit-animation-delay:.45s;animation-delay:.45s;-webkit-animation-duration:1.41s;animation-duration:1.41s}.ball-grid-beat>div:nth-child(3){-webkit-animation-delay:.06s;animation-delay:.06s;-webkit-animation-duration:1.43s;animation-duration:1.43s}.ball-grid-beat>div:nth-child(4){-webkit-animation-delay:.19s;animation-delay:.19s;-webkit-animation-duration:1.59s;animation-duration:1.59s}.ball-grid-beat>div:nth-child(5){-webkit-animation-delay:-.18s;animation-delay:-.18s;-webkit-animation-duration:.71s;animation-duration:.71s}.ball-grid-beat>div:nth-child(6){-webkit-animation-delay:.16s;animation-delay:.16s;-webkit-animation-duration:1.23s;animation-duration:1.23s}.ball-grid-beat>div:nth-child(7){-webkit-animation-delay:.1s;animation-delay:.1s;-webkit-animation-duration:1.42s;animation-duration:1.42s}.ball-grid-beat>div:nth-child(8){-webkit-animation-delay:0s;animation-delay:0s;-webkit-animation-duration:1.27s;animation-duration:1.27s}.ball-grid-beat>div:nth-child(9){-webkit-animation-delay:.76s;animation-delay:.76s;-webkit-animation-duration:1.4s;animation-duration:1.4s}.ball-grid-beat>div{background-color:#b8c2cc;width:15px;height:15px;border-radius:100%;margin:2px;-webkit-animation-fill-mode:both;animation-fill-mode:both;display:inline-block;float:left;-webkit-animation-name:ball-grid-beat;animation-name:ball-grid-beat;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite;-webkit-animation-delay:0;animation-delay:0}
+@-webkit-keyframes ball-grid-beat{50%{opacity:.7}to{opacity:1}}@keyframes ball-grid-beat{50%{opacity:.7}to{opacity:1}}.ball-grid-beat{width:57px}.ball-grid-beat>div:first-child{-webkit-animation-delay:.11s;animation-delay:.11s;-webkit-animation-duration:1.57s;animation-duration:1.57s}.ball-grid-beat>div:nth-child(2){-webkit-animation-delay:.4s;animation-delay:.4s;-webkit-animation-duration:.91s;animation-duration:.91s}.ball-grid-beat>div:nth-child(3){-webkit-animation-delay:.06s;animation-delay:.06s;-webkit-animation-duration:.85s;animation-duration:.85s}.ball-grid-beat>div:nth-child(4){-webkit-animation-delay:.64s;animation-delay:.64s;-webkit-animation-duration:.67s;animation-duration:.67s}.ball-grid-beat>div:nth-child(5){-webkit-animation-delay:.58s;animation-delay:.58s;-webkit-animation-duration:1.55s;animation-duration:1.55s}.ball-grid-beat>div:nth-child(6){-webkit-animation-delay:-.03s;animation-delay:-.03s;-webkit-animation-duration:.99s;animation-duration:.99s}.ball-grid-beat>div:nth-child(7){-webkit-animation-delay:.7s;animation-delay:.7s;-webkit-animation-duration:1.22s;animation-duration:1.22s}.ball-grid-beat>div:nth-child(8){-webkit-animation-delay:.61s;animation-delay:.61s;-webkit-animation-duration:1.22s;animation-duration:1.22s}.ball-grid-beat>div:nth-child(9){-webkit-animation-delay:.41s;animation-delay:.41s;-webkit-animation-duration:.63s;animation-duration:.63s}.ball-grid-beat>div{background-color:#b8c2cc;width:15px;height:15px;border-radius:100%;margin:2px;-webkit-animation-fill-mode:both;animation-fill-mode:both;display:inline-block;float:left;-webkit-animation-name:ball-grid-beat;animation-name:ball-grid-beat;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite;-webkit-animation-delay:0;animation-delay:0}

+ 1 - 1
resources/dist/css/plugins/loaders/animations/ball-grid-pulse.css

@@ -1 +1 @@
-@-webkit-keyframes ball-grid-pulse{0%{transform:scale(1)}50%{transform:scale(.5);opacity:.7}to{transform:scale(1);opacity:1}}@keyframes ball-grid-pulse{0%{transform:scale(1)}50%{transform:scale(.5);opacity:.7}to{transform:scale(1);opacity:1}}.ball-grid-pulse{width:57px}.ball-grid-pulse>div:first-child{-webkit-animation-delay:.34s;animation-delay:.34s;-webkit-animation-duration:1.07s;animation-duration:1.07s}.ball-grid-pulse>div:nth-child(2){-webkit-animation-delay:.23s;animation-delay:.23s;-webkit-animation-duration:1.24s;animation-duration:1.24s}.ball-grid-pulse>div:nth-child(3){-webkit-animation-delay:.24s;animation-delay:.24s;-webkit-animation-duration:1.16s;animation-duration:1.16s}.ball-grid-pulse>div:nth-child(4){-webkit-animation-delay:-.09s;animation-delay:-.09s;-webkit-animation-duration:.96s;animation-duration:.96s}.ball-grid-pulse>div:nth-child(5){-webkit-animation-delay:.8s;animation-delay:.8s;-webkit-animation-duration:1.02s;animation-duration:1.02s}.ball-grid-pulse>div:nth-child(6){-webkit-animation-delay:.08s;animation-delay:.08s;-webkit-animation-duration:1.5s;animation-duration:1.5s}.ball-grid-pulse>div:nth-child(7){-webkit-animation-delay:-.14s;animation-delay:-.14s;-webkit-animation-duration:.96s;animation-duration:.96s}.ball-grid-pulse>div:nth-child(8){-webkit-animation-delay:.04s;animation-delay:.04s;-webkit-animation-duration:1.51s;animation-duration:1.51s}.ball-grid-pulse>div:nth-child(9){-webkit-animation-delay:.15s;animation-delay:.15s;-webkit-animation-duration:1.3s;animation-duration:1.3s}.ball-grid-pulse>div{background-color:#b8c2cc;width:15px;height:15px;border-radius:100%;margin:2px;-webkit-animation-fill-mode:both;animation-fill-mode:both;display:inline-block;float:left;-webkit-animation-name:ball-grid-pulse;animation-name:ball-grid-pulse;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite;-webkit-animation-delay:0;animation-delay:0}
+@-webkit-keyframes ball-grid-pulse{0%{transform:scale(1)}50%{transform:scale(.5);opacity:.7}to{transform:scale(1);opacity:1}}@keyframes ball-grid-pulse{0%{transform:scale(1)}50%{transform:scale(.5);opacity:.7}to{transform:scale(1);opacity:1}}.ball-grid-pulse{width:57px}.ball-grid-pulse>div:first-child{-webkit-animation-delay:.16s;animation-delay:.16s;-webkit-animation-duration:1.38s;animation-duration:1.38s}.ball-grid-pulse>div:nth-child(2){-webkit-animation-delay:.17s;animation-delay:.17s;-webkit-animation-duration:1.16s;animation-duration:1.16s}.ball-grid-pulse>div:nth-child(3){-webkit-animation-delay:.64s;animation-delay:.64s;-webkit-animation-duration:.98s;animation-duration:.98s}.ball-grid-pulse>div:nth-child(4){-webkit-animation-delay:.34s;animation-delay:.34s;-webkit-animation-duration:.89s;animation-duration:.89s}.ball-grid-pulse>div:nth-child(5){-webkit-animation-delay:.11s;animation-delay:.11s;-webkit-animation-duration:1.41s;animation-duration:1.41s}.ball-grid-pulse>div:nth-child(6){-webkit-animation-delay:.5s;animation-delay:.5s;-webkit-animation-duration:1.56s;animation-duration:1.56s}.ball-grid-pulse>div:nth-child(7){-webkit-animation-delay:-.04s;animation-delay:-.04s;-webkit-animation-duration:1.54s;animation-duration:1.54s}.ball-grid-pulse>div:nth-child(8){-webkit-animation-delay:.31s;animation-delay:.31s;-webkit-animation-duration:.69s;animation-duration:.69s}.ball-grid-pulse>div:nth-child(9){-webkit-animation-delay:.76s;animation-delay:.76s;-webkit-animation-duration:1.43s;animation-duration:1.43s}.ball-grid-pulse>div{background-color:#b8c2cc;width:15px;height:15px;border-radius:100%;margin:2px;-webkit-animation-fill-mode:both;animation-fill-mode:both;display:inline-block;float:left;-webkit-animation-name:ball-grid-pulse;animation-name:ball-grid-pulse;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite;-webkit-animation-delay:0;animation-delay:0}

+ 1 - 1
resources/dist/css/plugins/loaders/animations/line-scale-random.css

@@ -1 +1 @@
-@-webkit-keyframes line-scale-party{0%{transform:scale(1)}50%{transform:scale(.5)}to{transform:scale(1)}}@keyframes line-scale-party{0%{transform:scale(1)}50%{transform:scale(.5)}to{transform:scale(1)}}.line-scale-party>div:first-child{-webkit-animation-delay:.02s;animation-delay:.02s;-webkit-animation-duration:.54s;animation-duration:.54s}.line-scale-party>div:nth-child(2){-webkit-animation-delay:.29s;animation-delay:.29s;-webkit-animation-duration:.85s;animation-duration:.85s}.line-scale-party>div:nth-child(3){-webkit-animation-delay:-.1s;animation-delay:-.1s;-webkit-animation-duration:1.18s;animation-duration:1.18s}.line-scale-party>div:nth-child(4){-webkit-animation-delay:.41s;animation-delay:.41s;-webkit-animation-duration:1.01s;animation-duration:1.01s}.line-scale-party>div{background-color:#b8c2cc;width:4px;height:3.45rem;border-radius:2px;margin:2px;-webkit-animation-fill-mode:both;animation-fill-mode:both;display:inline-block;-webkit-animation-name:line-scale-party;animation-name:line-scale-party;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite;-webkit-animation-delay:0;animation-delay:0}
+@-webkit-keyframes line-scale-party{0%{transform:scale(1)}50%{transform:scale(.5)}to{transform:scale(1)}}@keyframes line-scale-party{0%{transform:scale(1)}50%{transform:scale(.5)}to{transform:scale(1)}}.line-scale-party>div:first-child{-webkit-animation-delay:.2s;animation-delay:.2s;-webkit-animation-duration:.63s;animation-duration:.63s}.line-scale-party>div:nth-child(2){-webkit-animation-delay:.77s;animation-delay:.77s;-webkit-animation-duration:.85s;animation-duration:.85s}.line-scale-party>div:nth-child(3){-webkit-animation-delay:-.16s;animation-delay:-.16s;-webkit-animation-duration:.68s;animation-duration:.68s}.line-scale-party>div:nth-child(4){-webkit-animation-delay:.48s;animation-delay:.48s;-webkit-animation-duration:1s;animation-duration:1s}.line-scale-party>div{background-color:#b8c2cc;width:4px;height:3.45rem;border-radius:2px;margin:2px;-webkit-animation-fill-mode:both;animation-fill-mode:both;display:inline-block;-webkit-animation-name:line-scale-party;animation-name:line-scale-party;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite;-webkit-animation-delay:0;animation-delay:0}

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
resources/dist/css/plugins/loaders/loaders.css


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
resources/dist/dcat/extra/upload.js


+ 2 - 1
resources/views/form/file.blade.php

@@ -6,7 +6,8 @@
 
         @include('admin::form.error')
 
-        <input name="{{$name}}" id="{{ $id }}" type="hidden" />
+        <input name="{{ $name }}" id="{{ $id }}" type="hidden" />
+        <input name="file-{{ $name }}" type="file" style="display: none"/>
 
         <div class="web-uploader {{ $fileType }}">
             <div class="queueList">

+ 13 - 9
src/Form/Field/File.php

@@ -195,7 +195,7 @@ class File extends Field implements UploadFieldInterface
 
         $this->script = <<<JS
 (function () {
-    var upload, options = {$options}, listenComplete;
+    var uploader, newPage, options = {$options};
 
     build();
 
@@ -214,26 +214,30 @@ class File extends Field implements UploadFieldInterface
             paste: '#{$this->containerId} .web-uploader'
         }, opts);
 
-        upload = Dcat.Uploader(opts);
-        upload.build();
-        upload.preview();
+        uploader = Dcat.Uploader(opts);
+        uploader.build();
+        uploader.preview();
 
         function resize() {
             setTimeout(function () {
-                if (! upload) return;
+                if (! uploader) return;
 
-                upload.refreshButton();
+                uploader.refreshButton();
                 resize();
 
-                if (! listenComplete) {
-                    listenComplete = 1;
+                if (! newPage) {
+                    newPage = 1;
                     $(document).one('pjax:complete', function () {
-                        upload = null;
+                        uploader = null;
                     });
                 }
             }, 250);
         }
         resize();
+        
+        $('[name="file-{$this->getElementName()}"]').change(function () {
+            uploader.uploader.addFiles(this.files);
+        });
     }
 })();
 JS;

+ 4 - 3
src/Form/Field/Map.php

@@ -2,6 +2,7 @@
 
 namespace Dcat\Admin\Form\Field;
 
+use Dcat\Admin\Admin;
 use Dcat\Admin\Form\Field;
 
 class Map extends Field
@@ -16,9 +17,9 @@ class Map extends Field
     /**
      * Get assets required by this field.
      *
-     * @return array
+     * @return void
      */
-    public static function getAssets()
+    public static function collectAssets()
     {
         switch (config('admin.map_provider')) {
             case 'tencent':
@@ -34,7 +35,7 @@ class Map extends Field
                 $js = '//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key='.env('GOOGLE_API_KEY');
         }
 
-        return compact('js');
+        Admin::js($js);
     }
 
     public function __construct($column, $arguments)

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio