jqh 4 years ago
parent
commit
220fdee434

+ 1 - 5
resources/lang/zh-CN/global.php

@@ -30,11 +30,7 @@ return [
         'root'     => '顶级',
         'scaffold' => '代码生成器',
     ],
-
     'options' => [
-        'permissions' => [
-
-        ],
+        //
     ],
-
 ];

+ 1 - 4
resources/views/filter/selecttable.blade.php

@@ -10,10 +10,7 @@
 
     <input name="{{ $name }}" type="hidden" id="hidden-{{ $id }}" value="{{ implode(',', \Dcat\Admin\Support\Helper::array($value)) }}" />
     <div class="input-group-append">
-        <div class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modal-{{ $id }}">
-            &nbsp;<i class="feather icon-arrow-up"></i>&nbsp;
-        </div>
+        {!! $dialog !!}
     </div>
 
-    {!! $modal !!}
 </div>

+ 1 - 1
src/Controllers/LogController.php

@@ -22,7 +22,7 @@ class LogController extends Controller
     protected function grid()
     {
         return new Grid(new OperationLog(), function (Grid $grid) {
-            $grid->column('id')->sortable();
+            $grid->column('id', 'ID')->sortable();
             $grid->column('user', trans('admin.user'))
                 ->get('name')
                 ->link(function () {

+ 1 - 1
src/Controllers/RoleController.php

@@ -21,7 +21,7 @@ class RoleController extends AdminController
     protected function grid()
     {
         return new Grid(new Role(), function (Grid $grid) {
-            $grid->column('id')->sortable();
+            $grid->column('id', 'ID')->sortable();
             $grid->column('slug')->label('primary');
             $grid->column('name');
 

+ 1 - 1
src/Controllers/UserController.php

@@ -21,7 +21,7 @@ class UserController extends AdminController
     protected function grid()
     {
         return Grid::make(new Administrator('roles'), function (Grid $grid) {
-            $grid->column('id')->sortable();
+            $grid->column('id', 'ID')->sortable();
             $grid->column('username');
             $grid->column('name');
 

+ 20 - 0
src/Form/Field/SelectTable.php

@@ -75,6 +75,26 @@ class SelectTable extends Field
         return $this;
     }
 
+    /**
+     * 设置选中数据显示.
+     *
+     * @param string $model
+     * @param string $id
+     * @param string $text
+     *
+     * @return $this
+     */
+    public function model(string $model, string $id = 'id', string $text = 'title')
+    {
+        return $this->options(function ($v) use ($model, $id, $text) {
+            if (! $v) {
+                return [];
+            }
+
+            return $model::find($v)->pluck($text, $id);
+        });
+    }
+
     /**
      * 转化为数组格式保存.
      *

+ 2 - 2
src/Grid/Filter/AbstractFilter.php

@@ -332,7 +332,7 @@ abstract class AbstractFilter
     /**
      * @param LazyRenderable $table
      *
-     * @return mixed
+     * @return Filter\Presenter\SelectTable
      */
     public function selectTable(LazyRenderable $table)
     {
@@ -342,7 +342,7 @@ abstract class AbstractFilter
     /**
      * @param LazyRenderable $table
      *
-     * @return mixed
+     * @return Filter\Presenter\MultipleSelectTable
      */
     public function multipleSelectTable(LazyRenderable $table)
     {

+ 8 - 7
src/Grid/Filter/Presenter/MultipleSelectTable.php

@@ -35,13 +35,14 @@ class MultipleSelectTable extends SelectTable
     {
         Admin::script(
             <<<JS
-Dcat.grid.SelectTable({
-    modal: replaceNestedFormIndex('#{$this->modal->id()}'),
-    container: replaceNestedFormIndex('#{$this->id}'),
-    input: replaceNestedFormIndex('#hidden-{$this->id}'),
-    button: replaceNestedFormIndex('#{$this->getButtonId()}'),
-    multiple: true,
-    max: {$this->max},
+{$this->dialog->getScript()}
+
+Dcat.grid.SelectTable({
+    dialog: '#{$this->dialog->id()}',
+    container: '#{$this->id}',
+    input: '#hidden-{$this->id}',
+    multiple: true,
+    max: {$this->max},
     values: {$this->options},
 });
 JS

+ 63 - 35
src/Grid/Filter/Presenter/SelectTable.php

@@ -5,7 +5,7 @@ namespace Dcat\Admin\Grid\Filter\Presenter;
 use Dcat\Admin\Admin;
 use Dcat\Admin\Grid\LazyRenderable;
 use Dcat\Admin\Support\Helper;
-use Dcat\Admin\Widgets\TableModal;
+use Dcat\Admin\Widgets\DialogTable;
 use Illuminate\Support\Str;
 
 class SelectTable extends Presenter
@@ -15,9 +15,11 @@ class SelectTable extends Presenter
     ];
 
     /**
-     * @var TableModal
+     * @var DialogTable
      */
-    protected $modal;
+    protected $dialog;
+
+    protected $style = 'primary';
 
     protected $title;
 
@@ -29,7 +31,7 @@ class SelectTable extends Presenter
 
     public function __construct(LazyRenderable $table)
     {
-        $this->modal = TableModal::make($table);
+        $this->dialog = DialogTable::make($table);
         $this->id = 'select-table-filter-'.Str::random(8);
     }
 
@@ -48,13 +50,39 @@ class SelectTable extends Presenter
     }
 
     /**
-     * 设置尺寸为 xl.
+     * 设置选中数据显示.
+     *
+     * @param string $model
+     * @param string $id
+     * @param string $text
      *
      * @return $this
      */
-    public function xl()
+    public function model(string $model, string $id = 'id', string $text = 'title')
     {
-        $this->modal->xl();
+        return $this->options(function ($v) use ($model, $id, $text) {
+            if (! $v) {
+                return [];
+            }
+
+            return $model::find($v)->pluck($text, $id);
+        });
+    }
+
+    /**
+     * 设置弹窗宽度.
+     *
+     * @example
+     *    $this->width('500px');
+     *    $this->width('50%');
+     *
+     * @param string $width
+     *
+     * @return $this
+     */
+    public function dialogWidth(string $width)
+    {
+        $this->dialog->width($width);
 
         return $this;
     }
@@ -89,16 +117,13 @@ class SelectTable extends Presenter
         return $this;
     }
 
-    protected function setUpModal()
+    protected function setUpTable()
     {
-        $table = $this->modal->getTable();
-
-        $table->id('table-card-'.$this->id);
-
-        $this->modal
-            ->id('modal-'.$this->id)
-            ->title($this->title ?: $this->filter->getLabel())
-            ->footer($this->renderFooter());
+        $this->dialog
+            ->id('dialog-'.$this->id)
+            ->runScript(false)
+            ->footer($this->renderFooter())
+            ->button($this->renderButton());
     }
 
     protected function formatOptions()
@@ -126,11 +151,12 @@ class SelectTable extends Presenter
     {
         Admin::script(
             <<<JS
-Dcat.grid.SelectTable({
-    modal: replaceNestedFormIndex('#{$this->modal->id()}'),
-    container: replaceNestedFormIndex('#{$this->id}'),
-    input: replaceNestedFormIndex('#hidden-{$this->id}'),
-    button: replaceNestedFormIndex('#{$this->getButtonId()}'),
+{$this->dialog->getScript()}
+
+Dcat.grid.SelectTable({
+    dialog: '#{$this->dialog->id()}',
+    container: '#{$this->id}',
+    input: '#hidden-{$this->id}',
     values: {$this->options},
 });
 JS
@@ -143,16 +169,28 @@ JS
     public function variables(): array
     {
         $this->formatOptions();
-        $this->setUpModal();
+        $this->setUpTable();
+
+        $dialog = $this->dialog->render();
+
         $this->addScript();
 
         return [
             'id'          => $this->id,
-            'modal'       => $this->modal,
+            'dialog'      => $dialog,
             'placeholder' => $this->placeholder(),
         ];
     }
 
+    protected function renderButton()
+    {
+        return <<<HTML
+<div class="btn btn-{$this->style} btn-sm">
+    &nbsp;<i class="feather icon-arrow-up"></i>&nbsp;
+</div>
+HTML;
+    }
+
     /**
      * 弹窗底部内容构建.
      *
@@ -164,18 +202,8 @@ JS
         $cancel = trans('admin.cancel');
 
         return <<<HTML
-<a id="{$this->getButtonId()}" class="btn btn-primary" style="color: #fff">&nbsp;{$submit}&nbsp;</a>&nbsp;
-<a onclick="$(this).parents('.modal').modal('toggle')" class="btn btn-white">&nbsp;{$cancel}&nbsp;</a>
+<button class="btn btn-primary btn-sm submit-btn" style="color: #fff">&nbsp;{$submit}&nbsp;</button>&nbsp;
+<button class="btn btn-white btn-sm cancel-btn">&nbsp;{$cancel}&nbsp;</button>
 HTML;
     }
-
-    /**
-     * 提交按钮ID.
-     *
-     * @return string
-     */
-    public function getButtonId()
-    {
-        return 'submit-'.$this->id;
-    }
 }

+ 2 - 0
src/Grid/LazyRenderable.php

@@ -58,6 +58,8 @@ abstract class LazyRenderable extends Renderable
             $grid->disableBatchDelete();
             $grid->disableRefreshButton();
 
+            $grid->toolsWithOutline(false);
+
             $grid->filter()
                 ->panel()
                 ->view('admin::filter.tile-container');