Files
auto-solution/modeler/src/views/decision/builder/node.vue

321 lines
7.9 KiB
Vue
Raw Normal View History

2026-02-08 15:59:14 +08:00
<template>
<a-dropdown :trigger="['contextmenu']" @openChange="handleVisibleChange">
2026-02-08 17:57:40 +08:00
<a-card
:class="[
'ks-designer-node',
`ks-designer-${element?.category ?? 'model'}-node`
]"
hoverable
>
2026-02-08 15:59:14 +08:00
<template #title>
2026-02-08 17:57:40 +08:00
<a-space>
2026-02-08 20:57:07 +08:00
<div class="port port-in" data-port="in-0" magnet="passive"></div>
2026-02-08 17:57:40 +08:00
<span class="ks-designer-node-title">{{ element?.name ?? '-' }}</span>
2026-02-08 20:57:07 +08:00
<div class="port port-out" data-port="out-0" magnet="active"></div>
2026-02-08 17:57:40 +08:00
</a-space>
2026-02-08 15:59:14 +08:00
</template>
2026-02-08 17:57:40 +08:00
2026-02-08 15:59:14 +08:00
<div class="w-full">
2026-02-08 20:57:07 +08:00
<a-tooltip>
<template #title>
2026-02-08 22:31:13 +08:00
{{ element?.description ?? element?.name }}
2026-02-08 20:57:07 +08:00
</template>
2026-02-08 21:36:39 +08:00
<p>
2026-02-08 22:31:13 +08:00
{{ substring(element?.description ?? (element?.name ?? '-'), 40) }}
2026-02-08 21:36:39 +08:00
</p>
2026-02-08 20:57:07 +08:00
</a-tooltip>
2026-02-08 15:59:14 +08:00
</div>
</a-card>
2026-02-08 17:57:40 +08:00
2026-02-08 15:59:14 +08:00
<template #overlay>
<a-menu @click="handleMenuClick">
<a-menu-item key="delete">
<template #icon>
<DeleteOutlined />
</template>
删除
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
<script lang="ts">
import { defineComponent, onMounted, onUnmounted, ref } from 'vue';
import { elementProps } from './props';
2026-02-08 17:57:40 +08:00
import type { ModelElement } from './element';
2026-02-08 15:59:14 +08:00
import { DeleteOutlined, SettingOutlined } from '@ant-design/icons-vue';
import type { Graph } from '@antv/x6';
2026-02-08 22:31:13 +08:00
import { substring } from '@/utils/strings';
2026-02-08 15:59:14 +08:00
export default defineComponent({
2026-02-08 17:57:40 +08:00
name: 'ModelElement',
2026-02-08 15:59:14 +08:00
components: {
SettingOutlined,
DeleteOutlined,
},
props: elementProps,
setup(_props) {
2026-02-08 17:57:40 +08:00
const element = ref<ModelElement | null>(
_props.node ? (_props.node.getData() as ModelElement) : null,
2026-02-08 15:59:14 +08:00
);
const updateKey = ref(0);
const isMenuVisible = ref(false);
2026-02-08 17:57:40 +08:00
// 获取画布实例
2026-02-08 15:59:14 +08:00
const getGraph = (): Graph | null => {
return _props.graph as Graph || null;
};
2026-02-08 17:57:40 +08:00
// 监听节点数据变化
2026-02-08 15:59:14 +08:00
const handleDataChange = () => {
if (_props.node) {
2026-02-08 17:57:40 +08:00
element.value = _props.node.getData() as ModelElement;
2026-02-08 15:59:14 +08:00
} else {
element.value = null;
}
updateKey.value++;
};
const handleVisibleChange = (visible: boolean) => {
isMenuVisible.value = visible;
};
const handleMenuClick = ({ key }: { key: string }) => {
if (key === 'delete') {
handleDelete();
}
};
const handleDelete = () => {
if (!_props.node) return;
const graph = getGraph();
if (graph) {
try {
2026-02-08 17:57:40 +08:00
// 先删除关联边
2026-02-08 15:59:14 +08:00
const connectedEdges = graph.getConnectedEdges(_props.node);
2026-02-08 17:57:40 +08:00
connectedEdges.forEach(edge => graph.removeEdge(edge));
// 再删除节点
2026-02-08 15:59:14 +08:00
graph.removeNode(_props.node);
console.info(`节点 ${_props.node.id} 已删除`);
} catch (error) {
console.error('删除节点失败:', error);
}
}
isMenuVisible.value = false;
};
onMounted(() => {
_props.node?.on('change:data', handleDataChange);
});
onUnmounted(() => {
_props.node?.off('change:data', handleDataChange);
});
return {
element,
2026-02-08 20:57:07 +08:00
substring,
2026-02-08 15:59:14 +08:00
handleMenuClick,
handleVisibleChange,
};
},
});
</script>
<style lang="less">
.ks-designer-node {
2026-02-09 14:53:05 +08:00
background: linear-gradient(150deg, rgba(108, 99, 255) 1%, rgba(108, 99, 255) 100%);
2026-02-08 17:57:40 +08:00
border-radius: 8px;
2026-02-08 15:59:14 +08:00
width: 100%;
height: 100%;
cursor: pointer;
2026-02-08 22:31:13 +08:00
position: relative;
2026-02-09 14:53:05 +08:00
background: #1e2533;
border: 1px solid #4a7aff;
&:hover {
border: 1px solid #4a7aff;
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
}
2026-02-08 15:59:14 +08:00
.ant-card-head {
border: 0;
2026-02-08 17:57:40 +08:00
height: 38px;
min-height: 38px;
2026-02-08 15:59:14 +08:00
border-radius: 0;
2026-02-09 14:53:05 +08:00
color: #fff;
2026-02-08 15:59:14 +08:00
font-size: 12px;
font-weight: normal;
2026-02-08 17:57:40 +08:00
padding: 0 20px;
2026-02-09 14:53:05 +08:00
background: linear-gradient(to bottom, #3a4c70, #2d3a56);
border-top-left-radius: 8px;
border-top-right-radius: 8px;
background: linear-gradient(to bottom, rgba(108, 99, 255, 0.15), rgba(108, 99, 255, 0.05));
2026-02-09 15:04:34 +08:00
background: url('@/assets/icons/bg-node-head.png') center / 100% 100%;
2026-02-09 14:53:05 +08:00
//background: linear-gradient(to bottom, rgb(234 234 234 / 20%), rgb(191 191 191 / 58%));
2026-02-08 17:57:40 +08:00
}
.ks-designer-node-icon {
width: 15px;
height: 15px;
display: block;
position: absolute;
left: 8px;
top: 13px;
background: url('@/assets/icons/model-4.svg') center / 100% 100%;
}
.ks-designer-node-title {
font-size: 13px;
2026-02-09 14:53:05 +08:00
color: #fff;
2026-02-09 15:04:34 +08:00
color: #312e2e;
2026-02-08 15:59:14 +08:00
}
.ant-card-body {
2026-02-09 14:53:05 +08:00
color: #f5f5f5;
2026-02-08 17:57:40 +08:00
height: calc(100% - 38px);
2026-02-08 15:59:14 +08:00
border-radius: 0;
font-size: 12px;
2026-02-08 17:57:40 +08:00
padding: 8px 15px;
2026-02-09 14:53:05 +08:00
border-top: 1px solid rgba(108, 99, 255, 0.5);
2026-02-08 20:57:07 +08:00
overflow: hidden;
2026-02-08 21:36:39 +08:00
text-overflow: ellipsis;
white-space: nowrap;
2026-02-09 14:53:05 +08:00
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
2026-02-08 15:59:14 +08:00
}
2026-02-09 14:53:05 +08:00
// model/task 节点:浅紫渐变
//&.ks-designer-model-node,
//&.ks-designer-task-node {
// background: linear-gradient(150deg, rgba(92,84,247,0.9) 1%, rgba(115,108,250,0.7) 55%);
//
// .ant-card-body {
// border-top: 1px solid rgba(92,84,247,0.5);
// }
//
// .ks-designer-node-icon {
// background: url('@/assets/icons/m-02.png') center / 100% 100%;
// }
//}
//
//// input 节点:深紫渐变
//&.ks-designer-input-node {
// background: linear-gradient(150deg, rgba(82,73,245,0.9) 1%, rgba(105,98,249,0.7) 55%);
//
// .ant-card-body {
// border-top: 1px solid rgba(82,73,245,0.5);
// }
//
// .ks-designer-node-icon {
// background: url('@/assets/icons/icon-model-input.png') center / 100% 100%;
// }
//}
//
//// action 节点亮紫渐变对应之前的action-node
//&.ks-designer-action-node {
// background: linear-gradient(150deg, rgba(108,99,255,0.9) 1%, rgba(140,133,255,0.7) 55%);
//
// .ant-card-body {
// border-top: 1px solid rgba(108,99,255,0.5);
// }
//
// .ks-designer-node-icon {
// background: url('@/assets/icons/bg-fk-point.png') center / 100% 100%;
// }
//}
//
//// precondition/component 节点:蓝紫渐变
//&.ks-designer-precondition-node,
//&.ks-designer-component-node {
// background: linear-gradient(150deg, rgba(72,64,243,0.9) 1%, rgba(95,88,248,0.7) 55%);
//
// .ant-card-body {
// border-top: 1px solid rgba(72,64,243,0.5);
// }
//}
//
//// select/control 节点:浅蓝紫渐变
//&.ks-designer-select-node,
//&.ks-designer-control-node {
// background: linear-gradient(150deg, rgba(90,82,246,0.9) 1%, rgba(118,111,251,0.7) 55%);
//
// .ant-card-body {
// border-top: 1px solid rgba(90,82,246,0.5);
// }
//
// .ks-designer-node-icon {
// background: url('@/assets/icons/bg-model-builder-card-title.png') center / 100% 100%;
// }
//}
2026-02-08 15:59:14 +08:00
2026-02-08 17:57:40 +08:00
// 连接桩容器样式
.ks-designer-node-content {
width: 100%;
display: flex;
flex-direction: column;
2026-02-09 14:53:05 +08:00
gap: 4px;
2026-02-08 17:57:40 +08:00
}
.ks-designer-node-row {
width: 100%;
display: flex;
align-items: center;
position: relative;
2026-02-09 14:53:05 +08:00
min-height: 24px;
2026-02-08 17:57:40 +08:00
}
.port {
width: 12px;
height: 12px;
border-radius: 50%;
cursor: crosshair;
flex-shrink: 0;
2026-02-09 14:53:05 +08:00
box-shadow: 0 0 0 2px rgb(108, 99, 255, 0.8);
z-index: 10;
2026-02-08 17:57:40 +08:00
magnet: true;
}
// 左侧入桩样式
.port-in {
2026-02-09 14:53:05 +08:00
background-color: #6C63FF;
margin-right: 8px;
2026-02-08 17:57:40 +08:00
//border: 1px solid #093866;
magnet: passive;
box-shadow: none;
2026-02-08 22:16:22 +08:00
width: 15px;
height: 15px;
2026-02-08 17:57:40 +08:00
display: block;
background: url('@/assets/icons/point.svg') center / 100% 100%;
2026-02-08 20:57:07 +08:00
position: absolute;
left: 5px;
2026-02-08 22:16:22 +08:00
top: 12px;
2026-02-08 17:57:40 +08:00
}
.port-out {
2026-02-09 14:53:05 +08:00
margin-left: 8px;
2026-02-08 17:57:40 +08:00
margin-right: 5px;
magnet: active;
box-shadow: none;
2026-02-08 22:16:22 +08:00
width: 15px;
height: 15px;
2026-02-08 17:57:40 +08:00
display: block;
2026-02-08 22:16:22 +08:00
background: url('@/assets/icons/point.svg') center / 100% 100%;
2026-02-08 20:57:07 +08:00
position: absolute;
right: 5px;
2026-02-08 22:16:22 +08:00
top: 12px;
2026-02-08 17:57:40 +08:00
}
// 节点文本样式
.ks-designer-node-name {
2026-02-09 14:53:05 +08:00
flex: 1;
2026-02-08 17:57:40 +08:00
line-height: 24px;
overflow: hidden;
text-overflow: ellipsis;
2026-02-08 20:57:07 +08:00
//white-space: nowrap;
2026-02-08 17:57:40 +08:00
}
}
2026-02-08 15:59:14 +08:00
</style>