index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <script>
  2. export default {
  3. name: "SuperForm",
  4. props: {
  5. value: {
  6. type: [Object],
  7. require: true,
  8. },
  9. dict: {
  10. type: [Object],
  11. require: true,
  12. },
  13. columns: {
  14. type: [Array],
  15. require: true,
  16. },
  17. },
  18. components: {
  19. ElFileUpload: () => import("@/components/FileUpload/index.vue"),
  20. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  21. ElPopoverMultipleSelectV2: () =>
  22. import("@/components/popover-select-v2/multiple.vue"),
  23. ElPopoverTreeSelect: () =>
  24. import("@/components/popover-tree-select/index.vue"),
  25. ElPopoverMultipleTreeSelect: () =>
  26. import("@/components/popover-tree-select/multiple.vue"),
  27. },
  28. data() {
  29. const { columns } = this.$props;
  30. const innerColumns = columns;
  31. return {
  32. drawer: false,
  33. visible: false,
  34. innerColumns: innerColumns,
  35. };
  36. },
  37. computed: {
  38. innerValue: {
  39. get() {
  40. return this.value;
  41. },
  42. set(value) {
  43. this.$emit("input", value);
  44. },
  45. },
  46. },
  47. watch: {},
  48. methods: {
  49. // 继承el-table的Method
  50. extendMethod() {
  51. const refMethod = Object.entries(this.$refs["superForm"]);
  52. for (const [key, value] of refMethod) {
  53. if (!(key.includes("$") || key.includes("_"))) {
  54. this[key] = value;
  55. }
  56. }
  57. },
  58. },
  59. created() {},
  60. mounted() {
  61. this.extendMethod();
  62. },
  63. destroyed() {},
  64. };
  65. </script>
  66. <template>
  67. <el-form
  68. ref="superForm"
  69. v-bind="$attrs"
  70. v-on="$listeners"
  71. :model="innerValue"
  72. @submit.native.prevent
  73. >
  74. <el-row :gutter="24" style="display: flex; flex-wrap: wrap">
  75. <el-col
  76. v-for="({ item, attr }, index) in innerColumns"
  77. :key="index"
  78. :span="item.span"
  79. >
  80. <el-form-item :prop="item.key" :label="item.title">
  81. <slot :name="item.key" :row="innerValue" :item="item" :attr="attr">
  82. <component
  83. v-if="attr.is === 'el-select'"
  84. v-bind="attr"
  85. v-model="innerValue[item.key]"
  86. style="width: 100%"
  87. >
  88. <template>
  89. <el-option
  90. v-for="item in dict.type[attr.dictName]"
  91. :key="item.value"
  92. :label="item.label"
  93. :value="item.value"
  94. >
  95. </el-option>
  96. </template>
  97. </component>
  98. <component
  99. v-else-if="attr.is === 'el-popover-select-v2'"
  100. v-bind="attr"
  101. v-model="innerValue[item.key]"
  102. :source.sync="innerValue"
  103. style="width: 100%"
  104. >
  105. </component>
  106. <component
  107. v-else-if="attr.is === 'el-popover-multiple-select-v2'"
  108. v-bind="attr"
  109. v-model="innerValue[item.key]"
  110. :source.sync="innerValue"
  111. style="width: 100%"
  112. >
  113. </component>
  114. <component
  115. v-else-if="attr.is === 'el-popover-tree-select'"
  116. v-bind="attr"
  117. v-model="innerValue[item.key]"
  118. :source.sync="innerValue"
  119. style="width: 100%"
  120. >
  121. </component>
  122. <component
  123. v-else-if="attr.is === 'el-popover-multiple-tree-select'"
  124. v-bind="attr"
  125. v-model="innerValue[item.key]"
  126. :source.sync="innerValue"
  127. style="width: 100%"
  128. >
  129. </component>
  130. <component
  131. v-else
  132. v-bind="attr"
  133. v-model="innerValue[item.key]"
  134. style="width: 100%"
  135. >
  136. </component>
  137. </slot>
  138. </el-form-item>
  139. </el-col>
  140. </el-row>
  141. </el-form>
  142. </template>
  143. <style scoped></style>