添加分析设计页面

This commit is contained in:
limengnan 2026-01-13 15:11:39 +08:00
parent a4a8ed9535
commit f7238eaf63
23 changed files with 1896 additions and 6 deletions

View File

@ -10,6 +10,8 @@
"prettier": "prettier --write ."
},
"dependencies": {
"@antv/g6": "^5.0.51",
"@antv/x6": "^3.1.4",
"@element-plus/icons-vue": "^2.0.10",
"@types/js-cookie": "^3.0.2",
"@vueuse/core": "^9.1.1",
@ -20,6 +22,7 @@
"default-passive-events": "^2.0.0",
"echarts": "^5.2.2",
"element-plus": "^2.2.27",
"insert-css": "^2.0.0",
"js-base64": "^3.7.5",
"js-cookie": "^3.0.1",
"jsencrypt": "^3.3.2",

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

View File

@ -0,0 +1,244 @@
<!-- components/GraphCanvas.vue -->
<script setup lang="ts">
import { onMounted, ref, onBeforeUnmount } from 'vue';
import { Graph, registerNode, Brush } from '@antv/g6';
import { NodeItem, NodeType } from '@/types/graph';
//
const NODE_LABEL_MAP: Record<NodeType, string> = {
cylinder_slot: '圆柱槽',
flat_slot: '扁平槽',
ring_slot: '环形槽',
tube_slot: '管形槽',
bar_stock: '棒料',
tapered_head: '锥形头',
monk_ring_slot: '僧帽环形槽',
};
// G6 type
const registerCustomNode = () => {
registerNode(
'custom-mechanical-node',
{
draw: (cfg, group) => {
const type = cfg?.type as NodeType;
let shape, color;
//
switch (type) {
case 'cylinder_slot':
shape = group!.addShape('ellipse', {
attrs: {
x: 0,
y: 0,
rx: 40,
ry: 20,
fill: '#ffeaa7',
stroke: '#fab1a0',
lineWidth: 1.5,
},
});
break;
case 'flat_slot':
shape = group!.addShape('rect', {
attrs: {
x: -50,
y: -15,
width: 100,
height: 30,
fill: '#fdcb6e',
stroke: '#e17055',
radius: 4,
lineWidth: 1.5,
},
});
break;
case 'ring_slot':
shape = group!.addShape('circle', {
attrs: {
x: 0,
y: 0,
r: 30,
fill: '#a29bfe',
stroke: '#6c5ce7',
lineWidth: 2,
shadowBlur: 4,
shadowColor: 'rgba(108, 92, 231, 0.3)',
},
});
break;
case 'tube_slot':
shape = group!.addShape('path', {
attrs: {
path:
'M -40 -20 L 40 -20 C 50 -20 50 20 40 20 L -40 20 C -50 20 -50 -20 -40 -20 Z M -30 -10 L 30 -10 L 30 10 L -30 10 Z',
fill: '#7bed9f',
stroke: '#00b894',
lineWidth: 1,
},
});
break;
case 'bar_stock':
shape = group!.addShape('rect', {
attrs: {
x: -45,
y: -10,
width: 90,
height: 20,
fill: '#fab1a0',
stroke: '#d63031',
lineWidth: 1.2,
},
});
break;
case 'tapered_head':
shape = group!.addShape('path', {
attrs: {
path: 'M -40 20 L 0 -25 L 40 20 L 20 20 L 0 -5 L -20 20 Z',
fill: '#fd79a8',
stroke: '#e84393',
lineWidth: 1.5,
},
});
break;
case 'monk_ring_slot':
shape = group!.addShape('path', {
attrs: {
path:
'M -35 20 C -35 10, -25 -25, 0 -25 C 25 -25, 35 10, 35 20 C 35 20, 25 -10, 0 -10 C -25 -10, -35 20, -35 20 Z',
fill: '#6c5ce7',
stroke: '#55efc4',
lineWidth: 2,
},
});
break;
default:
shape = group!.addShape('circle', {
attrs: {
x: 0,
y: 0,
r: 20,
fill: '#ccc',
stroke: '#999',
},
});
}
//
group!.addShape('text', {
attrs: {
text: NODE_LABEL_MAP[type] || '未知',
x: 0,
y: 40,
fontSize: 12,
textAlign: 'center',
textBaseline: 'middle',
fill: '#555',
},
});
return shape!;
},
},
'single-shape'
);
};
let graph: Graph | null = null;
const container = ref<HTMLDivElement>();
onMounted(() => {
if (!container.value) return;
//
registerCustomNode();
// G6
graph = new Graph({
container: container.value!,
width: container.value.offsetWidth,
height: container.value.offsetHeight,
fitView: true,
fitViewPadding: 40,
//
defaultNode: {
shape: 'custom-mechanical-node',
size: [80, 40],
},
//
modes: {
default: [
'drag-canvas', //
'zoom-canvas', //
'drag-node', //
],
},
// Brush
plugins: [
new Brush({
brushType: 'rect', //
onSelect: (items) => {
console.log('Selected items:', items.map((i) => i.getModel()));
},
onDeselect: () => {
console.log('Deselected all');
},
})
brushType: 'rect', //
onSelect: (items) => {
console.log('Selected items:', items.map((i) => i.getModel()));
},
onDeselect: () => {
console.log('Deselected all');
},
}),
],
});
//
graph.data({ nodes: [], edges: [] });
graph.render();
});
onBeforeUnmount(() => {
if (graph) {
graph.destroy();
graph = null;
}
});
//
defineExpose({
addNodeAtPosition(type: NodeType, x: number, y: number) {
if (!graph) return;
const modelId = `${type}_${Date.now()}`;
const nodeModel = {
id: modelId,
shape: 'custom-mechanical-node',
x,
y,
type: type,
};
graph.addItem('node', nodeModel);
},
});
</script>
<template>
<div class="graph-container" ref="container"></div>
</template>
<style scoped>
.graph-container {
flex: 1;
height: 100vh;
overflow: hidden;
background-color: #f0f2f5;
position: relative;
}
</style>

