initVue.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. if(config.val){//增加对空值的判断 Ben(20260408)
  25. data[key] = config.val.split('|');
  26. }else{
  27. data[key] = [];
  28. }
  29. }
  30. if (config.type === window.SS.dom.TYPE.IMG) {
  31. data[key + "showUrl"] = config.showUrl;
  32. data[key + "uploadUrl"] = config.uploadUrl;
  33. }
  34. });
  35. }
  36. // console.log("data",data);
  37. SS.ready(function () {
  38. if(ss.dom.formVmConfig)//加判断条件,页面有校验配置时,才运行下面的 Ben(20251206)
  39. for (let i = 0; i < ss.dom.formVmConfig.length; i++) {
  40. const item = ss.dom.formVmConfig[i];
  41. // 处理每个元素
  42. let rule = item.rule;
  43. let field = item.field;
  44. let param = item.param;
  45. window.ssVm.add(rule, field, param);
  46. }
  47. // 在这里直接初始化,不需要等待 load 事件
  48. window.SS.dom.initializeFormApp({
  49. el: "#app",
  50. data(){
  51. return data;
  52. },
  53. mounted() {
  54. const self = this;
  55. // 在这里可以使用 Vue 实例
  56. Object.entries(this.$data).forEach(([key, value]) => {
  57. // 处理 objPicker
  58. if (key.includes('ObjPicker')) {
  59. }
  60. // 处理 CCPSINGLE
  61. if (key.includes('CCPSINGLE')) {
  62. const originalKey = key.replace('CCPSINGLE', '');
  63. const self = this;
  64. // 只有第一个字段需要自动加载
  65. if (this[originalKey + "InitLoad"]) {
  66. ccpsingleFirstLoad(this[originalKey + "Url"], key).then(result =>{
  67. this[originalKey+'Option'] = result;
  68. })
  69. }
  70. // 绑定 change 事件
  71. this[originalKey + 'Change'] = async function(value) {
  72. const objP = self[originalKey + "objP"] || [];
  73. const currentIndex = objP.indexOf(originalKey);
  74. const children = currentIndex < 0 || currentIndex >= objP.length - 1 ? [] : objP.slice(currentIndex + 1);
  75. await doCascade({
  76. children,
  77. value,
  78. vm: self,
  79. loadData: (value) => getCcpsingleValue(children,value),
  80. });
  81. };
  82. }
  83. // 如果是 CCPSINGLE 类型
  84. if (key.includes('CCPMUTIPLE')) {
  85. const originalKey = key.replace('CCPMUTIPLE', '');
  86. const self = this;
  87. // 只有第一个字段需要自动加载
  88. if (this[originalKey + "InitLoad"]) {
  89. ccpsingleFirstLoad(this[originalKey + "Url"], key).then(result =>{
  90. this[originalKey+'Option'] = result;
  91. })
  92. }
  93. // 绑定 change 事件
  94. this[originalKey + 'Change'] = async function(value) {
  95. const objP = self[originalKey + "objP"] || [];
  96. const currentIndex = objP.indexOf(originalKey);
  97. const children = currentIndex < 0 || currentIndex >= objP.length - 1 ? [] : objP.slice(currentIndex + 1);
  98. await doCascade({
  99. children,
  100. value,
  101. vm: self,
  102. loadData: (value) => getCcpsingleValue(children,value),
  103. });
  104. };
  105. }
  106. });
  107. }
  108. })
  109. });