initFormElem.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //公共初始化页面vue表单元素组件js,放在所有vue表单元素之后引入 Ben(20251217)
  2. const data = {};
  3. if (window.SS.dom.formElemConfig) {
  4. Object.entries(window.SS.dom.formElemConfig).forEach(([key, config]) => {
  5. data[key] = config.val;
  6. // 处理 objPicker
  7. if (config.type === window.SS.dom.TYPE.OBJPICKER) {
  8. data[key + "ObjPicker"] = true;
  9. data[key + "Option"] = [];
  10. data[key + "Url"] = config.url;
  11. }
  12. // 处理datepicker
  13. if (config.type === window.SS.dom.TYPE.DATE) {
  14. data[key + "Mode"] = config.mode
  15. console.log(data[key + "Mode"]);
  16. }
  17. // 处理富文本编辑器
  18. if (config.type === window.SS.dom.TYPE.RICHTEXT) {
  19. data[key + "Url"] = config.val;
  20. data[key + "editor"] = config.val;
  21. }
  22. // 处理onoff
  23. if (config.type === window.SS.dom.TYPE.ONOFFBTN) {
  24. data[key] = config.val.split('|');
  25. }
  26. if (config.type === window.SS.dom.TYPE.IMG) {
  27. data[key + "showUrl"] = config.showUrl;
  28. data[key + "uploadUrl"] = config.uploadUrl;
  29. }
  30. });
  31. }
  32. // console.log("data",data);
  33. SS.ready(function () {
  34. if(ss.dom.formVmConfig)//加判断条件,页面有校验配置时,才运行下面的 Ben(20251206)
  35. for (let i = 0; i < ss.dom.formVmConfig.length; i++) {
  36. const item = ss.dom.formVmConfig[i];
  37. // 处理每个元素
  38. let rule = item.rule;
  39. let field = item.field;
  40. let param = item.param;
  41. window.ssVm.add(rule, field, param);
  42. }
  43. // 在这里直接初始化,不需要等待 load 事件
  44. window.SS.dom.initializeFormApp({
  45. el: "#app",
  46. data(){
  47. return data;
  48. },
  49. mounted() {
  50. const self = this;
  51. // 在这里可以使用 Vue 实例
  52. Object.entries(this.$data).forEach(([key, value]) => {
  53. // 处理 objPicker
  54. if (key.includes('ObjPicker')) {
  55. }
  56. // 处理 CCPSINGLE
  57. if (key.includes('CCPSINGLE')) {
  58. const originalKey = key.replace('CCPSINGLE', '');
  59. const self = this;
  60. // 只有第一个字段需要自动加载
  61. if (this[originalKey + "InitLoad"]) {
  62. ccpsingleFirstLoad(this[originalKey + "Url"], key).then(result =>{
  63. this[originalKey+'Option'] = result;
  64. })
  65. }
  66. // 绑定 change 事件
  67. this[originalKey + 'Change'] = async function(value) {
  68. const objP = self[originalKey + "objP"] || [];
  69. const currentIndex = objP.indexOf(originalKey);
  70. const children = currentIndex < 0 || currentIndex >= objP.length - 1 ? [] : objP.slice(currentIndex + 1);
  71. await doCascade({
  72. children,
  73. value,
  74. vm: self,
  75. loadData: (value) => getCcpsingleValue(children,value),
  76. });
  77. };
  78. }
  79. // 如果是 CCPSINGLE 类型
  80. if (key.includes('CCPMUTIPLE')) {
  81. const originalKey = key.replace('CCPMUTIPLE', '');
  82. const self = this;
  83. // 只有第一个字段需要自动加载
  84. if (this[originalKey + "InitLoad"]) {
  85. ccpsingleFirstLoad(this[originalKey + "Url"], key).then(result =>{
  86. this[originalKey+'Option'] = result;
  87. })
  88. }
  89. // 绑定 change 事件
  90. this[originalKey + 'Change'] = async function(value) {
  91. const objP = self[originalKey + "objP"] || [];
  92. const currentIndex = objP.indexOf(originalKey);
  93. const children = currentIndex < 0 || currentIndex >= objP.length - 1 ? [] : objP.slice(currentIndex + 1);
  94. await doCascade({
  95. children,
  96. value,
  97. vm: self,
  98. loadData: (value) => getCcpsingleValue(children,value),
  99. });
  100. };
  101. }
  102. });
  103. }
  104. })
  105. });