瀏覽代碼

调整Show多列布局代码

jqh 5 年之前
父節點
當前提交
d9b1ce02a0
共有 5 個文件被更改,包括 22 次插入19 次删除
  1. 1 1
      src/Form/Row.php
  2. 1 1
      src/Form/Tab.php
  3. 0 5
      src/Show.php
  4. 1 1
      src/Show/Panel.php
  5. 19 11
      src/Show/Row.php

+ 1 - 1
src/Form/Row.php

@@ -109,7 +109,7 @@ class Row implements Renderable
      *
      * @return array
      */
-    public function getFields()
+    public function fields()
     {
         return $this->fields;
     }

+ 1 - 1
src/Form/Tab.php

@@ -72,7 +72,7 @@ class Tab
         foreach ($this->form->rows() as $row) {
             $rowFields = array_map(function ($field) {
                 return $field['element'];
-            }, $row->getFields());
+            }, $row->fields());
 
             $match = false;
 

+ 0 - 5
src/Show.php

@@ -685,11 +685,6 @@ class Show implements Renderable
 
             $this->fields->each->fill($model);
             $this->relations->each->model($model);
-            $this->rows->each(function ($row) {
-                $row->getFields()->each(function ($field) {
-                    $field['element']->fill($this->model());
-                });
-            });
 
             $this->callComposing();
 

+ 1 - 1
src/Show/Panel.php

@@ -59,7 +59,7 @@ class Panel implements Renderable
         $this->data = [
             'fields' => new Collection(),
             'tools'  => new Tools($this),
-            'rows' => $this->parent->rows(),
+            'rows'   => $this->parent->rows(),
             'style'  => 'default',
             'title'  => trans('admin.detail'),
         ];

+ 19 - 11
src/Show/Row.php

@@ -2,6 +2,7 @@
 
 namespace Dcat\Admin\Show;
 
+use Dcat\Admin\Show\Field;
 use Dcat\Admin\Show;
 use Illuminate\Contracts\Support\Renderable;
 use Illuminate\Support\Collection;
@@ -23,7 +24,7 @@ class Row implements Renderable
     protected $show;
 
     /**
-     * @var \Illuminate\Support\Collection
+     * @var Collection
      */
     protected $fields;
 
@@ -62,9 +63,9 @@ class Row implements Renderable
     }
 
     /**
-     * @return \Illuminate\Support\Collection
+     * @return Collection|Field[]
      */
-    public function getFields()
+    public function fields()
     {
         return $this->fields;
     }
@@ -84,14 +85,17 @@ class Row implements Renderable
     }
 
     /**
-     * @param        $name
+     * Add field.
+     *
+     * @param string $name
      * @param string $label
      *
-     * @return \Dcat\Admin\Show\Field
+     * @return Field
      */
     public function field($name, $label = '')
     {
         $field = $this->show->field($name, $label);
+
         $this->pushField($field);
 
         return $field;
@@ -99,13 +103,15 @@ class Row implements Renderable
 
     /**
      * Add field.
+     *
      * @param $name
      *
-     * @return \Dcat\Admin\Show\Field|\Illuminate\Support\Collection
+     * @return Field|\Illuminate\Support\Collection
      */
     public function __get($name)
     {
-        $field = $this->show->__get($name);
+        $field = $this->show->field($name);
+
         $this->pushField($field);
 
         return $field;
@@ -115,7 +121,7 @@ class Row implements Renderable
      * @param $method
      * @param $arguments
      *
-     * @return \Dcat\Admin\Show\Field
+     * @return Field
      */
     public function __call($method, $arguments)
     {
@@ -127,12 +133,14 @@ class Row implements Renderable
     }
 
     /**
-     * @param $field
+     * @param Field $field
+     *
+     * @return void
      */
-    public function pushField($field)
+    protected function pushField($field)
     {
         $this->fields->push([
-            'width' => $this->defaultFieldWidth,
+            'width'   => $this->defaultFieldWidth,
             'element' => $field,
         ]);
     }