浏览代码

修复rwd-table无法支持多表格bug

jqh 5 年之前
父节点
当前提交
2cb08bf031

+ 2 - 2
resources/assets/RWD-Table-Patterns/dist/js/rwd-table.js

@@ -18,7 +18,7 @@
         this.options = options;
         this.$tableWrapper = null; //defined later in wrapTable
         this.$tableScrollWrapper = $(element); //defined later in wrapTable
-        this.$table = $(element).find('table');
+        this.$table = $(element).find('table').first();
 
         if(this.$table.length !== 1) {
             throw new Error('Exactly one table is expected in a .table-responsive div.');
@@ -36,7 +36,7 @@
         this.$stickyTableHeader = null; //defined farther down
 
         //good to have - for easy access
-        this.$thead = this.$table.find('thead');
+        this.$thead = this.$table.find('thead').first();
         this.$hdrCells = this.$thead.find("tr").first().find('th');
         this.$bodyRows = this.$table.find('tbody, tfoot').find('tr');
 

文件差异内容过多而无法显示
+ 0 - 0
resources/assets/RWD-Table-Patterns/dist/js/rwd-table.min.js


+ 19 - 26
src/Traits/ModelTree.php

@@ -9,6 +9,11 @@ use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Request;
 
+/**
+ * @property string $parentColumn
+ * @property string $titleColumn
+ * @property string $orderColumn
+ */
 trait ModelTree
 {
     /**
@@ -16,21 +21,6 @@ trait ModelTree
      */
     protected static $branchOrder = [];
 
-    /**
-     * @var string
-     */
-    protected $parentColumn = 'parent_id';
-
-    /**
-     * @var string
-     */
-    protected $titleColumn = 'title';
-
-    /**
-     * @var string
-     */
-    protected $orderColumn = 'order';
-
     /**
      * @var \Closure
      */
@@ -43,7 +33,7 @@ trait ModelTree
      */
     public function children()
     {
-        return $this->hasMany(static::class, $this->parentColumn);
+        return $this->hasMany(static::class, $this->getParentColumn());
     }
 
     /**
@@ -53,7 +43,7 @@ trait ModelTree
      */
     public function parent()
     {
-        return $this->belongsTo(static::class, $this->parentColumn);
+        return $this->belongsTo(static::class, $this->getParentColumn());
     }
 
     /**
@@ -61,7 +51,7 @@ trait ModelTree
      */
     public function getParentColumn()
     {
-        return $this->parentColumn;
+        return empty($this->parentColumn) ? 'parent_id' : $this->parentColumn;
     }
 
     /**
@@ -81,7 +71,7 @@ trait ModelTree
      */
     public function getTitleColumn()
     {
-        return $this->titleColumn;
+        return empty($this->titleColumn) ? 'title' : $this->titleColumn;
     }
 
     /**
@@ -101,7 +91,7 @@ trait ModelTree
      */
     public function getOrderColumn()
     {
-        return $this->orderColumn;
+        return empty($this->orderColumn) ? 'order' : $this->orderColumn;
     }
 
     /**
@@ -143,7 +133,7 @@ trait ModelTree
             $nodes,
             0,
             $this->getKeyName(),
-            $this->parentColumn
+            $this->getParentColumn()
         );
     }
 
@@ -154,7 +144,7 @@ trait ModelTree
      */
     public function allNodes()
     {
-        $orderColumn = DB::getQueryGrammar()->wrap($this->orderColumn);
+        $orderColumn = DB::getQueryGrammar()->wrap($this->getOrderColumn());
         $byOrder = 'ROOT ASC, '.$orderColumn;
 
         $self = new static();
@@ -246,12 +236,15 @@ trait ModelTree
             $nodes = $this->allNodes();
         }
 
+        $titleColumn = $this->getTitleColumn();
+        $parentColumn = $this->getParentColumn();
+
         foreach ($nodes as $node) {
-            $node[$this->titleColumn] = $prefix.' '.$node[$this->titleColumn];
-            if ($node[$this->parentColumn] == $parentId) {
+            $node[$titleColumn] = $prefix.' '.$node[$titleColumn];
+            if ($node[$parentColumn] == $parentId) {
                 $children = $this->buildSelectOptions($nodes, $node[$this->getKeyName()], $prefix.$prefix);
 
-                $options[$node[$this->getKeyName()]] = $node[$this->titleColumn];
+                $options[$node[$this->getKeyName()]] = $node[$titleColumn];
 
                 if ($children) {
                     $options += $children;
@@ -267,7 +260,7 @@ trait ModelTree
      */
     public function delete()
     {
-        $this->where($this->parentColumn, $this->getKey())->delete();
+        $this->where($this->getParentColumn(), $this->getKey())->delete();
 
         return parent::delete();
     }

部分文件因为文件数量过多而无法显示