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

427 lines
10 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="[
2026-03-15 19:32:20 +08:00
'ks-scenario-node',
`ks-scenario-${element?.category ?? 'model'}-node`,
`ks-scenario-group-${element?.group ?? 'general'}`
2026-02-08 17:57:40 +08:00
]"
hoverable
>
2026-02-08 15:59:14 +08:00
<template #title>
2026-02-08 17:57:40 +08:00
<a-space>
2026-03-15 19:32:20 +08:00
<span class="ks-scenario-node-title">{{ element?.name ?? '-' }}</span>
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-03-14 18:08:20 +08:00
<div class="port port-in" data-port="in-0" magnet="passive">
<div class="triangle-left"></div>
2026-03-13 10:15:14 +08:00
</div>
2026-03-15 19:32:20 +08:00
<div class="w-full ks-scenario-node-text">
2026-03-14 18:08:20 +08:00
<a-tooltip >
2026-02-08 20:57:07 +08:00
<template #title>
2026-02-08 22:31:13 +08:00
{{ element?.description ?? element?.name }}
2026-02-08 20:57:07 +08:00
</template>
2026-03-15 19:32:20 +08:00
<p class="ks-scenario-node-label">
2026-03-14 18:08:20 +08:00
{{ substring(element?.name ?? (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>
2026-03-14 18:08:20 +08:00
<div class="port port-out" data-port="out-0" magnet="active">
<div class="triangle-right" ></div>
2026-03-13 10:15:14 +08:00
</div>
2026-02-08 15:59:14 +08:00
</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';
2026-03-15 19:32:20 +08:00
import { elementProps, type ModelElement } from '../graph';
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">
2026-03-15 19:32:20 +08:00
.ks-scenario-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;
2026-02-09 19:53:17 +08:00
border: 2px solid #000000;
2026-02-09 14:53:05 +08:00
&:hover {
2026-02-09 19:53:17 +08:00
border: 2px solid #4a7aff;
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
.ant-card-head {
border: 0;
2026-03-13 10:15:14 +08:00
height: 28px;
2026-02-09 19:53:17 +08:00
min-height: 25px;
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-03-13 10:15:14 +08:00
//background: linear-gradient(to bottom, #3a4c70, #2d3a56);
2026-02-09 14:53:05 +08:00
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-03-13 10:15:14 +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
}
2026-03-15 19:32:20 +08:00
.ks-scenario-node-icon {
2026-02-08 17:57:40 +08:00
width: 15px;
height: 15px;
display: block;
position: absolute;
left: 8px;
2026-03-13 10:15:14 +08:00
top: 6px;
background: url('@/assets/icons/icon-node.svg') center / 100% 100%;
2026-02-08 17:57:40 +08:00
}
2026-03-15 19:32:20 +08:00
.ks-scenario-node-title {
2026-03-13 10:15:14 +08:00
font-size: 12px;
2026-02-09 14:53:05 +08:00
color: #fff;
2026-03-13 10:15:14 +08:00
margin-top: -7px;
display: block;
2026-02-08 15:59:14 +08:00
}
.ant-card-body {
2026-02-09 14:53:05 +08:00
color: #f5f5f5;
2026-02-09 19:53:17 +08:00
height: calc(100% - 25px);
2026-02-08 15:59:14 +08:00
border-radius: 0;
font-size: 12px;
2026-03-13 10:40:44 +08:00
padding: 10px 30px !important;
2026-03-13 17:05:08 +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-09 15:35:20 +08:00
white-space: normal; // 恢复默认的换行行为
word-wrap: break-word; // 允许长单词换行
word-break: break-all; // 允许在任意字符处换行
line-height: 1.4; // 增加行高提升可读性
box-shadow: 0 0 10px rgba(74, 122, 255, 0.3);
2026-02-08 15:59:14 +08:00
}
2026-02-08 17:57:40 +08:00
// 连接桩容器样式
2026-03-15 19:32:20 +08:00
.ks-scenario-node-content {
2026-02-08 17:57:40 +08:00
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
}
2026-03-15 19:32:20 +08:00
.ks-scenario-node-row {
2026-02-08 17:57:40 +08:00
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;
2026-03-13 10:15:14 +08:00
position: relative;
.triangle-left {
width: 0;
height: 0;
2026-03-13 17:05:08 +08:00
border-top: 4px solid transparent;
border-right: 5px solid #5da1df;
border-bottom: 4px solid transparent;
2026-03-13 10:15:14 +08:00
position: absolute;
left: -8px;
2026-03-13 17:05:08 +08:00
top: 0.5px;
magnet: passive;
2026-03-13 10:15:14 +08:00
}
/* 右三角形 */
.triangle-right {
width: 0;
height: 0;
2026-03-13 17:05:08 +08:00
border-top: 4px solid transparent;
border-left: 5px solid #5da1df;
border-bottom: 4px solid transparent;
2026-03-13 10:15:14 +08:00
position: absolute;
right: -8px;
2026-03-13 17:05:08 +08:00
top: 0.5px;
magnet: passive;
2026-03-13 10:15:14 +08:00
}
2026-02-08 17:57:40 +08:00
}
// 左侧入桩样式
.port-in {
2026-03-13 17:05:08 +08:00
//background-color: #3c82f6;
2026-02-09 14:53:05 +08:00
margin-right: 8px;
2026-02-08 17:57:40 +08:00
//border: 1px solid #093866;
magnet: passive;
box-shadow: none;
2026-03-13 17:05:08 +08:00
width: 13px;
height: 13px;
2026-02-08 17:57:40 +08:00
display: block;
2026-03-13 17:05:08 +08:00
//background: url('@/assets/icons/point.svg') center / 100% 100%;
border: 2px solid #5da1df;
2026-02-08 20:57:07 +08:00
position: absolute;
2026-02-09 19:53:17 +08:00
//top: 7px;
2026-03-13 10:15:14 +08:00
left: 10px;
2026-02-09 19:53:17 +08:00
top: 50%;
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-03-13 17:05:08 +08:00
width: 13px;
height: 13px;
2026-02-08 17:57:40 +08:00
display: block;
2026-03-13 17:05:08 +08:00
//background: url('@/assets/icons/point.svg') center / 100% 100%;
border: 2px solid #5da1df;
background:#5da1df;
2026-02-08 20:57:07 +08:00
position: absolute;
2026-02-09 19:53:17 +08:00
//right: 8px;
//top: 7px;
top: 50%;
2026-03-13 10:15:14 +08:00
right: 6px;
2026-02-09 19:53:17 +08:00
2026-02-08 17:57:40 +08:00
}
// 节点文本样式
2026-03-15 19:32:20 +08:00
.ks-scenario-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-03-13 10:15:14 +08:00
2026-03-15 19:32:20 +08:00
&.ks-scenario-root-node{
.ks-scenario-node-icon {
2026-03-13 10:15:14 +08:00
background: url('@/assets/icons/icon-root.svg') center / 100% 100%;
}
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-action-node{
2026-03-13 10:15:14 +08:00
.ant-card-head {
background: url('@/assets/icons/card-head-red.png') center / 100% 100%;
}
2026-03-15 19:32:20 +08:00
.ks-scenario-node-icon {
2026-03-13 10:15:14 +08:00
background: url('@/assets/icons/icon-action.svg') center / 100% 100%;
}
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-sequence-node{
.ks-scenario-node-icon {
2026-03-13 10:15:14 +08:00
background: url('@/assets/icons/icon-sequence.svg') center / 100% 100%;
}
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-parallel-node{
.ks-scenario-node-icon {
2026-03-13 10:15:14 +08:00
background: url('@/assets/icons/icon-parallel.svg') center / 100% 100%;
}
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-precondition-node{
.ks-scenario-node-icon {
2026-03-13 10:15:14 +08:00
background: url('@/assets/icons/icon-branch.svg') center / 100% 100%;
}
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-group-control,
&.ks-scenario-group-condition {
2026-03-13 17:05:08 +08:00
.ant-card-head{
display:none;
}
.ant-card-body {
height: calc(100%);
border-radius: 8px;
background: url('@/assets/icons/card-head-gray.png') center / 100% 100%;
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-root-node{
2026-03-13 17:05:08 +08:00
.ant-card-body {
background: url('@/assets/icons/card-head-dark.png') center / 100% 100%;
}
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-sequence-node{
2026-03-13 17:05:08 +08:00
.ant-card-body {
background: url('@/assets/icons/card-head-green.png') center / 100% 100%;
}
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-parallel-node{
2026-03-13 17:05:08 +08:00
.ant-card-body {
background: url('@/assets/icons/card-head-blue.png') center / 100% 100%;
}
}
2026-03-15 19:32:20 +08:00
&.ks-scenario-precondition-node{
2026-03-13 17:05:08 +08:00
.ant-card-body {
background: url('@/assets/icons/card-head-dark.png') center / 100% 100%;
}
}
.port-in,
.port-out {
top: 40%;
}
2026-03-15 19:32:20 +08:00
.ks-scenario-node-text{
2026-03-13 17:05:08 +08:00
line-height: 38px;
}
}
2026-03-15 19:32:20 +08:00
//&.ks-scenario-precondition-node{
2026-03-13 10:15:14 +08:00
// border:0;
// box-shadown:none;
// &:hover{
// border:0;
// box-shadown:none;
// }
// background: url('@/assets/icons/lx.svg') center / 100% 100%;
// //transform: rotate(45deg);
// .ant-card-body {
// border: 0;
// box-shadow: none;
// height: 95px;
// line-height: 80px;
// font-size: 10px;
// padding: 0 !important;
// }
// .ant-card-head {
// display: none;
// }
//
2026-03-15 19:32:20 +08:00
// .ks-scenario-node-label {
2026-03-13 10:15:14 +08:00
// width: 40px; /* 保留原有宽度 */
// text-align: center; /* 保留文字居中 */
// /* 核心修改:取消固定行高,重置换行相关属性 */
// word-wrap: break-word;/* 强制换行(兼容老旧浏览器) */
// word-break: break-all;/* 截断长单词/字符确保在40px内换行 */
// white-space: normal; /* 恢复默认换行规则(避免文字不换行) */
// /* 可选:添加行间距,提升多行可读性 */
// line-height: 1.4; /* 多行时的行间距,可根据需求调整 */
// padding: 10px 0; /* 上下内边距替代原有line-height:98px的垂直居中效果 */
// margin: 31% auto;
// }
//
// .port-in {
// left: 12px;
// top: 42px;
// }
//
// .port-out {
// right: 6px;
// top: 42px;
// }
//}
2026-02-08 17:57:40 +08:00
}
2026-02-08 15:59:14 +08:00
</style>