WidgetForm.vue 1.6 KB

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