form-builder.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title><?=$form->getTitle()?></title>
  6. <script src="{__PLUG_PATH}vue/dist/vue.min.js"></script>
  7. <link href="{__PLUG_PATH}iview/dist/styles/iview.css" rel="stylesheet">
  8. <script src="{__PLUG_PATH}iview/dist/iview.min.js"></script>
  9. <script src="{__PLUG_PATH}jquery/jquery.min.js"></script>
  10. <script src="{__PLUG_PATH}form-create/province_city.js"></script>
  11. <script src="{__PLUG_PATH}form-create/form-create.min.js"></script>
  12. <style>
  13. /*弹框样式修改*/
  14. .ivu-modal{top: 20px;}
  15. .ivu-modal .ivu-modal-body{padding: 10px;}
  16. .ivu-modal .ivu-modal-body .ivu-modal-confirm-head{padding:0 0 10px 0;}
  17. .ivu-modal .ivu-modal-body .ivu-modal-confirm-footer{display: none;padding-bottom: 10px;}
  18. .ivu-date-picker {display: inline-block;line-height: normal;width: 280px;}
  19. .ivu-modal-footer{display: none;}
  20. body{padding: 20px;}
  21. </style>
  22. </head>
  23. <body>
  24. <script>
  25. window.$f = null
  26. formCreate.formSuccess = function(form,$r){
  27. <?=$form->getSuccessScript()?>
  28. //刷新父级页面
  29. // parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
  30. //关闭当前窗口
  31. // var index = parent.layer.getFrameIndex(window.name);
  32. // parent.layer.close(index);
  33. //提交成功后按钮恢复
  34. $r.btn.loading(false);
  35. };
  36. (function () {
  37. var create = (function () {
  38. var getRule = function () {
  39. var rule = <?=json_encode($form->getRules())?>;
  40. rule.forEach(function (c) {
  41. if ((c.type == 'cascader' || c.type == 'tree') && Object.prototype.toString.call(c.props.data) == '[object String]') {
  42. if (c.props.data.indexOf('js.') === 0) {
  43. c.props.data = window[c.props.data.replace('js.', '')];
  44. }
  45. }
  46. });
  47. return rule;
  48. }, vm = new Vue,name = 'formBuilderExec<?= !$form->getId() ? '' : '_'.$form->getId() ?>';
  49. var _b = false;
  50. window[name] = function create(el, callback) {
  51. if(_b) return ;
  52. _b = true;
  53. if (!el) el = document.body;
  54. $f = formCreate.create(getRule(), {
  55. el: el,
  56. form:<?=json_encode($form->getConfig('form'))?>,
  57. row:<?=json_encode($form->getConfig('row'))?>,
  58. submitBtn:<?=$form->isSubmitBtn() ? '{}' : 'false'?>,
  59. resetBtn:<?=$form->isResetBtn() ? 'true' : '{}'?>,
  60. iframeHelper:true,
  61. global:{
  62. upload: {
  63. props:{
  64. onExceededSize: function (file) {
  65. vm.$Message.error(file.name + '超出指定大小限制');
  66. },
  67. onFormatError: function () {
  68. vm.$Message.error(file.name + '格式验证失败');
  69. },
  70. onError: function (error) {
  71. vm.$Message.error(file.name + '上传失败,(' + error + ')');
  72. },
  73. onSuccess: function (res, file) {
  74. if (res.code == 200) {
  75. file.url = res.data.filePath;
  76. } else {
  77. vm.$Message.error(res.msg);
  78. }
  79. },
  80. },
  81. },
  82. },
  83. //表单提交事件
  84. onSubmit: function (formData) {
  85. $f.btn.loading(true);
  86. $.ajax({
  87. url: '<?=$form->getAction()?>',
  88. type: '<?=$form->getMethod()?>',
  89. dataType: 'json',
  90. data: formData,
  91. success: function (res) {
  92. if (res.code == 200) {
  93. vm.$Message.success(res.msg);
  94. $f.btn.loading(false);
  95. formCreate.formSuccess && formCreate.formSuccess(res, $f, formData);
  96. callback && callback(0, res, $f, formData);
  97. //TODO 表单提交成功!
  98. } else {
  99. vm.$Message.error(res.msg || '表单提交失败');
  100. $f.btn.loading(false);
  101. callback && callback(1, res, $f, formData);
  102. //TODO 表单提交失败
  103. }
  104. },
  105. error: function () {
  106. vm.$Message.error('表单提交失败');
  107. $f.btn.loading(false);
  108. }
  109. });
  110. }
  111. });
  112. return $f;
  113. };
  114. return window[name];
  115. }());
  116. window.$f = create();
  117. // create();
  118. })();
  119. </script>
  120. </body>
  121. </html>