Ver Fonte

Merge pull request #10 from jqhph/master

拉取代码
yxx há 5 anos atrás
pai
commit
968ee6d3c9

+ 5 - 7
resources/views/grid/data-table.blade.php

@@ -4,23 +4,21 @@
     @if ($grid->allowToolbar())
         <div class="custom-data-table-header">
             <div class="table-responsive">
-                <div class="top" style="padding: 0">
+                <div class="top d-block" style="padding: 0">
                 @if(!empty($title))
-                    <h4 style="margin:5px 10px 0;">
+                    <h4 class="pull-left" style="margin:5px 10px 0;">
                         {!! $title !!}&nbsp;
                         @if(!empty($description))
                             <small>{!! $description!!}</small>
                         @endif
                     </h4>
-                    <div data-responsive-table-toolbar="{{$tableId}}">
+                    <div class="pull-right" data-responsive-table-toolbar="{{$tableId}}">
                         {!! $grid->renderTools() !!} {!! $grid->renderCreateButton() !!} {!! $grid->renderExportButton() !!}  {!! $grid->renderQuickSearch() !!}
                     </div>
                 @else
-                    <div>
-                        {!! $grid->renderTools() !!}  {!! $grid->renderQuickSearch() !!}
-                    </div>
+                    {!! $grid->renderTools() !!}  {!! $grid->renderQuickSearch() !!}
 
-                    <div data-responsive-table-toolbar="{{$tableId}}">
+                    <div class="pull-right" data-responsive-table-toolbar="{{$tableId}}">
                         {!! $grid->renderCreateButton() !!} {!! $grid->renderExportButton() !!}
                     </div>
                 @endif

+ 0 - 12
src/Form/Field/WebUploader.php

@@ -221,16 +221,4 @@ trait WebUploader
     {
         $this->options['preview'] = $this->initialPreviewConfig();
     }
-
-    /**
-     * @param array $options
-     *
-     * @return $this
-     */
-    public function options($options = [])
-    {
-        $this->options = array_merge($options, $this->options);
-
-        return $this;
-    }
 }

+ 3 - 0
src/Grid/Column.php

@@ -5,6 +5,7 @@ namespace Dcat\Admin\Grid;
 use Closure;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Grid\Displayers\AbstractDisplayer;
+use Dcat\Admin\Grid\Displayers\Orderable;
 use Dcat\Admin\Traits\HasBuilderEvents;
 use Dcat\Admin\Traits\HasDefinitions;
 use Illuminate\Contracts\Support\Arrayable;
@@ -36,6 +37,7 @@ use Illuminate\Support\Traits\Macroable;
  * @method $this downloadable($server = '', $disk = null)
  * @method $this copyable()
  * @method $this orderable()
+ * @method $this limit(int $limit = 100, string $end = '...')
  * @method $this ascii()
  * @method $this camel()
  * @method $this finish($cap)
@@ -89,6 +91,7 @@ class Column
         'downloadable'     => Displayers\Downloadable::class,
         'copyable'         => Displayers\Copyable::class,
         'orderable'        => Displayers\Orderable::class,
+        'limit'            => Displayers\Limit::class,
     ];
 
     /**

+ 0 - 34
src/Grid/Column/HasDisplayers.php

@@ -6,7 +6,6 @@ use Dcat\Admin\Admin;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Grid\Column;
 use Dcat\Admin\Grid\Displayers\AbstractDisplayer;
-use Dcat\Admin\Support\Helper;
 use Illuminate\Contracts\Support\Arrayable;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Collection;
@@ -218,39 +217,6 @@ trait HasDisplayers
         });
     }
 
-    /**
-     * Limit the number of characters in a string, or the number of element in a array.
-     *
-     * @param int    $limit
-     * @param string $end
-     *
-     * @return $this
-     */
-    public function limit($limit = 100, $end = '...')
-    {
-        return $this->display(function ($value) use ($limit, $end) {
-            if ($value !== null && ! is_scalar($value)) {
-                $value = Helper::array($value);
-
-                if (count($value) <= $limit) {
-                    return $value;
-                }
-
-                $value = array_slice($value, 0, $limit);
-
-                array_push($value, $end);
-
-                return $value;
-            }
-
-            if (mb_strlen($value, 'UTF-8') <= $limit) {
-                return $value;
-            }
-
-            return mb_substr($value, 0, $limit).$end;
-        });
-    }
-
     /**
      * @return $this
      */

+ 15 - 3
src/Grid/Displayers/Expand.php

