Kaynağa Gözat

增加表单提交弹出确认弹窗功能

jqh 5 yıl önce
ebeveyn
işleme
80ed9be0c5

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

@@ -14,6 +14,8 @@ class Form {
             form: null,
             // 开启表单验证
             validate: false,
+            // 确认弹窗
+            confirm: {title: null, content: null},
             // 表单错误信息class
             errorClass: 'has-error',
             // 表单错误信息容器选择器
@@ -48,6 +50,19 @@ class Form {
     }
 
     submit() {
+        let _this = this;
+        let confirm = _this.options.confirm;
+
+        if (! confirm.title) {
+            return _this._ajaxSubmit();
+        }
+
+        Dcat.confirm(confirm.title, confirm.content, function () {
+            _this._ajaxSubmit();
+        });
+    }
+
+    _ajaxSubmit() {
         let Dcat = window.Dcat,
             _this = this,
             $form = _this.$form,

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
resources/dist/adminlte/adminlte.js.map


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
resources/dist/dcat/extra/action.js.map


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
resources/dist/dcat/extra/resource-selector.js.map


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
resources/dist/dcat/js/dcat-app.js


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
resources/dist/dcat/js/dcat-app.js.map


+ 13 - 0
src/Form.php

@@ -346,6 +346,19 @@ class Form implements Renderable
         return $this;
     }
 
+    /**
+     * @param string $title
+     * @param string $content
+     *
+     * @return $this
+     */
+    public function confirm(?string $title = null, ?string $content = null)
+    {
+        $this->builder->confirm($title, $content);
+
+        return $this;
+    }
+
     /**
      * @return bool
      */

+ 22 - 0
src/Form/Builder.php

@@ -150,6 +150,11 @@ class Builder
      */
     protected $stepBuilder;
 
+    /**
+     * @var array
+     */
+    protected $confirm = [];
+
     /**
      * Builder constructor.
      *
@@ -276,6 +281,20 @@ class Builder
         return $this->stepBuilder;
     }
 
+    /**
+     * @param string $title
+     * @param string $content
+     *
+     * @return $this
+     */
+    public function confirm(?string $title = null, ?string $content = null)
+    {
+        $this->confirm['title'] = $title;
+        $this->confirm['content'] = $content;
+
+        return $this;
+    }
+
     /**
      * Set the builder mode.
      *
@@ -878,10 +897,13 @@ EOF;
      */
     protected function addSubmitScript()
     {
+        $confirm = json_encode($this->confirm);
+
         Admin::script(
             <<<JS
 $('#{$this->getElementId()}').form({
     validate: true,
+     confirm: {$confirm},
 });
 JS
         );

+ 23 - 1
src/Widgets/Form.php

@@ -153,6 +153,11 @@ class Form implements Renderable
         'field' => 8,
     ];
 
+    /**
+     * @var array
+     */
+    protected $confirm = [];
+
     /**
      * Form constructor.
      *
@@ -216,11 +221,25 @@ class Form implements Renderable
      *
      * @return $this
      */
-    public function method($method = 'POST')
+    public function method(string $method = 'POST')
     {
         return $this->setHtmlAttribute('method', strtoupper($method));
     }
 
+    /**
+     * @param string $title
+     * @param string $content
+     *
+     * @return $this
+     */
+    public function confirm(?string $title = null, ?string $content = null)
+    {
+        $this->confirm['title'] = $title;
+        $this->confirm['content'] = $content;
+
+        return $this;
+    }
+
     /**
      * Set primary key.
      *
@@ -659,10 +678,13 @@ HTML;
      */
     protected function setUpSubmitScript()
     {
+        $confirm = json_encode($this->confirm);
+
         Admin::script(
             <<<JS
 $('#{$this->getElementId()}').form({
     validate: true,
+    confirm: {$confirm},
     success: function (data) {
         {$this->buildSuccessScript()}
         {$this->addSavedScript()}

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor