form.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // 无校验直接提交,兼容无校验页面 by xu 20251211
  9. const needValidate = window.ssVm && window.ssVm.validations && window.ssVm.validations.size > 0;
  10. if(!needValidate || window.ssVm.validateAllAndShowMsg()){
  11. let f = null;//表单元素对象
  12. if (id) {
  13. // 如果id不为空,根据id获取元素
  14. f = document.getElementById(id);
  15. } else {
  16. // 如果id为空,获取页面第一个form元素
  17. f = document.querySelector('form');
  18. }
  19. if(!f){
  20. alert('表单不存在');
  21. return;
  22. }
  23. if(url)
  24. f.action = url;
  25. if (width && height && minHeight && maxHeight) {
  26. ss.display.resizeComponent(
  27. width,
  28. height,
  29. minHeight,
  30. maxHeight
  31. );
  32. }
  33. if(targetWin){
  34. ss.form.submit2TargetWin(targetWin);
  35. }else{
  36. f.submit();
  37. }
  38. return true;
  39. }else
  40. return false;
  41. }
  42. ss.form.submit2TargetWin = function (targetWin) {
  43. const firstForm = document.querySelector('form');
  44. if(firstForm==null){
  45. console.log("找不到form!");
  46. }
  47. var myform = firstForm.cloneNode(true);
  48. myform.style.display = "none";
  49. firstForm.parentNode.innerHTML = "";
  50. targetWin.document.body.appendChild(myform);
  51. myform.submit();
  52. }
  53. ss.form.confirm = function (title,msg,yesFun,noFun){
  54. const isConfirmed = confirm(msg);
  55. if (isConfirmed) {
  56. console.log("用户确认yes");
  57. if(yesFun)
  58. yesFun();
  59. } else {
  60. console.log("用户取消");
  61. if(noFun)
  62. noFun();
  63. }
  64. }