form.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //表单操作相关js文件
  2. window.ss.form = window.ss.form || {};
  3. //提交表单的方法
  4. ss.form.submit = function (param){
  5. const {
  6. id, url, width, height, minHeight, maxHeight, targetWin
  7. } = param;
  8. //如果表单校验通过
  9. if(window.ssVm&&window.ssVm.validateAllAndShowMsg()){
  10. let f = null;//表单元素对象
  11. if (id) {
  12. // 如果id不为空,根据id获取元素
  13. f = document.getElementById(id);
  14. } else {
  15. // 如果id为空,获取页面第一个form元素
  16. f = document.querySelector('form');
  17. }
  18. if(!f){
  19. alert('表单不存在');
  20. return;
  21. }
  22. if(url)
  23. f.action = url;
  24. if (width && height && minHeight && maxHeight) {
  25. ss.display.resizeComponent(
  26. width,
  27. height,
  28. minHeight,
  29. maxHeight
  30. );
  31. }
  32. if(targetWin){
  33. ss.form.submit2TargetWin(targetWin);
  34. }else{
  35. f.submit();
  36. }
  37. return true;
  38. }else
  39. return false;
  40. }
  41. ss.form.submit2TargetWin = function (targetWin) {
  42. const firstForm = document.querySelector('form');
  43. if(firstForm==null){
  44. console.log("找不到form!");
  45. }
  46. var myform = firstForm.cloneNode(true);
  47. myform.style.display = "none";
  48. firstForm.parentNode.innerHTML = "";
  49. targetWin.document.body.appendChild(myform);
  50. myform.submit();
  51. }
  52. ss.form.confirm = function (title,msg,yesFun,noFun){
  53. const isConfirmed = confirm(msg);
  54. if (isConfirmed) {
  55. console.log("用户确认yes");
  56. if(yesFun)
  57. yesFun();
  58. } else {
  59. console.log("用户取消");
  60. if(noFun)
  61. noFun();
  62. }
  63. }