yudao-dev/src/views/extend/processFlowView/components/ProcessDetail.vue

543 lines
11 KiB
Vue
Raw Normal View History

2023-10-20 16:03:40 +08:00
<!--
filename: ProcessGraph.vue
author: liubin
date: 2023-10-20 15:00:58
description:
-->
<template>
<section class="process-graph">
<SearchBar :formConfigs="searchBarFormConfig" ref="search-bar" />
2023-10-24 15:56:15 +08:00
<div class="btns" style="text-align: right; position: absolute; top: 20px; right: 20px">
<el-button type="warning" @click="undo" plain v-if="allowUndo" :disabled="!allowUndo" icon="el-icon-back">
2023-10-24 11:17:07 +08:00
撤销
</el-button>
2023-10-24 15:56:15 +08:00
<el-button type="warning" @click="redo" plain v-if="allowRedo" :disabled="!allowRedo">
2023-10-24 11:17:07 +08:00
下一步
<i class="el-icon-right el-icon--right"></i>
</el-button>
2023-10-24 15:56:15 +08:00
<el-button class="btn-refresh" @click="handleUpdateLayout" prefix-icon="el-icon-refresh">刷新布局</el-button>
<el-button type="primary" plain class="btn-create" icon="el-icon-plus" @click="handleAdd">
2023-10-20 16:42:28 +08:00
新建工序
</el-button>
2023-10-24 15:56:15 +08:00
<el-button class="btn-serialize" @click="handleToJson">序列化</el-button>
<el-button class="btn-antiserialize" @click="handleLoadJson">
2023-10-20 16:42:28 +08:00
反序列化
</el-button>
2023-10-24 11:17:07 +08:00
<el-button class="btn-edit" @click="handleEdit">编辑</el-button>
<el-button type="error" class="btn-delete" @click="handleDelete">
删除
</el-button>
2023-10-20 16:42:28 +08:00
</div>
2023-10-20 16:03:40 +08:00
<div class="process-graph__panel" ref="panel"></div>
2023-10-24 11:17:07 +08:00
<!-- 对话框(添加 / 修改) -->
2023-10-24 15:56:15 +08:00
<base-dialog :dialogTitle="title" :dialogVisible="open" width="35%" @close="cancel" @cancel="cancel"
2023-10-24 11:17:07 +08:00
@confirm="submitForm">
<DialogForm v-if="open" ref="form" v-model="form" :rows="rows" />
</base-dialog>
2023-10-20 16:03:40 +08:00
</section>
</template>
<script>
import { Graph } from '@antv/x6';
2023-10-24 15:56:15 +08:00
import ProcessNode, { createProcessNode, CACHE_NAME } from './ProcessNode';
2023-10-24 11:17:07 +08:00
import DialogForm from '@/components/DialogForm';
2023-10-24 15:56:15 +08:00
// import { IdToName } from '@/utils'
2023-10-20 16:03:40 +08:00
Graph.registerNode('process-node', ProcessNode);
export default {
name: 'ProcessGraph',
2023-10-24 11:17:07 +08:00
components: { DialogForm },
2023-10-20 16:03:40 +08:00
props: {},
2023-10-24 11:17:07 +08:00
inject: ['getFlowId'],
2023-10-20 16:03:40 +08:00
data() {
return {
2023-10-24 11:17:07 +08:00
allowRedo: false,
allowUndo: false,
2023-10-20 16:42:28 +08:00
graph: null,
2023-10-20 16:03:40 +08:00
searchBarFormConfig: [{ label: '工序列表' }],
2023-10-24 11:17:07 +08:00
title: '',
open: false,
form: {
name: '', // 工序名称
sectionId: '', // 工段id
remark: '', // 描述
},
rows: [
[
{
input: true,
label: '工序名称',
prop: 'name',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
],
[
{
select: true,
label: '工段',
prop: 'sectionId',
url: '/base/core-workshop-section/listAll',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
bind: {
filterable: true,
},
2023-10-24 15:56:15 +08:00
cache: CACHE_NAME
2023-10-24 11:17:07 +08:00
},
],
[
{
textarea: true,
label: '工序说明',
prop: 'remark',
},
],
],
updateUrl: '/extend/process-flow-det/update',
addUrl: '/extend/process-flow-det/create',
// pageUrl: '/extend/process-flow-det/get',
infoUrl: '/extend/process-flow-det/get',
2023-10-24 15:56:15 +08:00
jsonData: '',
2023-10-20 16:03:40 +08:00
};
},
2023-10-24 11:17:07 +08:00
watch: {
'form.sectionId': {
handler(id) {
// const { form } = this;
// const { sectionId } = form;
// if (sectionId) {
// const { label } = this.$refs['form'].getSelectItem(
// 'sectionId',
// sectionId
// );
// form.workshopName = label;
// }
},
immediate: false,
},
},
2023-10-20 16:03:40 +08:00
mounted() {
2023-10-24 15:56:15 +08:00
const fakeJson = {
"cells": [
{
"position": {
"x": 20,
"y": 30
},
"size": {
"width": 240,
"height": 100
},
"shape": "process-node",
"id": "4783abf7-9a4a-47f7-aaed-37e906e789c0",
"tools": {
"items": [
{
"name": "button-remove"
}
]
},
"attrs": {
"detName": {
"text": "klj"
},
"sectionName": {
"text": "default"
},
"detId": {
"text": "1716703957541310466"
},
"processId": {
"text": "1715253265454723073"
}
},
"zIndex": 2
},
{
"position": {
"x": 290,
"y": 30
},
"size": {
"width": 240,
"height": 100
},
"shape": "process-node",
"id": "3a5c79f6-0f85-403e-b249-843d92488c29",
"tools": {
"items": [
{
"name": "button-remove"
}
]
},
"attrs": {
"detName": {
"text": "jkljkl"
},
"detDesc": {
"text": "hallo ich bin Maria"
},
"sectionName": {
"text": "default"
},
"detId": {
"text": "1716704220322844673"
},
"processId": {
"text": "1715253265454723073"
}
},
"zIndex": 3
}
]
}
2023-10-20 16:03:40 +08:00
2023-10-24 15:56:15 +08:00
this.loadLayout().then(json => {
this.initGraph(fakeJson)
})
2023-10-20 16:03:40 +08:00
2023-10-24 11:17:07 +08:00
// const pn1 = graph.addNode({
// shape: 'process-node',
// x: 30,
// y: 30,
// processName: '工序00A',
// workshopName: '工段1',
// processDesc: 'test test test',
// processId: '1',
// tools: [{ name: 'button-remove' }],
// });
// const pn2 = graph.addNode({
// shape: 'process-node',
// x: 240,
// y: 30,
// processName: '工序00B',
// workshopName: '工段1',
// processDesc: 'test test test',
// processId: '1',
// });
2023-10-20 16:03:40 +08:00
2023-10-24 11:17:07 +08:00
// const pn3 = graph.addNode({
// shape: 'process-node',
// x: 360,
// y: 30,
// processName: '工序00C',
// workshopName: '工段1',
// processDesc: 'test test test',
// processId: '1',
// });
// const pn4 = graph.addNode({
// shape: 'process-node',
// x: 360,
// y: 120,
// processName: '工序00D',
// workshopName: '工段1',
// processDesc: 'test test test',
// processId: '1',
// });
// const pn5 = graph.addNode({
// shape: 'process-node',
// x: 500,
// y: 30,
// processName: '工序00E',
// workshopName: '工段1',
// processDesc: 'test test test',
// processId: '1',
// });
// graph.addEdge({
// source: pn1,
// target: pn2,
// router: {
// name: 'er',
// },
// attrs: {
// line: {
// stroke: '#0b58ff',
// strokeWidth: 1,
// targetMarker: {
// // name: 'classic',
// // name: 'async',
// size: 0,
// },
// },
// },
// });
// graph.addEdge({
// source: pn2,
// target: pn3,
// router: {
// name: 'er',
// },
// attrs: {
// line: {
// stroke: '#0b58ff',
// strokeWidth: 1,
// targetMarker: {
// // name: 'classic',
// // name: 'async',
// size: 0,
// },
// },
// },
// });
// graph.addEdge({
// source: pn2,
// target: pn4,
// router: {
// name: 'er',
// },
// attrs: {
// line: {
// stroke: '#0b58ff',
// strokeWidth: 1,
// targetMarker: {
// // name: 'classic',
// // name: 'async',
// size: 0,
// },
// },
// },
// });
// graph.addEdge({
// source: pn3,
// target: pn5,
// router: {
// name: 'er',
// },
// attrs: {
// line: {
// stroke: '#0b58ff',
// strokeWidth: 1,
// targetMarker: {
// // name: 'classic',
// // name: 'async',
// size: 0,
// },
// },
// },
// });
// graph.addEdge({
// source: pn4,
// target: pn5,
// router: {
// name: 'er',
// },
// attrs: {
// line: {
// stroke: '#0b58ff',
// strokeWidth: 1,
// targetMarker: {
// // name: 'classic',
// // name: 'async',
// size: 0,
// },
// },
// },
// });
2023-10-20 16:03:40 +08:00
2023-10-24 15:56:15 +08:00
// const pn1 = graph.addNode({
// shape: 'process-node',
// x: 0,
// y: 0,
// detName: '测试工序', // 工序名称
// sectionName: 'default', // 工段
// detDesc: 'loremakdfkd...', // 工序说明
// processId: 'p-1', // 工艺ID
// detId: 'det-id-1', // 工序ID
// tools: [{ name: 'button-remove' }],
// });
2023-10-20 16:03:40 +08:00
2023-10-24 11:17:07 +08:00
// const htmlNode = graph.addNode({
// x: 0,
// y: 0,
// width: 200,
// height: 100,
// shape: 'html',
// html() {
// const ctn = document.createElement('div');
// ctn.style.width = '100%';
// ctn.style.height = '100%';
// ctn.style.border = '1px solid #ccc';
// ctn.style.background = '#fff';
// ctn.innerText = 'hello';
// return ctn;
// },
// });
2023-10-20 16:03:40 +08:00
},
computed: {},
2023-10-20 16:42:28 +08:00
methods: {
2023-10-24 15:56:15 +08:00
initGraph(json) {
const graph = new Graph({
container: this.$refs.panel,
grid: {
size: 10,
visible: true,
},
history: true
});
graph.fromJSON(json)
this.graph = graph;
},
loadLayout() {
return Promise.resolve()
},
handleToJson() { },
handleLoadJson() { },
handleDumpJson() {
2023-10-20 16:42:28 +08:00
if (this.graph) {
console.log(JSON.stringify(this.graph.toJSON(), null, 2));
}
},
2023-10-24 15:56:15 +08:00
handleUpdateLayout() {
// 手动刷新布局
},
2023-10-24 11:17:07 +08:00
reset() {
this.form = {
name: '', // 工序名称
sectionId: '', // 工段id
remark: '', // 描述
};
this.resetForm('form');
},
2023-10-24 15:56:15 +08:00
2023-10-24 11:17:07 +08:00
/** 取消按钮 */
cancel() {
this.open = false;
this.reset();
},
2023-10-24 15:56:15 +08:00
2023-10-24 11:17:07 +08:00
handleAdd() {
this.reset();
this.open = true;
this.title = '添加工序';
},
2023-10-24 15:56:15 +08:00
2023-10-24 11:17:07 +08:00
handleEdit() {
this.open = true;
this.title = '编辑工序';
},
2023-10-24 15:56:15 +08:00
handleDelete(id) { },
2023-10-24 11:17:07 +08:00
/** 提交按钮 */
submitForm() {
this.$refs['form'].validate((valid) => {
if (!valid) {
return;
}
// 修改的提交
if (this.form.id != null) {
this.updateProcess();
return;
}
2023-10-24 15:56:15 +08:00
const flowId = this.getFlowId();
this.createProcess()
.then(({ id, name, sectionId, remark }) => {
if (!id || !flowId) return null;
return createProcessNode({
flowId: flowId,
name, sectionId, remark,
2023-10-24 11:17:07 +08:00
id,
})
2023-10-24 15:56:15 +08:00
}
).then(node => {
if (!node) {
this.$modal.msgError('创建节点失败');
return;
};
this.graph.addNode(node);
});
2023-10-24 11:17:07 +08:00
});
},
2023-10-24 15:56:15 +08:00
2023-10-24 11:17:07 +08:00
updateProcess() {
return updateEquipmentType(this.form).then((response) => {
this.$modal.msgSuccess('修改成功');
this.open = false;
// this.getList();
});
},
2023-10-24 15:56:15 +08:00
2023-10-24 11:17:07 +08:00
createProcess() {
2023-10-24 15:56:15 +08:00
// const flowId = this.$route.params.id;
const flowId = this.getFlowId(); // it also works
2023-10-24 11:17:07 +08:00
if (!flowId) {
this.$modal.msgError('工艺ID不能为空');
return Promise.reject(null);
}
2023-10-24 15:56:15 +08:00
console.log('create process', this.form)
2023-10-24 11:17:07 +08:00
// 添加的提交
return this.post({ flowId: this.flowId, ...this.form }).then(
({ code, data }) => {
this.$modal.msgSuccess('新增成功');
this.open = false;
// this.getList();
2023-10-24 15:56:15 +08:00
return {
id: data, // 服务器返回的新建的工段id
...this.form, // 保存一份 this.form 副本,当 open->false 时 this.form 里的信息就清空了
};
2023-10-24 11:17:07 +08:00
}
);
},
2023-10-24 15:56:15 +08:00
2023-10-24 11:17:07 +08:00
put(payload) {
return this.http(this.updateUrl, 'put', payload);
},
post(payload) {
return this.http(this.addUrl, 'post', payload);
},
recv(payload) {
return this.http(this.pageUrl, 'get', payload);
},
info(payload) {
return this.http(this.infoUrl, 'get', payload);
},
http(url, method, payload) {
return this.$axios({
url,
method,
params: method === 'get' ? payload : null,
data: method !== 'get' ? payload : null,
})
},
2023-10-20 16:42:28 +08:00
},
2023-10-20 16:03:40 +08:00
};
</script>
<style scoped lang="scss">
.process-graph {
padding: 12px 20px 20px;
background: #fff;
border-radius: 8px;
2023-10-20 16:42:28 +08:00
position: relative;
2023-10-20 16:03:40 +08:00
}
.process-graph__panel {
height: 300px;
}
</style>
2023-10-24 11:17:07 +08:00
<style>
.x6-widget-selection-selected {
border: 1px solid red;
}
</style>