WidgetForm.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <el-form
  3. label-suffix=":"
  4. bg-gray-50 relative flex="~ 1"
  5. v-bind="config"
  6. >
  7. <div v-if="!list?.length" text="gray-400 lg" absolute top-50 left="1/2" translate-x="-1/2">
  8. 从左侧拖拽来添加字段
  9. </div>
  10. <Draggable
  11. class="flex-1 m-2 bg-white shadow p-1"
  12. item-key="key"
  13. handle="[cursor-move]"
  14. :animation="200"
  15. group="form-design"
  16. :list="list"
  17. @add="selectWidget=list[$event.newIndex]"
  18. >
  19. <template #item="{ element, index }">
  20. <WidgetFormItem
  21. v-model:selectWidget="selectWidget"
  22. :element="element"
  23. :index="index"
  24. :list="list"
  25. />
  26. </template>
  27. </Draggable>
  28. </el-form>
  29. </template>
  30. <script lang="ts" setup>
  31. import Draggable from 'vuedraggable'
  32. import WidgetFormItem from './WidgetFormItem.vue'
  33. import type { WidgetForm } from '@/config'
  34. const props = defineProps<{ list: any; config: WidgetForm['config']; selectWidget: any }>()
  35. defineEmits(['update:selectWidget'])
  36. const selectWidget = useVModel(props, 'selectWidget')
  37. </script>
  38. <style lang="scss">
  39. .widget-view {
  40. @apply relative m-0.5 p-1 border border-dashed border-gray-300;
  41. &.col {
  42. @apply grid grid-cols-24;
  43. }
  44. &.active {
  45. @apply border-solid border-blue-500 outline outline-2 outline-blue-500;
  46. &.col {
  47. @apply border-yellow-500 outline-yellow-500;
  48. }
  49. }
  50. &:hover {
  51. @apply border-blue-500 bg-blue-50;
  52. &.col {
  53. @apply border-yellow-500 bg-yellow-50;
  54. }
  55. }
  56. }
  57. </style>