浏览代码

表单增加location刷新整体页面方法

jqh 4 年之前
父节点
当前提交
3abba55ebc

+ 10 - 0
resources/assets/dcat/js/extensions/Form.js

@@ -102,6 +102,16 @@ class Form {
 
                 Dcat.success(response.message || 'Save succeeded!');
 
+                if (typeof response.location !== "undefined") {
+                    return setTimeout(function () {
+                        if (response.location) {
+                            location.href = response.location;
+                        } else {
+                            location.reload();
+                        }
+                    }, 1500)
+                }
+
                 if (response.redirect === false || ! options.redirect) {
                     return;
                 }

文件差异内容过多而无法显示
+ 0 - 0
resources/dist/adminlte/adminlte.js.map


文件差异内容过多而无法显示
+ 0 - 0
resources/dist/dcat/extra/action.js.map


文件差异内容过多而无法显示
+ 0 - 0
resources/dist/dcat/extra/resource-selector.js.map


文件差异内容过多而无法显示
+ 0 - 0
resources/dist/dcat/js/dcat-app.js


文件差异内容过多而无法显示
+ 0 - 0
resources/dist/dcat/js/dcat-app.js.map


+ 1 - 1
src/Admin.php

@@ -36,7 +36,7 @@ class Admin
      *
      * @var string
      */
-    const VERSION = '1.5.5';
+    const VERSION = '1.6.0';
 
     /**
      * @var array

+ 10 - 0
src/Form/Field.php

@@ -737,6 +737,16 @@ class Field implements Renderable
         return array_key_exists($key, $this->attributes);
     }
 
+    /**
+     * @param string $key
+     *
+     * @return mixed|null
+     */
+    public function getAttribute(string $key)
+    {
+        return $this->attributes[$key] ?? null;
+    }
+
     /**
      * Specifies a regular expression against which to validate the value of the input.
      *

+ 29 - 3
src/Traits/HasFormResponse.php

@@ -31,6 +31,32 @@ trait HasFormResponse
         return false;
     }
 
+    /**
+     * Send a location redirect response.
+     *
+     * @param string|null $message
+     * @param string|null $url
+     * @param bool        $status
+     *
+     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+     */
+    public function location(?string $message, ?string $url = null, bool $status = true)
+    {
+        if ($this->isAjaxRequest()) {
+            return response()->json([
+                'status'   => $status,
+                'message'  => $message,
+                'location' => $url ? admin_url($url) : false,
+            ]);
+        }
+
+        if ($message) {
+            admin_toastr($message, $status ? 'success' : 'error');
+        }
+
+        return $url ? redirect(admin_url($url)) : redirect()->refresh();
+    }
+
     /**
      * @param Request $request
      *
@@ -132,13 +158,13 @@ trait HasFormResponse
             return $this->ajaxResponse($message, $url, $status);
         }
 
-        $status = (int) ($options['status_code'] ?? 302);
+        $statusCode = (int) ($options['status_code'] ?? 302);
 
         if ($message) {
-            admin_toastr($message);
+            admin_toastr($message, $status ? 'success' : 'error');
         }
 
-        return redirect(admin_url($url), $status);
+        return $url ? redirect(admin_url($url), $statusCode) : redirect()->back($statusCode);
     }
 
     /**

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