FormWrapper.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <el-form ref="form" :model="form" label-width="130px" v-if="form && form.type">
  3. <!-- Text component form items -->
  4. <text-form-items
  5. v-if="form.type === 'h5-text'"
  6. :config="form"
  7. @update:config="updateFormConfig"
  8. />
  9. <!-- Image component form items -->
  10. <image-form-items
  11. v-if="form.type === 'h5-image'"
  12. :config="form"
  13. />
  14. <!-- Sep component form items -->
  15. <sep-form-items
  16. v-if="form.type === 'h5-sep'"
  17. :config="form"
  18. />
  19. <!-- Countdown component form items -->
  20. <countdown-form-items
  21. v-if="form.type === 'h5-countdown'"
  22. :config="form"
  23. @update:config="updateFormConfig"
  24. />
  25. <chat-form-items
  26. v-if="form.type === 'h5-chat'"
  27. :config="form"
  28. @update:config="updateFormConfig"
  29. />
  30. <!-- Common form items for all components -->
  31. <common-form-items
  32. :config="form"
  33. :index="index"
  34. :list="list"
  35. @bottom-change="handleBottomChange"
  36. @delete="handleDelete"
  37. @update:config="updateFormConfig"
  38. />
  39. </el-form>
  40. </template>
  41. <script>
  42. import TextFormItems from './config-item/h5-text-config.vue';
  43. import ImageFormItems from './config-item/h5-image-config.vue';
  44. import SepFormItems from './config-item/h5-sep-config.vue';
  45. import CommonFormItems from './config-item/common-config.vue';
  46. import CountdownFormItems from './config-item/h5-countdown-config.vue';
  47. import ChatFormItems from './config-item/h5-chat-config.vue'
  48. export default {
  49. name: 'FormWrapper',
  50. components: {
  51. TextFormItems,
  52. ImageFormItems,
  53. SepFormItems,
  54. CommonFormItems,
  55. CountdownFormItems,
  56. ChatFormItems
  57. },
  58. props: {
  59. form: {
  60. type: Object,
  61. default: () => ({})
  62. },
  63. index: {
  64. type: Number,
  65. default: -1
  66. },
  67. list: {
  68. type: Array,
  69. default: () => []
  70. }
  71. },
  72. methods: {
  73. updateFormConfig(newConfig) {
  74. console.log("更新表单配置...");
  75. // Update form config
  76. this.$emit('update:form', newConfig);
  77. },
  78. handleBottomChange() {
  79. // Check if another item is already fixed to bottom
  80. let hasFooter = this.list.some((item, idx) =>
  81. idx !== this.index && item.classText && item.classText.includes('footer')
  82. );
  83. if(hasFooter) {
  84. alert('全局只能允许有一个在底部!');
  85. this.form.fixe = false;
  86. return;
  87. }
  88. // Update the class
  89. let className = "footer";
  90. if (this.form.fixe) {
  91. this.addClassToItem(className);
  92. } else {
  93. this.removeClassFromItem(className);
  94. }
  95. },
  96. addClassToItem(className) {
  97. if (!this.form.classText.includes(className)) {
  98. this.form.classText.push(className);
  99. }
  100. },
  101. removeClassFromItem(className) {
  102. this.form.classText = this.form.classText.filter(cls => cls !== className);
  103. },
  104. handleDelete() {
  105. this.$emit('delete', this.index);
  106. }
  107. }
  108. }
  109. </script>
  110. <style scoped>
  111. .el-form-item__label{
  112. text-align: center !important;
  113. }
  114. </style>