画布
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
import { ref, inject } from 'vue'
|
import { ref, inject } from 'vue'
|
||||||
import { NODE_DATATYPE } from '../../tools/index.d'
|
import { NODE_DATATYPE } from '../../tools/index.d'
|
||||||
const nodeManager = inject('nodeManager') as any
|
const nodeManager = inject('nodeManager') as any
|
||||||
|
const stateManager = inject('stateManager') as any
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
node: { required: true, type: Object }
|
node: { required: true, type: Object }
|
||||||
})
|
})
|
||||||
@@ -46,9 +47,10 @@
|
|||||||
const onClickItem = (v) => {
|
const onClickItem = (v) => {
|
||||||
const id = props.node.id
|
const id = props.node.id
|
||||||
if (!id) return
|
if (!id) return
|
||||||
nodeManager.deleteNode(id)
|
stateManager.deleteNode(id)
|
||||||
nodeManager.createCardNode({ data: { type: v.type } })
|
nodeManager.createCardNode({ data: { type: v.type } })
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({})
|
defineExpose({})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, useAttrs } from 'vue'
|
import { computed, ref, useAttrs, onMounted, inject } from 'vue'
|
||||||
import CardsSelect from './cards-select.vue'
|
import CardsSelect from './cards-select.vue'
|
||||||
import ToRealStyle from './to-real-style.vue'
|
import ToRealStyle from './to-real-style.vue'
|
||||||
import SurfaceEdit from './surface-edit.vue'
|
import SurfaceEdit from './surface-edit.vue'
|
||||||
@@ -32,9 +32,9 @@
|
|||||||
import To3View from './to-3view.vue'
|
import To3View from './to-3view.vue'
|
||||||
import To3DModel from './to-3d-model.vue'
|
import To3DModel from './to-3d-model.vue'
|
||||||
|
|
||||||
import ToVideo from './to-video.vue'
|
// import ToVideo from './to-video.vue'
|
||||||
import AddPrint from './add-print.vue'
|
// import AddPrint from './add-print.vue'
|
||||||
import ToCAD from './to-cad.vue'
|
// import ToCAD from './to-cad.vue'
|
||||||
const components = [
|
const components = [
|
||||||
{
|
{
|
||||||
type: 'cards-select',
|
type: 'cards-select',
|
||||||
@@ -73,23 +73,8 @@
|
|||||||
title: 'To 3D Model',
|
title: 'To 3D Model',
|
||||||
component: To3DModel
|
component: To3DModel
|
||||||
}
|
}
|
||||||
// {
|
|
||||||
// type: 'to-video',
|
|
||||||
// title: 'To Video',
|
|
||||||
// component: ToVideo
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// type: 'to-cad',
|
|
||||||
// title: 'To CAD',
|
|
||||||
// component: ToCAD
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// type: 'add-print',
|
|
||||||
// title: 'Add Print',
|
|
||||||
// component: AddPrint
|
|
||||||
// }
|
|
||||||
]
|
]
|
||||||
const emit = defineEmits(['add', 'generate'])
|
const nodeManager = inject('nodeManager') as any
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
type: {
|
type: {
|
||||||
type: String as () =>
|
type: String as () =>
|
||||||
@@ -101,6 +86,10 @@
|
|||||||
| 'to-3d-model'
|
| 'to-3d-model'
|
||||||
| 'to-3view',
|
| 'to-3view',
|
||||||
default: 'to-real-style'
|
default: 'to-real-style'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const attrs = useAttrs()
|
const attrs = useAttrs()
|
||||||
@@ -111,8 +100,21 @@
|
|||||||
const onGenerateClick = () => {
|
const onGenerateClick = () => {
|
||||||
const data = { ...componentRef.value.data }
|
const data = { ...componentRef.value.data }
|
||||||
console.log(data)
|
console.log(data)
|
||||||
emit('generate')
|
nodeManager.createResultNode({
|
||||||
|
data: {
|
||||||
|
data: {
|
||||||
|
url: 'https://s3-alpha-sig.figma.com/img/ea2f/590e/9638f62a2fc91e31f33db0022db1642c?Expires=1773014400&Key-Pair-Id=APKAQ4GOSFWCW27IBOMQ&Signature=M0B8oJJOk~dGG0aZAqOIocAp7T0LFdJ9FYmCrEZVTCRzYxM6SJRNtYMTX-rTO3Z~s14QINh~o-S41XiZnBv-0zcKjuWot~VVaNHfd0~1LesfNe2KwvCinT~72btFut1pheLnKE-wWCX5ewtonxU77bnw386YPMTqv7DBZzksf2udsJA7NmOYD6~TUG3Q2dWSt~zPH~lkaidscPqpCnCbqzljCEi4RiHY4U3A45l5XypcX2umqn1UaYUFCTqV9471J4qdB6Dg2pcKocdp-7-3s1De6Q~2SmBOrSgDQ~KEADCB2lhKfhxgWmy0lwMvhTd4l90ygVZDWZRABgjHNrGUvg__'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onMounted(() => {
|
||||||
|
for (const key in props.data) {
|
||||||
|
if (componentRef.value?.data?.hasOwnProperty(key)) {
|
||||||
|
componentRef.value.data[key] = props.data[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
|||||||
@@ -1,10 +1,31 @@
|
|||||||
|
<template>
|
||||||
|
<div class="node start" :class="{ center: posCenter }">
|
||||||
|
<template v-if="type === NODE_TYPE.INPUT">
|
||||||
|
<Handle type="source" id="Right" :position="Position.Right" />
|
||||||
|
</template>
|
||||||
|
<template v-else-if="type === NODE_TYPE.SECONDARY">
|
||||||
|
<Handle type="target" id="Left" :position="Position.Left" />
|
||||||
|
<Handle type="source" id="Right" :position="Position.Right" />
|
||||||
|
</template>
|
||||||
|
<template v-else-if="type === NODE_TYPE.OUTPUT">
|
||||||
|
<Handle type="target" id="Left" :position="Position.Left" />
|
||||||
|
</template>
|
||||||
|
<div class="item">
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
<div class="add" @mousedown.stop v-if="isAdd" @click="onAdd">
|
||||||
|
<svg-icon name="add" size="14" size-unit="px" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { Handle, Position } from '@vue-flow/core'
|
import { Handle, Position } from '@vue-flow/core'
|
||||||
|
import { NODE_TYPE } from '../tools/index.d'
|
||||||
import { NODE_DATATYPE } from '../tools/index.d'
|
import { NODE_DATATYPE } from '../tools/index.d'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
type: {
|
type: {
|
||||||
type: String as () => 'InputNode' | 'SecondaryNode',
|
type: String,
|
||||||
default: 'InputNode'
|
default: 'InputNode'
|
||||||
},
|
},
|
||||||
node: {
|
node: {
|
||||||
@@ -19,41 +40,29 @@
|
|||||||
const nodes = computed(() => props.stateManager.nodes.value)
|
const nodes = computed(() => props.stateManager.nodes.value)
|
||||||
const firstNode = computed(() => nodes.value[0])
|
const firstNode = computed(() => nodes.value[0])
|
||||||
const lastNode = computed(() => nodes.value[nodes.value.length - 1])
|
const lastNode = computed(() => nodes.value[nodes.value.length - 1])
|
||||||
const notAddNodeTypes = [NODE_DATATYPE.CARDS_SELECT]
|
|
||||||
const isAdd = computed(
|
const isAdd = computed(
|
||||||
() => props.node.id === lastNode.value.id && !notAddNodeTypes.includes(props.node.data.type)
|
() => props.node.id === lastNode.value.id && NODE_DATATYPE.RESULT_IMAGE === props.node.data.type
|
||||||
)
|
)
|
||||||
const onAdd = () => {
|
const onAdd = () => {
|
||||||
props.stateManager.nodeManager.createCardsSelect()
|
props.stateManager.nodeManager.createCardsSelect()
|
||||||
}
|
}
|
||||||
|
const posCenter = computed(() => {
|
||||||
|
const arr = [NODE_DATATYPE.RESULT_IMAGE]
|
||||||
|
return arr.includes(props.node?.data?.type)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="node start">
|
|
||||||
<template v-if="type === 'InputNode'">
|
|
||||||
<Handle type="source" id="Right" :position="Position.Right" />
|
|
||||||
</template>
|
|
||||||
<template v-else-if="type === 'SecondaryNode'">
|
|
||||||
<Handle type="target" id="Left" :position="Position.Left" />
|
|
||||||
<Handle type="source" id="Right" :position="Position.Right" />
|
|
||||||
</template>
|
|
||||||
<div class="item">
|
|
||||||
<slot></slot>
|
|
||||||
</div>
|
|
||||||
<div class="add" @mousedown.stop v-if="isAdd" @click="onAdd">
|
|
||||||
<svg-icon name="add" size="14" size-unit="px" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.node {
|
.node {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
--top: 50px;
|
||||||
.vue-flow__handle {
|
.vue-flow__handle {
|
||||||
width: 5px;
|
width: 12px;
|
||||||
height: 5px;
|
height: 12px;
|
||||||
top: 50px;
|
top: var(--top);
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
background: #b5b5b5;
|
||||||
|
border: 1px solid #ffffff;
|
||||||
}
|
}
|
||||||
> .item {
|
> .item {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -63,9 +72,8 @@
|
|||||||
width: 32px;
|
width: 32px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
border: 2px solid #fff;
|
border: 2px solid #fff;
|
||||||
// bottom: -16px;
|
top: var(--top);
|
||||||
right: -16px;
|
right: -16px;
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
background-color: #ed8936;
|
background-color: #ed8936;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
@@ -78,5 +86,8 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
z-index: 20;
|
z-index: 20;
|
||||||
}
|
}
|
||||||
|
&.center {
|
||||||
|
--top: 50%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -16,10 +16,7 @@
|
|||||||
<span class="text">Edit</span>
|
<span class="text">Edit</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<img
|
<img class="image" :src="data.url" />
|
||||||
class="image"
|
|
||||||
src="https://s3-alpha-sig.figma.com/img/ea2f/590e/9638f62a2fc91e31f33db0022db1642c?Expires=1773014400&Key-Pair-Id=APKAQ4GOSFWCW27IBOMQ&Signature=M0B8oJJOk~dGG0aZAqOIocAp7T0LFdJ9FYmCrEZVTCRzYxM6SJRNtYMTX-rTO3Z~s14QINh~o-S41XiZnBv-0zcKjuWot~VVaNHfd0~1LesfNe2KwvCinT~72btFut1pheLnKE-wWCX5ewtonxU77bnw386YPMTqv7DBZzksf2udsJA7NmOYD6~TUG3Q2dWSt~zPH~lkaidscPqpCnCbqzljCEi4RiHY4U3A45l5XypcX2umqn1UaYUFCTqV9471J4qdB6Dg2pcKocdp-7-3s1De6Q~2SmBOrSgDQ~KEADCB2lhKfhxgWmy0lwMvhTd4l90ygVZDWZRABgjHNrGUvg__"
|
|
||||||
/>
|
|
||||||
<div class="more" @click="showMenu = !showMenu" @mousedown.stop>
|
<div class="more" @click="showMenu = !showMenu" @mousedown.stop>
|
||||||
<svg-icon name="more" size="24" size-unit="px" color="#C9C9C9" />
|
<svg-icon name="more" size="24" size-unit="px" color="#C9C9C9" />
|
||||||
</div>
|
</div>
|
||||||
@@ -40,10 +37,19 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref, onBeforeUnmount } from 'vue'
|
import { reactive, ref, onBeforeUnmount, useAttrs } from 'vue'
|
||||||
const showHeader = ref(true)
|
const props = defineProps({
|
||||||
|
data: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const attrs = useAttrs()
|
||||||
|
const showHeader = ref(!!attrs.node?.data?.isHeader)
|
||||||
const showMenu = ref(false)
|
const showMenu = ref(false)
|
||||||
const data = reactive({})
|
const data = reactive({
|
||||||
|
url: props.data?.url || ''
|
||||||
|
})
|
||||||
const menus = ref([
|
const menus = ref([
|
||||||
{ label: 'Copy', tip: 'Ctrl+C', on: () => {} },
|
{ label: 'Copy', tip: 'Ctrl+C', on: () => {} },
|
||||||
{ label: 'Paste', tip: 'Ctrl+V', on: () => {} },
|
{ label: 'Paste', tip: 'Ctrl+V', on: () => {} },
|
||||||
|
|||||||
@@ -11,20 +11,12 @@
|
|||||||
@node-drag-stop="(e) => eventManager.handleNodeDragStop(e)"
|
@node-drag-stop="(e) => eventManager.handleNodeDragStop(e)"
|
||||||
@viewport-change="(e) => eventManager.handleViewportChange(e)"
|
@viewport-change="(e) => eventManager.handleViewportChange(e)"
|
||||||
>
|
>
|
||||||
<template #node-InputNode="nodeProps">
|
<template v-for="v in nodeTypes" :key="v" #[`node-${v}`]="nodeProps">
|
||||||
<node type="InputNode" :stateManager="stateManager" :node="nodeProps">
|
<node :type="v" :stateManager="stateManager" :node="nodeProps">
|
||||||
<component
|
|
||||||
:is="nodeProps.data.component"
|
|
||||||
:node="nodeProps"
|
|
||||||
v-bind="nodeProps.data"
|
|
||||||
/>
|
|
||||||
</node>
|
|
||||||
</template>
|
|
||||||
<template #node-SecondaryNode="nodeProps">
|
|
||||||
<node type="SecondaryNode" :stateManager="stateManager" :node="nodeProps">
|
|
||||||
<component
|
<component
|
||||||
:is="nodeProps.data.component"
|
:is="nodeProps.data.component"
|
||||||
:node="nodeProps"
|
:node="nodeProps"
|
||||||
|
:data="nodeProps.data.data"
|
||||||
v-bind="nodeProps.data"
|
v-bind="nodeProps.data"
|
||||||
/>
|
/>
|
||||||
</node>
|
</node>
|
||||||
@@ -43,6 +35,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { VueFlow, useVueFlow } from '@vue-flow/core'
|
import { VueFlow, useVueFlow } from '@vue-flow/core'
|
||||||
import { useLayout } from '@/utils/treeDiagram'
|
import { useLayout } from '@/utils/treeDiagram'
|
||||||
|
import { NODE_TYPE } from './tools/index.d'
|
||||||
// 组件
|
// 组件
|
||||||
import headerTools from './components/header-tools.vue'
|
import headerTools from './components/header-tools.vue'
|
||||||
import zoom from '../components/zoom.vue'
|
import zoom from '../components/zoom.vue'
|
||||||
@@ -56,6 +49,7 @@
|
|||||||
import { NodeManager } from './manager/NodeManager'
|
import { NodeManager } from './manager/NodeManager'
|
||||||
|
|
||||||
const vueFlow = ref<any>()
|
const vueFlow = ref<any>()
|
||||||
|
const nodeTypes = ref([NODE_TYPE.INPUT, NODE_TYPE.SECONDARY, NODE_TYPE.OUTPUT])
|
||||||
|
|
||||||
// 状态管理器
|
// 状态管理器
|
||||||
const stateManager = new StateManager({ vueFlow })
|
const stateManager = new StateManager({ vueFlow })
|
||||||
@@ -97,11 +91,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
window.vueFlow = vueFlow
|
// window['vueFlow'] = vueFlow
|
||||||
window.nodes = nodes
|
// window['nodes'] = nodes
|
||||||
nodeManager.createResultNode()
|
nodeManager.createResultNode({
|
||||||
// nodeManager.createCardsSelect()
|
data: {
|
||||||
// nodeManager.createResultNode()
|
isHeader: false,
|
||||||
|
data: {
|
||||||
|
url: 'https://s3-alpha-sig.figma.com/img/ea2f/590e/9638f62a2fc91e31f33db0022db1642c?Expires=1773014400&Key-Pair-Id=APKAQ4GOSFWCW27IBOMQ&Signature=M0B8oJJOk~dGG0aZAqOIocAp7T0LFdJ9FYmCrEZVTCRzYxM6SJRNtYMTX-rTO3Z~s14QINh~o-S41XiZnBv-0zcKjuWot~VVaNHfd0~1LesfNe2KwvCinT~72btFut1pheLnKE-wWCX5ewtonxU77bnw386YPMTqv7DBZzksf2udsJA7NmOYD6~TUG3Q2dWSt~zPH~lkaidscPqpCnCbqzljCEi4RiHY4U3A45l5XypcX2umqn1UaYUFCTqV9471J4qdB6Dg2pcKocdp-7-3s1De6Q~2SmBOrSgDQ~KEADCB2lhKfhxgWmy0lwMvhTd4l90ygVZDWZRABgjHNrGUvg__'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ export class NodeManager {
|
|||||||
|
|
||||||
/** 删除节点 */
|
/** 删除节点 */
|
||||||
deleteNode(id: string) {
|
deleteNode(id: string) {
|
||||||
this.stateManager.nodes.value = this.stateManager.nodes.value.filter((node: any) => node.id !== id)
|
this.stateManager.deleteNode(id)
|
||||||
|
}
|
||||||
|
/** 添加节点 */
|
||||||
|
addNode(node: any) {
|
||||||
|
this.stateManager.addNode(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建节点 */
|
/** 创建节点 */
|
||||||
@@ -33,46 +37,47 @@ export class NodeManager {
|
|||||||
const position = options.position ||
|
const position = options.position ||
|
||||||
!lastNode ? { x: positionX, y: positionY } :
|
!lastNode ? { x: positionX, y: positionY } :
|
||||||
{ x: lastNode.position.x + lastNode.dimensions.width + 50 + positionX, y: lastNode.position.y + positionY }
|
{ x: lastNode.position.x + lastNode.dimensions.width + 50 + positionX, y: lastNode.position.y + positionY }
|
||||||
const data = { ...(options?.data || {}) }
|
const data = options?.data || {}
|
||||||
data['component'] = options.component
|
data['component'] = options.component
|
||||||
const options_ = {
|
const options_ = {
|
||||||
id,
|
id,
|
||||||
position,
|
position,
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
this.stateManager.nodes.value.push(options_)
|
this.addNode(options_)
|
||||||
return options_;
|
return options_;
|
||||||
}
|
}
|
||||||
/** 创建结果节点 */
|
/** 创建结果节点 */
|
||||||
createResultNode(options?: NodeOptions) {
|
createResultNode(options?: NodeOptions) {
|
||||||
const options_ = {
|
const options_ = {
|
||||||
|
...(options ? options : {}),
|
||||||
component: resultImage,
|
component: resultImage,
|
||||||
data: {
|
data: {
|
||||||
type: NODE_DATATYPE.RESULT_IMAGE,
|
type: NODE_DATATYPE.RESULT_IMAGE,
|
||||||
|
isHeader: true,
|
||||||
...(options?.data || {}),
|
...(options?.data || {}),
|
||||||
},
|
},
|
||||||
...(options ? options : {}),
|
|
||||||
}
|
}
|
||||||
return this.createNode(options_)
|
return this.createNode(options_)
|
||||||
}
|
}
|
||||||
/** 创建卡片选择节点 */
|
/** 创建卡片选择节点 */
|
||||||
createCardsSelect(options?: NodeOptions) {
|
createCardsSelect(options?: NodeOptions) {
|
||||||
const options_ = {
|
const options_ = {
|
||||||
|
...(options ? options : {}),
|
||||||
component: card,
|
component: card,
|
||||||
positionY: 50,
|
positionY: 50,
|
||||||
data: {
|
data: {
|
||||||
type: NODE_DATATYPE.CARDS_SELECT,
|
type: NODE_DATATYPE.CARDS_SELECT,
|
||||||
...(options?.data || {}),
|
...(options?.data || {}),
|
||||||
},
|
},
|
||||||
...(options ? options : {}),
|
|
||||||
}
|
}
|
||||||
return this.createNode(options_)
|
return this.createNode(options_)
|
||||||
}
|
}
|
||||||
/** 创建卡片节点 */
|
/** 创建卡片节点 */
|
||||||
createCardNode(options?: NodeOptions) {
|
createCardNode(options?: NodeOptions) {
|
||||||
const options_ = {
|
const options_ = {
|
||||||
component: card,
|
|
||||||
...(options ? options : {}),
|
...(options ? options : {}),
|
||||||
|
component: card,
|
||||||
}
|
}
|
||||||
return this.createNode(options_)
|
return this.createNode(options_)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import { ref, computed } from "vue";
|
import { ref, computed } from "vue";
|
||||||
|
import { NODE_TYPE } from '../tools/index.d'
|
||||||
|
|
||||||
|
export interface NodesItem {
|
||||||
|
id: string
|
||||||
|
type: string
|
||||||
|
class: string
|
||||||
|
position: { x: number, y: number }
|
||||||
|
data: { component: any, type: string }
|
||||||
|
}
|
||||||
export class StateManager {
|
export class StateManager {
|
||||||
vueFlow: any
|
vueFlow: any
|
||||||
nodes: any
|
nodes: any
|
||||||
@@ -18,15 +26,7 @@ export class StateManager {
|
|||||||
}
|
}
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.vueFlow = options.vueFlow
|
this.vueFlow = options.vueFlow
|
||||||
this.nodes = ref<any[]>([
|
this.nodes = ref<NodesItem[]>([]);
|
||||||
// {
|
|
||||||
// id: '8',
|
|
||||||
// type: 'SecondaryNode',
|
|
||||||
// class: 'custom-node',
|
|
||||||
// position: { x: 0, y: 0 },
|
|
||||||
// data: { component: card, type: 'edit-material' }
|
|
||||||
// }
|
|
||||||
]);
|
|
||||||
this.nodes_ = computed(() => {
|
this.nodes_ = computed(() => {
|
||||||
return this.nodes.value.map((node, index) => {
|
return this.nodes.value.map((node, index) => {
|
||||||
const obj = {
|
const obj = {
|
||||||
@@ -34,10 +34,13 @@ export class StateManager {
|
|||||||
}
|
}
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
obj.class = 'custom-node start';
|
obj.class = 'custom-node start';
|
||||||
obj.type = 'InputNode';
|
obj.type = NODE_TYPE.INPUT;
|
||||||
|
} else if (index === this.nodes.value.length - 1) {
|
||||||
|
obj.class = 'custom-node end';
|
||||||
|
obj.type = NODE_TYPE.OUTPUT;
|
||||||
} else {
|
} else {
|
||||||
obj.class = 'custom-node';
|
obj.class = 'custom-node';
|
||||||
obj.type = 'SecondaryNode';
|
obj.type = NODE_TYPE.SECONDARY;
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
})
|
})
|
||||||
@@ -53,7 +56,7 @@ export class StateManager {
|
|||||||
id: `el-${id}-${target}`,
|
id: `el-${id}-${target}`,
|
||||||
source: id,
|
source: id,
|
||||||
target: target,
|
target: target,
|
||||||
type: 'smoothstep'
|
type: 'output'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -62,6 +65,14 @@ export class StateManager {
|
|||||||
|
|
||||||
this.zoom = ref(1)
|
this.zoom = ref(1)
|
||||||
}
|
}
|
||||||
|
/** 添加节点 */
|
||||||
|
addNode(node: NodesItem) {
|
||||||
|
this.nodes.value.push(node)
|
||||||
|
}
|
||||||
|
/** 删除节点 */
|
||||||
|
deleteNode(id: string) {
|
||||||
|
this.nodes.value = this.nodes.value.filter((node: NodesItem) => node.id !== id)
|
||||||
|
}
|
||||||
getLastNode() {
|
getLastNode() {
|
||||||
return this.nodes.value[this.nodes.value.length - 1]
|
return this.nodes.value[this.nodes.value.length - 1]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* 节点类型
|
||||||
|
*/
|
||||||
|
export const NODE_TYPE = {
|
||||||
|
INPUT: 'InputNode',
|
||||||
|
SECONDARY: 'SecondaryNode',
|
||||||
|
OUTPUT: 'OutputNode',
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 节点数据类型
|
* 节点数据类型
|
||||||
*/
|
*/
|
||||||
|
|||||||
20
src/ignoredWarning.ts
Normal file
20
src/ignoredWarning.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// 定义要忽略的警告关键词列表
|
||||||
|
const ignoredWarnings = [
|
||||||
|
'`markRaw` or using `shallowRef` instead of `ref`',
|
||||||
|
]
|
||||||
|
|
||||||
|
/** 忽略组件响应式警告 */
|
||||||
|
export default function (app) {
|
||||||
|
// 只忽略组件响应式警告
|
||||||
|
app.config.warnHandler = (msg, instance, trace) => {
|
||||||
|
// 检查是否包含要忽略的关键词
|
||||||
|
const shouldIgnore = ignoredWarnings.some(warning =>
|
||||||
|
msg.includes(warning)
|
||||||
|
)
|
||||||
|
// 如果不应该忽略,才输出警告
|
||||||
|
if (!shouldIgnore) {
|
||||||
|
console.warn(msg, instance, trace)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,7 +15,11 @@ import "./router/router-config" // 路由守卫,做动态路由的地方
|
|||||||
import ElementPlus from 'element-plus'
|
import ElementPlus from 'element-plus'
|
||||||
import 'element-plus/dist/index.css'
|
import 'element-plus/dist/index.css'
|
||||||
|
|
||||||
|
import ignoredWarning from './ignoredWarning'
|
||||||
|
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
ignoredWarning(app)
|
||||||
app.use(router)
|
app.use(router)
|
||||||
.use(ElementPlus)
|
.use(ElementPlus)
|
||||||
.use(store)
|
.use(store)
|
||||||
|
|||||||
Reference in New Issue
Block a user