form-builder.php 5.5 KB

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