form-drawing-item.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="form-drawing-item" :class="{'is-active':isActive,'is-layout': config.type === 'grid'}">
  3. <div class="form-drawing-item__handle">
  4. <i class="el-icon-rank show-focus handle-icon move-icon"/>
  5. <span class="right-top item-field-key">{{fieldKey}}
  6. <template v-if="twoValueComponentList.includes(config.type)">
  7. -{{config.otherKey}}
  8. </template>
  9. </span>
  10. <div class="right-bottom show-focus">
  11. <i class="el-icon-document-copy handle-icon" v-if="showCopy" @click.stop="copyItem"></i>
  12. <i class="el-icon-delete handle-icon" @click.stop="deleteItem"></i>
  13. </div>
  14. </div>
  15. <cip-form-item :field-key="fieldKey" :config="computedConfig" :show-template="true" :model="model"></cip-form-item>
  16. </div>
  17. </template>
  18. <script>
  19. import { computed, watch, ref } from 'vue'
  20. import CipFormItem from '@cip/components/cip-form-item'
  21. import { handleFormConfig } from './handle-config'
  22. import { twoValueComponentList } from '../util'
  23. export default {
  24. name: 'FormDrawingItem',
  25. components: {
  26. CipFormItem
  27. },
  28. props: {
  29. isActive: Boolean,
  30. fieldKey: String,
  31. config: Object,
  32. showCopy: {
  33. type: Boolean,
  34. default: true
  35. }
  36. },
  37. emits: ['onDelete', 'onCopy'],
  38. setup (props, context) {
  39. const model = ref({})
  40. const computedConfig = computed(() => {
  41. return handleFormConfig(props.config, [], {
  42. table: 'basic-table-design'
  43. }, { })
  44. })
  45. watch(() => computedConfig.value.defaultValue, (val) => {
  46. model.value[props.fieldKey] = val
  47. })
  48. const deleteItem = () => {
  49. context.emit('onDelete')
  50. }
  51. const copyItem = () => {
  52. context.emit('onCopy')
  53. }
  54. return {
  55. twoValueComponentList,
  56. computedConfig,
  57. deleteItem,
  58. copyItem,
  59. model
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="less">
  65. .form-drawing-item{
  66. user-select: none;
  67. position: relative;
  68. background-color: rgba(236,245,255,.3);
  69. border: 1px dashed #999;
  70. margin: 4px 2px;
  71. &.is-active{
  72. .form-drawing-item__handle{
  73. border: 1px solid @primary;
  74. outline: 2px solid @primary;
  75. }
  76. .show-focus{
  77. visibility: visible;
  78. }
  79. .handle-icon{
  80. padding: 4px;
  81. color: #fff;
  82. background-color: @primary;
  83. }
  84. }
  85. .show-focus{
  86. visibility: hidden;
  87. }
  88. &__handle{
  89. position: absolute;
  90. left: 0;
  91. right: 0;
  92. top: 0;
  93. bottom: 0;
  94. z-index: 2;
  95. .handle-icon{
  96. cursor: pointer;
  97. }
  98. .move-icon{
  99. cursor: move;
  100. }
  101. .item-field-key{
  102. color: @success;
  103. font-size: 12px;
  104. }
  105. .right-top{
  106. position: absolute;
  107. right: 0;
  108. top: 0;
  109. }
  110. .right-bottom{
  111. position: absolute;
  112. right: 0;
  113. bottom: 0;
  114. }
  115. }
  116. }
  117. </style>