xaboy 7 年 前
コミット
2a2438ce93
2 ファイル変更56 行追加58 行削除
  1. 1 1
      src/Form.php
  2. 55 57
      src/view/formScript.php

+ 1 - 1
src/Form.php

@@ -135,7 +135,7 @@ class Form
      * @param string $action 提交地址
      * @param array $components 组件
      */
-    public function __construct($action, array $components = [])
+    public function __construct($action = '', array $components = [])
     {
         $this->components($components);
         $this->action = $action;

+ 55 - 57
src/view/formScript.php

@@ -2,67 +2,65 @@
     var getRule = function () {
         var rule = <?=json_encode($rule)?>;
         rule.forEach(function (c) {
-            if((c.type == 'cascader' || c.type == 'tree') && Object.prototype.toString.call(c.props.data) == '[object String]'){
-				if(c.props.data.indexOf('js.') === 0){
-					c.props.data = window[c.props.data.replace('js.','')];
-				}
+            if ((c.type == 'cascader' || c.type == 'tree') && Object.prototype.toString.call(c.props.data) == '[object String]') {
+                if (c.props.data.indexOf('js.') === 0) {
+                    c.props.data = window[c.props.data.replace('js.', '')];
+                }
             }
         });
         return rule;
-    },vm = new Vue;
-    return function create(el,callback) {
-        var formData = {};
-        if(!el) el = document.body;
-        $f = formCreate.create(getRule(),{
-                el:el,
-                form:<?=json_encode($form->getConfig('form'))?>,
-				row:<?=json_encode($form->getConfig('row'))?>,
-        upload:{
-            onExceededSize:function (file) {
-                vm.$Message.error(file.name + '超出指定大小限制');
-            },
-            onFormatError:function () {
-                vm.$Message.error(file.name + '格式验证失败');
-            },
-            onError:function (error) {
-                vm.$Message.error(file.name + '上传失败,('+ error +')');
-            },
-            onSuccess:function (res) {
-                if(res.code == 200){
-                    return res.data.filePath;
-                }else{
-                    vm.$Message.error(res.msg);
+    }, vm = new Vue;
+    return function create(el, callback) {
+        if (!el) el = document.body;
+        return formCreate.create(getRule(), {
+            el: el,
+            form:<?=json_encode($form->getConfig('form'))?>,
+            row:<?=json_encode($form->getConfig('row'))?>,
+            upload: {
+                onExceededSize: function (file) {
+                    vm.$Message.error(file.name + '超出指定大小限制');
+                },
+                onFormatError: function () {
+                    vm.$Message.error(file.name + '格式验证失败');
+                },
+                onError: function (error) {
+                    vm.$Message.error(file.name + '上传失败,(' + error + ')');
+                },
+                onSuccess: function (res) {
+                    if (res.code == 200) {
+                        return res.data.filePath;
+                    } else {
+                        vm.$Message.error(res.msg);
+                    }
                 }
-            }
-        },
-        //表单提交事件
-        onSubmit: function (formData) {
-            $f.submitStatus({loading: true});
-            $.ajax({
-                url:'<?=$form->getAction()?>',
-                type:'<?=$form->getMethod()?>',
-                dataType:'json',
-                data:formData,
-                success:function (res) {
-                    if(res.code == 200){
-                        vm.$Message.success(res.msg);
-                        formCreate.formSuccess && formCreate.formSuccess(res,$f,formData);
-						callback && callback(0,res,$f,formData);
-						//TODO 表单提交成功!
-                    }else{
-						vm.$Message.error(res.msg);
+            },
+            //表单提交事件
+            onSubmit: function (formData) {
+                $f.submitStatus({loading: true});
+                $.ajax({
+                    url: '<?=$form->getAction()?>',
+                    type: '<?=$form->getMethod()?>',
+                    dataType: 'json',
+                    data: formData,
+                    success: function (res) {
+                        if (res.code == 200) {
+                            vm.$Message.success(res.msg);
+                            formCreate.formSuccess && formCreate.formSuccess(res, $f, formData);
+                            callback && callback(0, res, $f, formData);
+                            //TODO 表单提交成功!
+                        } else {
+                            vm.$Message.error(res.msg);
+                            $f.btn.finish();
+                            callback && callback(1, res, $f, formData);
+                            //TODO 表单提交失败
+                        }
+                    },
+                    error: function () {
+                        vm.$Message.error('表单提交失败');
                         $f.btn.finish();
-						callback && callback(1,res,$f,formData);
-						//TODO 表单提交失败
                     }
-                },
-                error:function () {
-                    vm.$Message.error('表单提交失败');
-                    $f.btn.finish();
-                }
-            });
-        }
-    });
-        return formData;
+                });
+            }
+        });
     };
-}());
+}());