jqh há 5 anos atrás
pai
commit
8182639134
3 ficheiros alterados com 21 adições e 8 exclusões
  1. 5 5
      src/Grid/Displayers/Expand.php
  2. 11 3
      src/Grid/Displayers/Modal.php
  3. 5 0
      src/Widgets/Table.php

+ 5 - 5
src/Grid/Displayers/Expand.php

@@ -4,6 +4,7 @@ namespace Dcat\Admin\Grid\Displayers;
 
 use Dcat\Admin\Admin;
 use Illuminate\Contracts\Support\Renderable;
+use Illuminate\Support\Str;
 
 class Expand extends AbstractDisplayer
 {
@@ -12,7 +13,7 @@ class Expand extends AbstractDisplayer
     /**
      * @var array
      */
-    protected static $counter = [];
+    protected static $counter = 0;
 
     public function button($button)
     {
@@ -54,12 +55,11 @@ EOT;
      */
     protected function getDataKey()
     {
-        $key = $this->key();
+        $key = $this->key() ?: Str::random(8);
 
-        static::$counter[$key] = static::$counter[$key] ?? 0;
-        static::$counter[$key]++;
+        static::$counter++;
 
-        return $key.static::$counter[$key];
+        return $this->grid->getName().$key.'-'.static::$counter;
     }
 
     protected function setupScript()

+ 11 - 3
src/Grid/Displayers/Modal.php

@@ -3,6 +3,7 @@
 namespace Dcat\Admin\Grid\Displayers;
 
 use Dcat\Admin\Support\Helper;
+use Illuminate\Support\Str;
 
 class Modal extends AbstractDisplayer
 {
@@ -13,6 +14,13 @@ class Modal extends AbstractDisplayer
         $this->title = $title;
     }
 
+    protected function generateElementId()
+    {
+        $key = $this->key() ?: Str::random(8);
+
+        return 'grid-modal-'.$this->grid->getName().$key;
+    }
+
     public function display($callback = null)
     {
         $title = $this->trans('title');
@@ -28,14 +36,14 @@ class Modal extends AbstractDisplayer
         }
 
         $title = $this->title ?: $title;
-        $key = $this->grid->getName().$this->key();
+        $id = $this->generateElementId();
 
         return <<<EOT
-<span class="grid-expand" data-toggle="modal" data-target="#grid-modal-{$key}">
+<span class="grid-expand" data-toggle="modal" data-target="#{$id}">
    <a href="javascript:void(0)"><i class="fa fa-clone"></i>&nbsp;&nbsp;{$this->value}</a>
 </span>
 
-<div class="modal fade" id="grid-modal-{$key}" tabindex="-1" role="dialog">
+<div class="modal fade" id="{$id}" tabindex="-1" role="dialog">
   <div class="modal-dialog modal-lg" role="document">
     <div class="modal-content">
       <div class="modal-header">

+ 5 - 0
src/Widgets/Table.php

@@ -40,6 +40,11 @@ class Table extends Widget
      */
     public function __construct($headers = [], $rows = [], $style = [])
     {
+        if ($headers && ! $rows) {
+            $rows = $headers;
+            $headers = [];
+        }
+
         $this->setHeaders($headers);
         $this->setRows($rows);
         $this->setStyle($style);