jqh 4 éve
szülő
commit
e6f0e68b0c
2 módosított fájl, 42 hozzáadás és 1 törlés
  1. 7 1
      src/Grid/Actions/Delete.php
  2. 35 0
      src/Grid/Concerns/HasTree.php

+ 7 - 1
src/Grid/Actions/Delete.php

@@ -3,6 +3,7 @@
 namespace Dcat\Admin\Grid\Actions;
 
 use Dcat\Admin\Grid\RowAction;
+use Dcat\Admin\Support\Helper;
 
 class Delete extends RowAction
 {
@@ -24,12 +25,17 @@ class Delete extends RowAction
             'data-url'      => $this->url(),
             'data-message'  => "ID - {$this->getKey()}",
             'data-action'   => 'delete',
-            'data-redirect' => request()->fullUrl(),
+            'data-redirect' => $this->redirectUrl(),
         ]);
 
         return parent::render();
     }
 
+    protected function redirectUrl()
+    {
+        return $this->parent->model()->withoutTreeQuery(request()->fullUrl());
+    }
+
     public function url()
     {
         return "{$this->resource()}/{$this->getKey()}";

+ 35 - 0
src/Grid/Concerns/HasTree.php

@@ -9,6 +9,13 @@ use Dcat\Admin\Repositories\EloquentRepository;
 use Dcat\Admin\Support\Helper;
 use Illuminate\Support\Collection;
 
+/**
+ * Trait HasTree
+ *
+ * @package Dcat\Admin\Grid\Concerns
+ *
+ * @method \Dcat\Admin\Grid grid()
+ */
 trait HasTree
 {
     /**
@@ -224,6 +231,34 @@ HTML
         ) ?: $this->getDefaultParentId();
     }
 
+    /**
+     * 移除树相关参数.
+     *
+     * @param string $url
+     *
+     * @return string
+     */
+    public function withoutTreeQuery($url)
+    {
+        if (! $url) {
+            return $url;
+        }
+
+        parse_str(explode('?', $url)[1] ?? '', $originalQuery);
+
+        $parentId = $originalQuery[$this->getParentIdQueryName()] ?? 0;
+
+        if (! $parentId) {
+            return $url;
+        }
+
+        return Helper::urlWithoutQuery($url, [
+            $this->getParentIdQueryName(),
+            $this->getChildrenPageName($parentId),
+            $this->getDepthQueryName(),
+        ]);
+    }
+
     /**
      * 获取默认parent_id字段值.
      *