customComponent.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!--
  2. * @Descripttion:
  3. * @Author: kcz
  4. * @Date: 2021-05-02 16:04:02
  5. * @LastEditors: kcz
  6. * @LastEditTime: 2021-05-14 21:24:50
  7. -->
  8. <template>
  9. <a-form-item
  10. :label="record.label"
  11. :label-col="
  12. formConfig.layout === 'horizontal'
  13. ? formConfig.labelLayout === 'flex'
  14. ? { style: `width:${formConfig.labelWidth}px` }
  15. : formConfig.labelCol
  16. : {}
  17. "
  18. :wrapper-col="
  19. formConfig.layout === 'horizontal'
  20. ? formConfig.labelLayout === 'flex'
  21. ? { style: 'width:auto;flex:1' }
  22. : formConfig.wrapperCol
  23. : {}
  24. "
  25. :style="
  26. formConfig.layout === 'horizontal' && formConfig.labelLayout === 'flex'
  27. ? { display: 'flex' }
  28. : {}
  29. "
  30. >
  31. <component
  32. :record="record"
  33. :style="`width:${record.options.width}`"
  34. @change="handleChange"
  35. :disabled="disabled"
  36. :dynamicData="dynamicData"
  37. :height="
  38. typeof record.options.height !== 'undefined'
  39. ? record.options.height
  40. : ''
  41. "
  42. v-decorator="[
  43. record.model,
  44. {
  45. initialValue: record.options.defaultValue,
  46. rules: record.rules
  47. }
  48. ]"
  49. :is="customComponent"
  50. ></component>
  51. </a-form-item>
  52. </template>
  53. <script>
  54. export default {
  55. name: "customComponent",
  56. props: ["record", "formConfig", "disabled", "dynamicData"],
  57. computed: {
  58. customComponent() {
  59. // 计算需要显示的组件
  60. const customComponentList = {};
  61. if (window.$customComponentList) {
  62. // 将数组映射成json
  63. window.$customComponentList.forEach(item => {
  64. customComponentList[item.type] = item.component;
  65. });
  66. }
  67. return customComponentList[this.record.type];
  68. }
  69. },
  70. methods: {
  71. handleChange(value, key) {
  72. this.$emit("change", value, key);
  73. }
  74. }
  75. };
  76. </script>