node-index.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="node" ref="ref_node" :class="{active: state.active, panel: WorkflowStore.panel.node?.id === state.node?.id}">
  3. <div class="node-title">
  4. {{ state.nodeData?.title }}
  5. <div class="node-sub" v-if="state.nodeData?.subTitle">{{ state.nodeData.subTitle }}</div>
  6. </div>
  7. <div class="node-content">
  8. <template v-if="state.nodeData?.type === NodeType.Root">
  9. <rootNode :node="state.node"/>
  10. </template>
  11. <template v-else-if="state.nodeData?.type === NodeType.Test">
  12. <testNode :node="state.node"/>
  13. </template>
  14. <template v-else-if="state.nodeData?.type === NodeType.IfElse">
  15. <ifElseNode :node="state.node"/>
  16. </template>
  17. <template v-else-if="state.nodeData?.type === NodeType.Answer">
  18. <answerNode :node="state.node"/>
  19. </template>
  20. </div>
  21. </div>
  22. </template>
  23. <script setup lang="ts">
  24. import {computed, getCurrentInstance, inject, nextTick, onMounted, reactive, ref, watch} from "vue";
  25. import rootNode from '../instance/root/node/index.vue'
  26. import ifElseNode from '../instance/if-else/node/index.vue'
  27. import testNode from '../instance/test/node/index.vue'
  28. import answerNode from '../instance/answer/node/index.vue'
  29. import {useWorkflowStore} from "@/stores";
  30. import {NodeType} from "@/views/workflow/types";
  31. import {lineActiveStyle, lineStyle} from "@/views/workflow/config";
  32. const WorkflowStore = useWorkflowStore()
  33. const getNode: any = inject('getNode')
  34. const emits = defineEmits([])
  35. const props = defineProps({})
  36. const {proxy}: any = getCurrentInstance()
  37. const state: any = reactive({
  38. node: null,
  39. nodeData: {},
  40. active: false
  41. })
  42. const ref_node = ref()
  43. onMounted(() => {
  44. state.node = getNode()
  45. state.node.on('change:attrs', () => {
  46. state.active = state.node.getAttrByPath('hover') || state.node.getAttrByPath('select')
  47. })
  48. state.nodeData = state.node.data.workflowData
  49. nextTick(() => {
  50. state.node.size(ref_node.value.clientWidth, ref_node.value.clientHeight)
  51. })
  52. })
  53. </script>
  54. <style lang="scss" scoped>
  55. @use "@/views/workflow/instance/component/style";
  56. .node {
  57. z-index: 10;
  58. border-radius: 10px;
  59. background-color: #ffffff;
  60. position: absolute;
  61. width: 240px;
  62. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  63. border-width: 2px;
  64. border-color: transparent;
  65. &.active {
  66. border-color: rgba(var(--czr-main-color-rgb), 0.5);
  67. cursor: pointer;
  68. }
  69. &.panel {
  70. border-color: rgba(var(--czr-main-color-rgb), 1);
  71. cursor: pointer;
  72. }
  73. .node-title {
  74. min-height: 50px;
  75. width: 100%;
  76. display: flex;
  77. justify-content: center;
  78. flex-direction: column;
  79. padding: 8px 12px;
  80. font-size: 14px;
  81. font-weight: bold;
  82. .node-sub {
  83. font-size: 12px;
  84. font-weight: normal;
  85. opacity: 0.65;
  86. }
  87. }
  88. .node-content {
  89. padding: 0px 12px;
  90. //margin-bottom: 8px;
  91. //border-top: 1px solid rgba(0, 0, 0, 0.1);
  92. }
  93. }
  94. </style>