View File

@ -0,0 +1,101 @@
<!-- components/LeftPanel.vue -->
<script setup lang="ts">
import { ref } from 'vue';
import { NodeItem, NodeType } from '@/types/graph';
const emit = defineEmits<{
(e: 'drag-start', nodeType: NodeType): void;
(e: 'drag-end'): void;
}>();
const nodes: NodeItem[] = [
{ type: 'cylinder_slot', label: '圆柱槽' },
{ type: 'flat_slot', label: '扁平槽' },
{ type: 'ring_slot', label: '环形槽' },
{ type: 'tube_slot', label: '管形槽' },
{ type: 'bar_stock', label: '棒料' },
{ type: 'tapered_head', label: '锥形头' },
{ type: 'monk_ring_slot', label: '僧帽环形槽' },
];
const handleDragStart = (e: DragEvent, type: NodeType) => {
if (!e.dataTransfer) return;
e.dataTransfer.setData('text/plain', type);
emit('drag-start', type);
};
</script>
<template>
<div class="left-panel">
<h3 class="panel-title">图形元件库</h3>
<div class="node-list">
<div
v-for="node in nodes"
:key="node.type"
class="node-item"
draggable
@dragstart="handleDragStart($event, node.type)"
>
<span class="icon"></span>
<span class="label">{{ node.label }}</span>
</div>
</div>
</div>
</template>
<style scoped>
.left-panel {
width: 200px;
height: 100vh;
background-color: #f7f9fc;
border-right: 1px solid #ddd;
overflow-y: auto;
display: flex;
flex-direction: column;
}
.panel-title {
padding: 16px;
font-size: 18px;
color: #1a1a1a;
border-bottom: 1px solid #eee;
margin: 0;
background-color: #ffffff;
}
.node-list {
padding: 8px;
flex: 1;
}
.node-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
margin-bottom: 6px;
background-color: white;
border: 1px solid #e0e0e0;
border-radius: 6px;
cursor: grab;
user-select: none;
transition: all 0.2s ease;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.node-item:hover {
background-color: #e6f7ff;
border-color: #91d5ff;
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.icon {
font-size: 16px;
}
.label {
font-size: 14px;
color: #333;
}
</style>

View File

@ -0,0 +1,414 @@
<!-- AntV G6 Graph Component -->
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { Graph,NodeEvent } from '@antv/g6';
const container = ref<HTMLElement | null>(null);
let graph: Graph | null = null;
// Device types data
const deviceTypes = [
{ id: 'device1', name: '圆柱槽', icon: '🟢',
img: 'http://localhost:3000/dev-api/avatar/1.png'
},
{ id: 'device2', name: '扁平槽', icon: '🔵',
img: 'http://localhost:3000/dev-api/avatar/2.png'
},
{ id: 'device3', name: '环形槽', icon: '🟢',
img: 'http://localhost:3000/dev-api/avatar/3.png'
},
{ id: 'device4', name: '管束槽', icon: '🟢',
img: 'http://localhost:3000/dev-api/avatar/4.png'
},
{ id: 'device5', name: '萃取柱', icon: '🟦',
img: 'http://localhost:3000/dev-api/avatar/5.png'
},
{ id: 'device6', name: '流化床', icon: '🟦',
img: 'http://localhost:3000/dev-api/avatar/6.png'
},
{ id: 'device7', name: '锥底环形槽', icon: '🟦',
img: 'http://localhost:3000/dev-api/avatar/7.png'
},
];
const data = {
nodes: [
],
edges: [
],
};
// Drag and drop functions
const handleDragStart = (event: DragEvent, device: any) => {
if (event.dataTransfer) {
event.dataTransfer.setData('application/json', JSON.stringify(device));
event.dataTransfer.effectAllowed = 'copy';
}
};
const handleDragOver = (event: DragEvent) => {
event.preventDefault();
if (event.dataTransfer) {
event.dataTransfer.dropEffect = 'copy';
}
};
const handleDrop = (event: DragEvent) => {
event.preventDefault();
if (!graph || !event.dataTransfer || !container.value) return;
let newNode = null;
try {
const deviceData = JSON.parse(event.dataTransfer.getData('application/json'));
let imgUrl = deviceData.img;
// Calculate coordinates relative to graph container
const rect = container.value.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
// const point = graph.getPointByClient(event.clientX, event.clientY);
// const x = point.x;
// const y = point.y;
const nodeId = 'node1-' + Date.now();
graph.addNodeData([
{
type: 'image',
id: nodeId,
img: imgUrl, //
data: { label: '自定义图片1', status: 'online' },
style: {
x: x,
y: y,
size: 60,
src: imgUrl, //
labelText: '111111111111',
},
},
]);
graph.draw();
} catch (error) {
console.error('Error handling drop:', error);
console.error('Graph instance:', graph);
if (newNode) {
console.error('New node:', JSON.stringify(newNode, null, 2));
}
}
};
const dragelement = ref('');
function setDragElement(type: string) {
dragelement.value = type;
}
const dragLineData = ref([{
stroke: '#333',
lineWidth: 2,
endArrow: false,
endArrowType: '',
endArrowSize: 10,
},{
stroke: '#333',
lineWidth: 2,
endArrow: true,
endArrowType: 'vee',
endArrowSize: 10,
},{
startArrow: true,
startArrowType: 'vee',
startArrowSize: 10,
endArrow: true,
endArrowType: 'vee',
endArrowSize: 10,
stroke: '#333',
lineWidth: 2
},{
stroke: '#333',
lineWidth: 2,
lineDash: [5, 5],
},{
stroke: '#333',
lineWidth: 2,
lineDash: [5, 5],
endArrow: true,
endArrowType: 'vee',
endArrowSize: 10,
},{
startArrow: true,
startArrowType: 'vee',
startArrowSize: 10,
lineDash: [5, 5],
endArrow: true,
endArrowType: 'vee',
endArrowSize: 10,
stroke: '#333',
lineWidth: 2
}]);
const dragLine:any = ref({
stroke: '#333',
lineWidth: 2,
lineDash: [5, 5],
});
const dragLineType = ref('实线');
function setDragLineStyle(index: any, type: string) {
dragLine.value = dragLineData.value[index];
dragLineType.value = type;
// graph.updateBehavior({
// key: 'create-edge',
// style: (edgeData:any) => {
// debugger
// return {
// ...dragLine.value
// };
// }
// });
}
onMounted(() => {
if (container.value) {
// Create G6 graph instance with data in constructor - G6 v4 compatible
graph = new Graph({
container: container.value,
width: container.value.offsetWidth,
height: container.value.offsetHeight,
node: {
type: 'image',
style: {
size: 80,
labelText: (d) => '',
src: (d: any) => d.img
},
},
edge: {
type: 'line',
style: (datum) => {
//
return dragLine.value
},
// style: {
// lineDash: function (datum) {
// if (dragLineType.value === '线' || dragLineType.value === '线' || dragLineType.value === '线') {
// return [5, 5];
// }
// return [];
// },
// }
},
behaviors: [
// 'drag-canvas', //
// 'zoom-canvas', //
{
type: 'drag-element',
enable: (event:any) => {
// id'fixedNode'
return dragelement.value === 'drag-element' ;
},
}, //
{
type: 'create-edge',
trigger: 'drag',
enable: (event:any) => {
//
// Shift 线
return dragelement.value === '' ;
},
// style: dragLine.value,
style: (edgeData:any) => {
debugger
// 线线
const baseStyle = dragLine.value;
if (edgeData.data && edgeData.data.isDashed) {
return {
...baseStyle,
lineDash: [5, 5], // 线
};
} else {
return {
...baseStyle,
lineDash: [], // 线
};
}
},
},
],
data: data // Pass data directly in constructor
});
graph.on(NodeEvent.CLICK, (evt) => {
debugger
const { target } = evt;
const nodeId = target.id;
//
console.log(`节点 ${nodeId} 被点击了`);
//
const nodeData = graph.getNodeData(nodeId);
console.log('节点数据:', nodeData);
//
graph.setElementState(nodeId, 'selected', true);
});
// Just render, no need for separate data() call
}
});
</script>
<template>
<div class="app-layout">
<!-- Left Sidebar -->
<div class="sidebar">
<div class="sidebar-section">
<h3>设备</h3>
<div
v-for="device in deviceTypes"
:key="device.id"
class="device-item"
draggable="true"
@dragstart="handleDragStart($event, device)"
>
<div class="device-icon">
<img :src="device.img" alt="设备图标" style="width: 40px; height: 40px;">
</div>
<div class="device-name">{{ device.name }}</div>
</div>
</div>
<div class="sidebar-section">
<h3>链接</h3>
<div class="device-item" @click="setDragElement('drag-element')">
<div class="device-icon"></div>
<div class="device-name">移动</div>
</div>
<div class="device-item" @click="setDragElement('')">
<div class="device-icon"></div>
<div class="device-name">不移动</div>
</div>
<div class="device-item" @click="setDragLineStyle(0,'实线')">
<div class="device-icon"></div>
<div class="device-name">实线</div>
</div>
<div class="device-item" @click="setDragLineStyle(1,'单箭头实线')">
<div class="device-icon"></div>
<div class="device-name">单箭头实线</div>
</div>
<div class="device-item" @click="setDragLineStyle(2,'双箭头实线')">
<div class="device-icon"></div>
<div class="device-name">双箭头实线</div>
</div>
<div class="device-item" @click="setDragLineStyle(3,'虚线')">
<div class="device-icon"></div>
<div class="device-name">虚线</div>
</div>
<div class="device-item" @click="setDragLineStyle(4,'单箭头虚线')">
<div class="device-icon"></div>
<div class="device-name">单箭头虚线</div>
</div>
<div class="device-item" @click="setDragLineStyle(5,'双箭头虚线')">
<div class="device-icon"></div>
<div class="device-name">双箭头虚线</div>
</div>
</div>
</div>
<!-- Graph Container -->
<div
class="graph-container"
ref="container"
@dragover="handleDragOver"
@drop="handleDrop"
></div>
</div>
</template>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.app-layout {
display: flex;
width: 100vw;
height: 100vh;
font-family: 'Segoe UI', sans-serif;
}
/* Sidebar Styles */
.sidebar {
width: 200px;
background-color: #ffffff;
border-right: 1px solid #e0e0e0;
overflow-y: auto;
padding: 16px;
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}
.sidebar-section {
margin-bottom: 24px;
}
.sidebar-section h3 {
font-size: 14px;
font-weight: 600;
color: #333;
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid #f0f0f0;
}
.device-item {
display: flex;
align-items: center;
padding: 10px;
margin-bottom: 8px;
background-color: #fafafa;
border: 1px solid #e0e0e0;
border-radius: 4px;
cursor: grab;
transition: all 0.2s ease;
}
.device-item:hover {
background-color: #f0f5ff;
border-color: #1890ff;
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(24, 144, 255, 0.2);
}
.device-item:active {
cursor: grabbing;
}
.device-icon {
font-size: 24px;
margin-right: 12px;
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
}
.device-name {
font-size: 13px;
color: #333;
font-weight: 500;
}
/* Graph Container Styles */
.graph-container {
flex: 1;
position: relative;
background-color: #fafafa;
overflow: hidden;
width: 100%;
height: 100%;
}
/* Drag and drop visual feedback */
.graph-container.drag-over {
background-color: #e6f7ff;
border: 2px dashed #1890ff;
}
</style>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
// types/graph.ts
export type NodeType =
| 'cylinder_slot'
| 'flat_slot'
| 'ring_slot'
| 'tube_slot'
| 'bar_stock'
| 'tapered_head'
| 'monk_ring_slot';
export interface NodeItem {
type: NodeType;
label: string;
icon?: string; // 可选图标字符或SVG路径
}

View File

@ -10,6 +10,8 @@ import { ElForm, ElMessage, ElMessageBox } from "element-plus";
import { searchProjectsLsit,addProjects,updateProjects,deleteProjects,deleteBatchProjects} from "@/api/business/project";
import Page from '@/components/Pagination/page.vue'
import ScenarioModel from '@/views/component/scenario/index.vue'
import Antvx6 from '@/components/antvx6/index.vue'
const isShowAntvx6 = ref(false); //
const isScenario = ref(false) //
//
const queryParams = ref({
@ -111,12 +113,16 @@ const rules = ref({
code: [{ required: true, message: "请输入项目编码", trigger: "blur" }],
});
//
function editClick(row: any) {
function editClick(row: any) { //
title.value = "修改项目";
info.value = JSON.parse(JSON.stringify(row));
dialogVisible.value = true;
}
function simulationClick(row: any) {
function designClick(row: any) { //
info.value = JSON.parse(JSON.stringify(row));
isShowAntvx6.value = true;
}
function simulationClick(row: any) { //
info.value = JSON.parse(JSON.stringify(row));
isScenario.value = true;
}
@ -185,6 +191,12 @@ function dateFormat(row: any) {
onMounted(() => {
gettableData();
});
//
function closeAntvx6() {
gettableData();
isShowAntvx6.value = false;
}
</script>
<template>
@ -224,7 +236,7 @@ onMounted(() => {
<img src="@/assets/table/edit.png" alt="" title="修改"
@click="editClick(scope.row)" style="cursor: pointer; ">
<img src="@/assets/table/design.png" alt="" title="分析设计"
style="cursor: pointer; ">
style="cursor: pointer; " @click="designClick(scope.row)">
<img src="@/assets/table/simulation.png" alt="" title="模拟分析"
@click="simulationClick(scope.row)"
style="cursor: pointer; ">
@ -237,9 +249,7 @@ onMounted(() => {
</el-table-column>
</el-table>
<Page :total="total" v-model:size="queryParams.size" v-model:current="queryParams.current" @pagination="gettableData()" ></Page>
</div>
<el-dialog v-model="dialogVisible" :close-on-click-modal="false"
:modal="false" draggable :before-close="handleClose" :title="title"
append-to-body width="620px" height="600px">
@ -267,7 +277,9 @@ onMounted(() => {
<ScenarioModel v-if="isScenario" :projectInfo="info" ref="Scenario" />
</el-dialog>
<div v-if="isShowAntvx6" style="position: fixed;top: 0px;left: 10px; width: 100vw;height: 100vh;background-color: #fff;z-index: 9999;">
<Antvx6 ref="antvx6" v-if="isShowAntvx6" :projectInfo="info" @closeAntvx6="closeAntvx6"/>
</div>
</div>
</template>

View File

@ -0,0 +1,15 @@
// types/graph.ts
export type NodeType =
| 'cylinder_slot'
| 'flat_slot'
| 'ring_slot'
| 'tube_slot'
| 'bar_stock'
| 'tapered_head'
| 'monk_ring_slot';
export interface NodeItem {
type: NodeType;
label: string;
icon?: string; // 可选图标字符或SVG路径
}