@@ -66,16 +66,28 @@ EOT;
     {
         $script = <<<'JS'
 $('.grid-expand').off('click').on('click', function () {
+    var _th = $(this);
     
     if ($(this).data('inserted') == '0') {
     
-        var key = $(this).data('key');
-        var row = $(this).closest('tr');
+        var key = _th.data('key');
+        var row = _th.closest('tr');
         var html = $('template.grid-expand-'+key).html();
+        var id = 'expand-'+key+Dcat.helpers.random(10);
+        
+        $(this).attr('data-expand', '#'+id);
 
-        row.after("<tr><td colspan='"+(row.find('td').length)+"' style='padding:0 !important; border:0;height:0;'>"+html+"</td></tr>");
+        row.after("<tr id="+id+"><td colspan='"+(row.find('td').length)+"' style='padding:0 !important; border:0;height:0;'>"+html+"</td></tr>");
 
         $(this).data('inserted', 1);
+    } else {
+        if ($("i", this).hasClass('icon-chevrons-right')) {
+            $(_th.data('expand')).show();
+        } else {
+            setTimeout(function() {
+              $(_th.data('expand')).hide();
+            }, 250);
+        }
     }
     
     $("i", this).toggleClass("icon-chevrons-right icon-chevrons-down");

+ 61 - 0
src/Grid/Displayers/Limit.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace Dcat\Admin\Grid\Displayers;
+
+use Dcat\Admin\Admin;
+use Dcat\Admin\Support\Helper;
+use Illuminate\Support\Str;
+
+class Limit extends AbstractDisplayer
+{
+    protected function addScript()
+    {
+        $script = <<<'JS'
+$('.limit-more').click(function () {
+    $(this).parent('.limit-text').toggleClass('d-none').siblings().toggleClass('d-none');
+});
+JS;
+
+        Admin::script($script);
+    }
+
+    public function display($limit = 100, $end = '...')
+    {
+        // 数组
+        if ($this->value !== null && ! is_scalar($this->value)) {
+            $value = Helper::array($this->value);
+
+            if (count($value) <= $limit) {
+                return $value;
+            }
+
+            $value = array_slice($value, 0, $limit);
+
+            array_push($value, $end);
+
+            return $value;
+        }
+
+        // 字符串
+        $this->addScript();
+
+        $value = Str::limit($this->value, $limit, $end);
+
+        $original = $this->column->getOriginal();
+
+        if ($value == $original) {
+            return $value;
+        }
+
+        return <<<HTML
+<div class="limit-text">
+    <span class="text">{$value}</span>
+    &nbsp;<a href="javascript:void(0);" class="limit-more">&nbsp;<i class="fa fa-angle-double-down"></i></a>
+</div>
+<div class="limit-text d-none">
+    <span class="text">{$original}</span>
+    &nbsp;<a href="javascript:void(0);" class="limit-more">&nbsp;<i class="fa fa-angle-double-up"></i></a>
+</div>
+HTML;
+    }
+}

+ 12 - 5
src/Grid/Tools/QuickCreate.php

@@ -22,14 +22,17 @@ class QuickCreate implements Renderable
      * @var Collection
      */
     protected $fields;
+
     /**
      * @var string
      */
     protected $action;
+
     /**
      * @var string
      */
-    protected $method;
+    protected $method = 'POST';
+
     /**
      * QuickCreate constructor.
      *
@@ -40,7 +43,6 @@ class QuickCreate implements Renderable
         $this->parent = $grid;
         $this->fields = Collection::make();
         $this->action = request()->url();
-        $this->method = "POST";
     }
 
     protected function formatPlaceholder($placeholder)
@@ -269,23 +271,28 @@ class QuickCreate implements Renderable
 
         return "admin::grid.quick-create.{$name}";
     }
+
     /**
-     * @param $action
+     * @param string $action
+     *
      * @return $this
      */
-    public function action($action)
+    public function action(?string $action)
     {
         $this->action = admin_url($action);
+
         return $this;
     }
 
     /**
      * @param string $method
+     *
      * @return $this
      */
-    public function method($method = "POST")
+    public function method(?string $method = 'POST')
     {
         $this->method = $method;
+
         return $this;
     }
 

+ 2 - 2
src/Tree.php

@@ -479,12 +479,12 @@ JS;
 
         $quickBtn = $btn = '';
         if ($this->useCreate) {
-            $btn = "<a href='{$url}' class='btn btn-sm btn-success'><i class='feather icon-plus'></i><span class='d-none d-sm-inline'>&nbsp;{$new}</span></a>";
+            $btn = "<a href='{$url}' class='btn btn-sm btn-primary'><i class='feather icon-plus'></i><span class='d-none d-sm-inline'>&nbsp;{$new}</span></a>";
         }
 
         if ($this->useQuickCreate) {
             $text = $this->useCreate ? '<i class=\' fa fa-clone\'></i>' : "<i class='feather icon-plus'></i><span class='d-none d-sm-inline'>&nbsp; $new</span>";
-            $quickBtn = "<button data-url='$url' class='btn btn-sm btn-success tree-quick-create'>$text</button>";
+            $quickBtn = "<button data-url='$url' class='btn btn-sm btn-primary tree-quick-create'>$text</button>";
         }
 
         return "&nbsp;<div class='btn-group pull-right' style='margin-right:3px'>{$btn}{$quickBtn}</div>";