This commit is contained in:
lzp
2026-02-27 14:58:36 +08:00
parent e2e1bcf322
commit 43ea391a75
10 changed files with 159 additions and 90 deletions

View File

@@ -14,6 +14,7 @@
import { ref, inject } from 'vue'
import { NODE_DATATYPE } from '../../tools/index.d'
const nodeManager = inject('nodeManager') as any
const stateManager = inject('stateManager') as any
const props = defineProps({
node: { required: true, type: Object }
})
@@ -46,9 +47,10 @@
const onClickItem = (v) => {
const id = props.node.id
if (!id) return
nodeManager.deleteNode(id)
stateManager.deleteNode(id)
nodeManager.createCardNode({ data: { type: v.type } })
}
defineExpose({})
</script>

View File

@@ -23,7 +23,7 @@
</template>
<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 ToRealStyle from './to-real-style.vue'
import SurfaceEdit from './surface-edit.vue'
@@ -32,9 +32,9 @@
import To3View from './to-3view.vue'
import To3DModel from './to-3d-model.vue'
import ToVideo from './to-video.vue'
import AddPrint from './add-print.vue'
import ToCAD from './to-cad.vue'
// import ToVideo from './to-video.vue'
// import AddPrint from './add-print.vue'
// import ToCAD from './to-cad.vue'
const components = [
{
type: 'cards-select',
@@ -73,23 +73,8 @@
title: 'To 3D Model',
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({
type: {
type: String as () =>
@@ -101,6 +86,10 @@
| 'to-3d-model'
| 'to-3view',
default: 'to-real-style'
},
data: {
type: Object,
default: () => ({})
}
})
const attrs = useAttrs()
@@ -111,8 +100,21 @@
const onGenerateClick = () => {
const data = { ...componentRef.value.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>
<style lang="less" scoped>

View File

@@ -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>
import { Handle, Position } from '@vue-flow/core'
import { NODE_TYPE } from '../tools/index.d'
import { NODE_DATATYPE } from '../tools/index.d'
import { computed } from 'vue'
const props = defineProps({
type: {
type: String as () => 'InputNode' | 'SecondaryNode',
type: String,
default: 'InputNode'
},
node: {
@@ -19,41 +40,29 @@
const nodes = computed(() => props.stateManager.nodes.value)
const firstNode = computed(() => nodes.value[0])
const lastNode = computed(() => nodes.value[nodes.value.length - 1])
const notAddNodeTypes = [NODE_DATATYPE.CARDS_SELECT]
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 = () => {
props.stateManager.nodeManager.createCardsSelect()
}
const posCenter = computed(() => {
const arr = [NODE_DATATYPE.RESULT_IMAGE]
return arr.includes(props.node?.data?.type)
})
</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>
.node {
position: relative;
--top: 50px;
.vue-flow__handle {
width: 5px;
height: 5px;
top: 50px;
width: 12px;
height: 12px;
top: var(--top);
z-index: 10;
background: #b5b5b5;
border: 1px solid #ffffff;
}
> .item {
position: relative;
@@ -63,9 +72,8 @@
width: 32px;
height: 32px;
border: 2px solid #fff;
// bottom: -16px;
top: var(--top);
right: -16px;
top: 50%;
transform: translateY(-50%);
background-color: #ed8936;
border-radius: 50%;
@@ -78,5 +86,8 @@
cursor: pointer;
z-index: 20;
}
&.center {
--top: 50%;
}
}
</style>

View File

@@ -16,10 +16,7 @@
<span class="text">Edit</span>
</button>
</div>
<img
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__"
/>
<img class="image" :src="data.url" />
<div class="more" @click="showMenu = !showMenu" @mousedown.stop>
<svg-icon name="more" size="24" size-unit="px" color="#C9C9C9" />
</div>
@@ -40,10 +37,19 @@
</template>
<script setup lang="ts">
import { reactive, ref, onBeforeUnmount } from 'vue'
const showHeader = ref(true)
import { reactive, ref, onBeforeUnmount, useAttrs } from 'vue'
const props = defineProps({
data: {
type: Object,
default: () => ({})
}
})
const attrs = useAttrs()
const showHeader = ref(!!attrs.node?.data?.isHeader)
const showMenu = ref(false)
const data = reactive({})
const data = reactive({
url: props.data?.url || ''
})
const menus = ref([
{ label: 'Copy', tip: 'Ctrl+C', on: () => {} },
{ label: 'Paste', tip: 'Ctrl+V', on: () => {} },

View File

@@ -11,20 +11,12 @@
@node-drag-stop="(e) => eventManager.handleNodeDragStop(e)"
@viewport-change="(e) => eventManager.handleViewportChange(e)"
>
<template #node-InputNode="nodeProps">
<node type="InputNode" :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">
<template v-for="v in nodeTypes" :key="v" #[`node-${v}`]="nodeProps">
<node :type="v" :stateManager="stateManager" :node="nodeProps">
<component
:is="nodeProps.data.component"
:node="nodeProps"
:data="nodeProps.data.data"
v-bind="nodeProps.data"
/>
</node>
@@ -43,6 +35,7 @@
<script setup lang="ts">
import { VueFlow, useVueFlow } from '@vue-flow/core'
import { useLayout } from '@/utils/treeDiagram'
import { NODE_TYPE } from './tools/index.d'
// 组件
import headerTools from './components/header-tools.vue'
import zoom from '../components/zoom.vue'
@@ -56,6 +49,7 @@
import { NodeManager } from './manager/NodeManager'
const vueFlow = ref<any>()
const nodeTypes = ref([NODE_TYPE.INPUT, NODE_TYPE.SECONDARY, NODE_TYPE.OUTPUT])
// 状态管理器
const stateManager = new StateManager({ vueFlow })
@@ -97,11 +91,16 @@
}
onMounted(() => {
window.vueFlow = vueFlow
window.nodes = nodes
nodeManager.createResultNode()
// nodeManager.createCardsSelect()
// nodeManager.createResultNode()
// window['vueFlow'] = vueFlow
// window['nodes'] = nodes
nodeManager.createResultNode({
data: {
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>
<style lang="less">

View File

@@ -21,7 +21,11 @@ export class NodeManager {
/** 删除节点 */
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 ||
!lastNode ? { x: positionX, 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
const options_ = {
id,
position,
data
}
this.stateManager.nodes.value.push(options_)
this.addNode(options_)
return options_;
}
/** 创建结果节点 */
createResultNode(options?: NodeOptions) {
const options_ = {
...(options ? options : {}),
component: resultImage,
data: {
type: NODE_DATATYPE.RESULT_IMAGE,
isHeader: true,
...(options?.data || {}),
},
...(options ? options : {}),
}
return this.createNode(options_)
}
/** 创建卡片选择节点 */
createCardsSelect(options?: NodeOptions) {
const options_ = {
...(options ? options : {}),
component: card,
positionY: 50,
data: {
type: NODE_DATATYPE.CARDS_SELECT,
...(options?.data || {}),
},
...(options ? options : {}),
}
return this.createNode(options_)
}
/** 创建卡片节点 */
createCardNode(options?: NodeOptions) {
const options_ = {
component: card,
...(options ? options : {}),
component: card,
}
return this.createNode(options_)
}

View File

@@ -1,5 +1,13 @@
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 {
vueFlow: any
nodes: any
@@ -18,15 +26,7 @@ export class StateManager {
}
constructor(options) {
this.vueFlow = options.vueFlow
this.nodes = ref<any[]>([
// {
// id: '8',
// type: 'SecondaryNode',
// class: 'custom-node',
// position: { x: 0, y: 0 },
// data: { component: card, type: 'edit-material' }
// }
]);
this.nodes = ref<NodesItem[]>([]);
this.nodes_ = computed(() => {
return this.nodes.value.map((node, index) => {
const obj = {
@@ -34,10 +34,13 @@ export class StateManager {
}
if (index === 0) {
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 {
obj.class = 'custom-node';
obj.type = 'SecondaryNode';
obj.type = NODE_TYPE.SECONDARY;
}
return obj
})
@@ -53,7 +56,7 @@ export class StateManager {
id: `el-${id}-${target}`,
source: id,
target: target,
type: 'smoothstep'
type: 'output'
})
}
})
@@ -62,6 +65,14 @@ export class StateManager {
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() {
return this.nodes.value[this.nodes.value.length - 1]
}

View File

@@ -1,3 +1,12 @@
/**
* 节点类型
*/
export const NODE_TYPE = {
INPUT: 'InputNode',
SECONDARY: 'SecondaryNode',
OUTPUT: 'OutputNode',
}
/**
* 节点数据类型
*/
@@ -10,4 +19,4 @@ export const NODE_DATATYPE = {
COLOR_PALETTE: 'color-palette',
TO_3VIEW: 'to-3view',
TO_3D_MODEL: 'to-3d-model',
}
}