浏览代码

表单弹窗

update
jqh 5 年之前
父节点
当前提交
9e919753c8

+ 18 - 19
resources/assets/dcat/js/extensions/DialogForm.js

@@ -54,12 +54,12 @@ export default class DialogForm {
         (! options.buttonSelector) || $(options.buttonSelector).off('click').click(function () {
             $btn = $(this);
 
-            let num = $btn.attr('counter'), url;
+            let counter = $btn.attr('counter'), url;
 
-            if (! num) {
-                num = _this._counter;
+            if (! counter) {
+                counter = _this._counter;
 
-                $btn.attr('counter', num);
+                $btn.attr('counter', counter);
 
                 _this._counter++;
             }
@@ -72,7 +72,7 @@ export default class DialogForm {
                 url += '&' + options.query + '=1'
             }
 
-            _this._build($btn, url, num);
+            _this._build($btn, url, counter);
         });
 
         options.buttonSelector || setTimeout(function () {
@@ -100,7 +100,7 @@ export default class DialogForm {
 
         // 刷新或跳转页面时移除弹窗
         Dcat.onPjaxComplete(() => {
-            _this._destory(counter);
+            _this._destroy(counter);
         });
 
         _this.isLoading = 1;
@@ -118,11 +118,11 @@ export default class DialogForm {
                 }, 50);
             }
 
-            _this._popup(tpl, counter);
+            _this._popup($btn, tpl, counter);
         });
     }
 
