NodeCard.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <script setup lang="ts">
  2. import { Pin, renderNodeIcon } from '@/views/flow/store/get';
  3. import Draggable from 'vuedraggable';
  4. interface Props {
  5. list: Array<any>;
  6. }
  7. const props = defineProps<Props>();
  8. function onDragStart(e: any, v: Pin) {
  9. if (e.dataTransfer) {
  10. e.dataTransfer.setData('isNode', true);
  11. e.dataTransfer.setData('data', JSON.stringify(v));
  12. }
  13. }
  14. </script>
  15. <template>
  16. <n-collapse class="panel" :default-expanded-names="[0, 1, 2, 3, 4, 5, 6, 7]">
  17. <n-collapse-item
  18. v-for="(item, index) in props.list"
  19. :key="index"
  20. :title="item.key"
  21. :name="index"
  22. >
  23. <Draggable
  24. animation="300"
  25. :list="item.value"
  26. :group="{ name: 'plugins', pull: 'clone', put: false }"
  27. itemKey="label"
  28. :sort="false"
  29. :clone="(e) => e"
  30. class="flex flex-col gap-2 w-full"
  31. >
  32. <template #item="{ element }">
  33. <n-card
  34. @dragstart="onDragStart($event, element)"
  35. :draggable="true"
  36. hoverable
  37. size="small"
  38. class="rounded-md cursor-pointer"
  39. header-class="pb-0"
  40. content-class="pb-2"
  41. >
  42. <template #header>
  43. <div class="flex justify-start items-center">
  44. <n-icon>
  45. <component :is="renderNodeIcon(element.type)" />
  46. </n-icon>
  47. <span class="text-[14px] ml-1">{{ element.type }}</span>
  48. </div>
  49. </template>
  50. <template #header-extra>
  51. <n-button text type="primary">
  52. <SvgIcon class="text-lg" icon="ic:baseline-plus" />
  53. </n-button>
  54. </template>
  55. <span class="text-gray-400 text-xs">{{ element.des }}</span>
  56. </n-card>
  57. </template>
  58. </Draggable>
  59. </n-collapse-item>
  60. </n-collapse>
  61. </template>
  62. <style scoped lang="less"></style>