jqh 4 年之前
父节点
当前提交
92e88eb97d
共有 2 个文件被更改,包括 91 次插入64 次删除
  1. 66 52
      src/Grid/Concerns/CanFixColumns.php
  2. 25 12
      src/Grid/FixColumns.php

+ 66 - 52
src/Grid/Concerns/CanFixColumns.php

@@ -1,52 +1,66 @@
-<?php
-
-namespace Dcat\Admin\Grid\Concerns;
-
-use Dcat\Admin\Grid\FixColumns;
-use Illuminate\Support\Collection;
-
-trait CanFixColumns
-{
-    /**
-     * @var FixColumns
-     */
-    protected $fixColumns;
-
-    /**
-     * @param int $head
-     * @param int $tail
-     *
-     * @return $this
-     */
-    public function fixColumns(int $head, int $tail = -1)
-    {
-        $this->fixColumns = new FixColumns($this, $head, $tail);
-
-        return $this;
-    }
-
-    protected function applyFixColumns()
-    {
-        if ($this->fixColumns) {
-            $this->withBorder();
-
-            $this->fixColumns->apply();
-        }
-    }
-
-    /**
-     * @return Collection
-     */
-    public function leftVisibleColumns()
-    {
-        return $this->fixColumns->leftColumns();
-    }
-
-    /**
-     * @return Collection
-     */
-    public function rightVisibleColumns()
-    {
-        return $this->fixColumns->rightColumns();
-    }
-}
+<?php
+
+namespace Dcat\Admin\Grid\Concerns;
+
+use Dcat\Admin\Grid\Displayers\Actions;
+use Dcat\Admin\Grid\Displayers\ContextMenuActions;
+use Dcat\Admin\Grid\Displayers\DropdownActions;
+use Dcat\Admin\Grid\FixColumns;
+use Illuminate\Support\Collection;
+
+trait CanFixColumns
+{
+    /**
+     * @var FixColumns
+     */
+    protected $fixColumns;
+
+    /**
+     * @param int $head
+     * @param int $tail
+     *
+     * @return $this
+     */
+    public function fixColumns(int $head, int $tail = -1)
+    {
+        $this->fixColumns = new FixColumns($this, $head, $tail);
+
+        $this->resetActions();
+
+        return $this;
+    }
+
+    protected function resetActions()
+    {
+        $actions = $this->actionsClass ?: config('admin.grid.grid_action_class');
+
+        if ($actions === DropdownActions::class) {
+            $this->setActionClass(Actions::class);
+        }
+    }
+
+    protected function applyFixColumns()
+    {
+        if ($this->fixColumns) {
+            $this->withBorder();
+
+            $this->fixColumns->apply();
+        }
+    }
+
+    /**
+     * @return Collection
+     */
+    public function leftVisibleColumns()
+    {
+        return $this->fixColumns->leftColumns();
+    }
+
+    /**
+     * @return Collection
+     */
+    public function rightVisibleColumns()
+    {
+        return $this->fixColumns->rightColumns();
+    }
+}

+ 25 - 12
src/Grid/FixColumns.php

@@ -16,12 +16,12 @@ class FixColumns
     /**
      * @var int
      */
-    protected $head;
+    public $head;
 
     /**
      * @var int
      */
-    protected $tail;
+    public $tail;
 
     /**
      * @var Collection
@@ -95,11 +95,6 @@ class FixColumns
      */
     protected function addScript()
     {
-        $allName = $this->grid->getSelectAllName();
-        //$rowName = $this->grid->getGridRowName();
-
-        $selected = trans('admin.grid_items_selected');
-
         $script = <<<JS
 
 (function () {
@@ -118,6 +113,18 @@ class FixColumns
     
     if ($('.table-main').width() >= $('.table-main').prop('scrollWidth')) {
         $('.table-fixed').hide();
+    } else {
+        var height = ($(window).height() - 200);
+        
+        $('.table-main,.table-fixed').css({height: height + 'px'});
+        $('.table-fixed-right').css({right: '15px'});
+        $('.table-fixed-right,.table-fixed-left').css({height: (height - 16) + 'px'});
+        
+        $('.table-main').scroll(function () {
+            var self = $(this); 
+            
+            self.parents('.tables-container').find('.table-fixed-right,.table-fixed-left').scrollTop(self.scrollTop());
+        });
     }
     
     $('.table-wrap tbody tr').on('mouseover', function () {
@@ -151,6 +158,7 @@ JS;
         $style = <<<'CSS'
 .tables-container {
     position:relative;
+    margin-top: 12px;
 }
 
 .tables-container table {
@@ -166,7 +174,7 @@ JS;
 }
 
 .table-main {
-    overflow-x: auto;
+    overflow: auto;
     width: 100%;
 }
 
@@ -174,6 +182,7 @@ JS;
     position:absolute;
 	top: 0;
 	z-index:10;
+	overflow: hidden;
 }
 
 .table-fixed th {
@@ -188,12 +197,16 @@ JS;
 	right:0;
 }
 
-.table-fixed-left table {
- box-shadow: 5px 0 5px -5px rgba(0,0,0,.1);
+.table-fixed-left {
+    box-shadow: 5px 0 5px -5px rgba(0,0,0,.1);
+}
+
+.table-fixed-right {
+    box-shadow: -5px 0 5px -5px rgba(0,0,0,.1);
 }
 
-.table-fixed-right table {
- box-shadow: -5px 0 5px -5px rgba(0,0,0,.1);
+.tables-container .table.table-bordered.dataTable.complex-headers {
+    margin-top: 0!important;
 }
 CSS;