-    _popup(tpl, counter) {
+    _popup($btn, tpl, counter) {
         let _this = this,
             options = _this.options;
 
@@ -142,7 +142,7 @@ export default class DialogForm {
                 content: tpl,
                 title: options.title,
                 yes: function () {
-                    _this._submit($template)
+                    _this._submit($btn, $template)
                 },
                 cancel: function () {
                     if (options.forceRefresh) { // 是否强制刷新
@@ -158,8 +158,6 @@ export default class DialogForm {
             btns.push(options.lang.reset);
 
             dialogOpts.btn2 = function () { // 重置按钮
-                _this.$form = _this.$form || $template.find('form').first();
-
                 _this.$form.trigger('reset');
                 
                 return false;
@@ -170,9 +168,10 @@ export default class DialogForm {
 
         _this._idx[counter] = _this._dialog.open(dialogOpts);
         _this._dialogs[counter] = w.$('#layui-layer' + _this._idx[counter]);
+        _this.$form = _this._dialogs[counter].find('form').first();
     }
 
-    _destory(counter) {
+    _destroy(counter) {
         let dialogs = this._dialogs;
 
         this._dialog.close(this._idx[counter]);
@@ -182,15 +181,15 @@ export default class DialogForm {
         dialogs[counter] = null;
     }
 
-    _submit($template) {
-        let _this = this, options = _this.options;
+    _submit($btn) {
+        let _this = this, 
+            options = _this.options,
+            counter = $btn.attr('counter');
 
         if (_this.isSubmitting) {
             return;
         }
 
-        _this.$form = _this.$form || $template.find('form').first();  // 此处必须重新创建jq对象,否则无法操作页面元素
-
         Dcat.Form({
             form: _this.$form,
             disableRedirect: true,
@@ -203,10 +202,10 @@ export default class DialogForm {
 
                 _this.isSubmitting = 1;
 
-                _this._dialogs[num].find('.layui-layer-btn0').button('loading');
+                Dcat.NP.start();
             },
             after: function (success, res) {
-                _this._dialogs[num].find('.layui-layer-btn0').button('reset');
+                Dcat.NP.done();
 
                 _this.isSubmitting = 0;
 
@@ -218,7 +217,7 @@ export default class DialogForm {
                 if (res.status) {
                     options.success(success, res);
 
-                    _this._destory(num);
+                    _this._destroy(counter);
 
                     return;
                 }

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

@@ -48,6 +48,8 @@ class Form {
 
         $form.ajaxSubmit({
             beforeSubmit: function (fields, $form, _opt) {
+                console.log(6666, fields);
+
                 if (options.before(fields, $form, _opt, _this) === false) {
                     return false;
                 }

+ 1 - 1
resources/assets/dcat/js/extensions/Loading.js

@@ -35,7 +35,7 @@ class Loading {
         content.appendTo(_this.$container);
     }
 
-    destory() {
+    destroy() {
         this.$container.find(loading).remove();
     }
 }

+ 2 - 2
resources/assets/dcat/js/extensions/Slider.js

@@ -31,7 +31,7 @@ export default class Slider {
         if (_this.options.autoDestory) {
             // 刷新或跳转页面时移除面板
             Dcat.onPjaxComplete(() => {
-                _this.destory();
+                _this.destroy();
             });
         }
     }
@@ -48,7 +48,7 @@ export default class Slider {
         this.$container.toggleClass('open');
     }
 
-    destory() {
+    destroy() {
         this.$container.remove()
     }
 }

+ 25 - 27
resources/dist/dcat/js/dcat-app.js

@@ -1305,12 +1305,12 @@ var DialogForm = /*#__PURE__*/function () {
 
       !options.buttonSelector || $(options.buttonSelector).off('click').click(function () {
         $btn = $(this);
-        var num = $btn.attr('counter'),
+        var counter = $btn.attr('counter'),
             url;
 
-        if (!num) {
-          num = _this._counter;
-          $btn.attr('counter', num);
+        if (!counter) {
+          counter = _this._counter;
+          $btn.attr('counter', counter);
           _this._counter++;
         }
 
@@ -1322,7 +1322,7 @@ var DialogForm = /*#__PURE__*/function () {
           url += '&' + options.query + '=1';
         }
 
-        _this._build($btn, url, num);
+        _this._build($btn, url, counter);
       });
       options.buttonSelector || setTimeout(function () {
         _this._build($btn, defUrl, _this._counter);
@@ -1350,7 +1350,7 @@ var DialogForm = /*#__PURE__*/function () {
 
 
       Dcat.onPjaxComplete(function () {
-        _this._destory(counter);
+        _this._destroy(counter);
       });
       _this.isLoading = 1;
       $btn && $btn.button('loading');
@@ -1364,12 +1364,12 @@ var DialogForm = /*#__PURE__*/function () {
           }, 50);
         }
 
-        _this._popup(tpl, counter);
+        _this._popup($btn, tpl, counter);
       });
     }
   }, {
     key: "_popup",
-    value: function _popup(tpl, counter) {
+    value: function _popup($btn, tpl, counter) {
       var _this = this,
           options = _this.options;
 
@@ -1388,7 +1388,7 @@ var DialogForm = /*#__PURE__*/function () {
         content: tpl,
         title: options.title,
         yes: function yes() {
-          _this._submit($template);
+          _this._submit($btn, $template);
         },
         cancel: function cancel() {
           if (options.forceRefresh) {
@@ -1407,8 +1407,6 @@ var DialogForm = /*#__PURE__*/function () {
 
         dialogOpts.btn2 = function () {
           // 重置按钮
-          _this.$form = _this.$form || $template.find('form').first();
-
           _this.$form.trigger('reset');
 
           return false;
@@ -1418,10 +1416,11 @@ var DialogForm = /*#__PURE__*/function () {
       dialogOpts.btn = btns;
       _this._idx[counter] = _this._dialog.open(dialogOpts);
       _this._dialogs[counter] = w.$('#layui-layer' + _this._idx[counter]);
+      _this.$form = _this._dialogs[counter].find('form').first();
     }
   }, {
-    key: "_destory",
-    value: function _destory(counter) {
+    key: "_destroy",
+    value: function _destroy(counter) {
       var dialogs = this._dialogs;
 
       this._dialog.close(this._idx[counter]);
@@ -1431,16 +1430,15 @@ var DialogForm = /*#__PURE__*/function () {
     }
   }, {
     key: "_submit",
-    value: function _submit($template) {
+    value: function _submit($btn) {
       var _this = this,
-          options = _this.options;
+          options = _this.options,
+          counter = $btn.attr('counter');
 
       if (_this.isSubmitting) {
         return;
       }
 
-      _this.$form = _this.$form || $template.find('form').first(); // 此处必须重新创建jq对象,否则无法操作页面元素
-
       Dcat.Form({
         form: _this.$form,
         disableRedirect: true,
@@ -1452,12 +1450,10 @@ var DialogForm = /*#__PURE__*/function () {
           }
 
           _this.isSubmitting = 1;
-
-          _this._dialogs[num].find('.layui-layer-btn0').button('loading');
+          Dcat.NP.start();
         },
         after: function after(success, res) {
-          _this._dialogs[num].find('.layui-layer-btn0').button('reset');
-
+          Dcat.NP.done();
           _this.isSubmitting = 0;
           options.saved(success, res);
 
@@ -1468,7 +1464,7 @@ var DialogForm = /*#__PURE__*/function () {
           if (res.status) {
             options.success(success, res);
 
-            _this._destory(num);
+            _this._destroy(counter);
 
             return;
           }
@@ -1557,6 +1553,8 @@ var Form = /*#__PURE__*/function () {
       removeFieldError(_this);
       $form.ajaxSubmit({
         beforeSubmit: function beforeSubmit(fields, $form, _opt) {
+          console.log(6666, fields);
+
           if (options.before(fields, $form, _opt, _this) === false) {
             return false;
           }
@@ -2242,8 +2240,8 @@ var Loading = /*#__PURE__*/function () {
   }
 
   _createClass(Loading, [{
-    key: "destory",
-    value: function destory() {
+    key: "destroy",
+    value: function destroy() {
       this.$container.find(loading).remove();
     }
   }]);
@@ -2496,7 +2494,7 @@ var Slider = /*#__PURE__*/function () {
     if (_this.options.autoDestory) {
       // 刷新或跳转页面时移除面板
       Dcat.onPjaxComplete(function () {
-        _this.destory();
+        _this.destroy();
       });
     }
   }
@@ -2517,8 +2515,8 @@ var Slider = /*#__PURE__*/function () {
       this.$container.toggleClass('open');
     }
   }, {
-    key: "destory",
-    value: function destory() {
+    key: "destroy",
+    value: function destroy() {
       this.$container.remove();
     }
   }]);

+ 8 - 1
resources/views/layouts/form-content.blade.php

@@ -1,8 +1,15 @@
 <script>Dcat.pjaxResponded();</script>
 
+<style>
+    .form-content .row {
+        margin-right: 0;
+        margin-left: 0;
+    }
+</style>
+
 {{--必须在静态资源加载前,用section先渲染 content--}}
 @section('content')
-    <section class="content">{!! $content !!}</section>
+    <section class="form-content">{!! $content !!}</section>
 @endsection
 
 {!! Dcat\Admin\Admin::assets()->renderCss() !!}