update extend process

This commit is contained in:
lb 2023-10-26 11:28:24 +08:00
parent 5ba186b0c6
commit 6c348202a1
3 changed files with 85 additions and 210 deletions

View File

@ -12,8 +12,8 @@ ENV = 'development'
VUE_APP_TITLE = 产线监控系统 VUE_APP_TITLE = 产线监控系统
# 芋道管理系统/开发环境 # 芋道管理系统/开发环境
VUE_APP_BASE_API = 'http://192.168.1.8:48082' # VUE_APP_BASE_API = 'http://192.168.1.8:48082'
# VUE_APP_BASE_API = 'http://192.168.0.33:48082' VUE_APP_BASE_API = 'http://192.168.0.33:48082'
# 路由懒加载 # 路由懒加载
VUE_CLI_BABEL_TRANSPILE_MODULES = true VUE_CLI_BABEL_TRANSPILE_MODULES = true

View File

@ -22,19 +22,11 @@
<el-button type="primary" plain class="btn-create" icon="el-icon-plus" @click="handleAdd"> <el-button type="primary" plain class="btn-create" icon="el-icon-plus" @click="handleAdd">
新建工序 新建工序
</el-button> </el-button>
<!-- <el-button class="btn-serialize" @click="handleToJson">序列化</el-button>
<el-button class="btn-antiserialize" @click="handleLoadJson">
反序列化
</el-button> -->
<el-button class="btn-edit" :disabled="currentDet == null" @click="handleEdit">编辑</el-button> <el-button class="btn-edit" :disabled="currentDet == null" @click="handleEdit">编辑</el-button>
<!-- <el-button type="danger" plain :disabled="currentDet == null" class="btn-delete" @click="handleDelete">
删除
</el-button> -->
</div> </div>
<div class="process-graph__panel" ref="panel"></div> <div class="process-graph__panel" ref="panel"></div>
<!-- 对话框(添加 / 修改) -->
<base-dialog :dialogTitle="title" :dialogVisible="open" width="35%" @close="cancel" @cancel="cancel" <base-dialog :dialogTitle="title" :dialogVisible="open" width="35%" @close="cancel" @cancel="cancel"
@confirm="submitForm"> @confirm="submitForm">
<DialogForm v-if="open" ref="form" v-model="form" :rows="rows" /> <DialogForm v-if="open" ref="form" v-model="form" :rows="rows" />
@ -44,7 +36,7 @@
<script> <script>
import { Graph } from '@antv/x6'; import { Graph } from '@antv/x6';
import ProcessNode, { createProcessNode, CACHE_NAME } from './ProcessNode'; import ProcessNode, { createProcessNode, CACHE_NAME, getSectionFrom } from './ProcessNode';
import DialogForm from '@/components/DialogForm'; import DialogForm from '@/components/DialogForm';
// import { IdToName } from '@/utils' // import { IdToName } from '@/utils'
@ -98,8 +90,9 @@ export default {
}, },
], ],
], ],
updateUrl: '/extend/process-flow-view/update', updateUrl: '/extend/process-flow-det/update',
addUrl: '/extend/process-flow-view/create', deleteUrl: '/extend/process-flow-det/delete',
addUrl: '/extend/process-flow-det/create',
// pageUrl: '/extend/process-flow-det/get', // pageUrl: '/extend/process-flow-det/get',
infoUrl: '/extend/process-flow-view/getByFlowId', infoUrl: '/extend/process-flow-view/getByFlowId',
layout: { layout: {
@ -109,6 +102,7 @@ export default {
createTime: null createTime: null
}, },
currentDet: null, currentDet: null,
currentNode: null
}; };
}, },
@ -130,177 +124,6 @@ export default {
this.loadLayout().then(json => { this.loadLayout().then(json => {
this.initGraph(json) this.initGraph(json)
}) })
// 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',
// });
// 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,
// },
// },
// },
// });
// 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' }],
// });
// 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;
// },
// });
}, },
deactivated() { deactivated() {
this.graph.dispose(); this.graph.dispose();
@ -331,11 +154,14 @@ export default {
allowPort: true, allowPort: true,
allowEdge: false, allowEdge: false,
}, },
scroller: { panning: true,
enabled: true, // scroller: {
pannable: true, // enabled: true,
cursor: 'grab' // pannable: true,
}, // cursor: '',
// width: 800,
// height: 200
// },
mousewheel: { mousewheel: {
enabled: true, enabled: true,
modifiers: ['ctrl', 'meta'] modifiers: ['ctrl', 'meta']
@ -354,6 +180,8 @@ export default {
const nodes = this.graph.getNodes(); const nodes = this.graph.getNodes();
const edges = this.graph.getEdges(); const edges = this.graph.getEdges();
this.currentDet = null; this.currentDet = null;
this.currentNode = null;
nodes.forEach(node => { nodes.forEach(node => {
node.attr('container/stroke', '#ccc'); node.attr('container/stroke', '#ccc');
}); });
@ -365,13 +193,15 @@ export default {
this.graph.on('node:click', ({ e, x, y, node, view }) => { this.graph.on('node:click', ({ e, x, y, node, view }) => {
reset(); reset();
node.attr('container/stroke', '#0b58ff'); node.attr('container/stroke', '#0b58ff');
const { detId, detName, detDesc, processId, sectionName } = node.attrs; const { detId, detName, detDesc, processId, sectionId, sectionName } = node.attrs;
this.currentDet = {} this.currentDet = {}
this.$set(this.currentDet, 'detId', detId.text) this.$set(this.currentDet, 'detId', detId.text)
this.$set(this.currentDet, 'sectionId', sectionId.text)
this.$set(this.currentDet, 'detName', detName.text) this.$set(this.currentDet, 'detName', detName.text)
this.$set(this.currentDet, 'detDesc', detDesc.text) this.$set(this.currentDet, 'detDesc', detDesc.text)
this.$set(this.currentDet, 'flowId', processId.text) this.$set(this.currentDet, 'flowId', processId.text)
this.$set(this.currentDet, 'sectionName', sectionName.text) this.$set(this.currentDet, 'sectionName', sectionName.text)
this.currentNode = node
}); });
this.graph.on('edge:click', ({ e, x, y, edge, view }) => { this.graph.on('edge:click', ({ e, x, y, edge, view }) => {
// console.log('edge clicked!', edge) // console.log('edge clicked!', edge)
@ -451,10 +281,10 @@ export default {
console.table([this.layout, this.$route.params.id]) console.table([this.layout, this.$route.params.id])
// //
if (this.layout.id) { if (this.layout.id) {
({ code, data } = await this.put(this.layout)); ({ code, data } = await this.http('/extend/process-flow-view/update', 'put', this.layout));
} else { } else {
this.layout.flowId = this.$route.params.id; this.layout.flowId = this.$route.params.id;
({ code, data } = await this.post(this.layout)); ({ code, data } = await this.http('/extend/process-flow-view/create', 'post', this.layout));
} }
if (code == 0) { if (code == 0) {
@ -484,11 +314,24 @@ export default {
}, },
handleEdit() { handleEdit() {
this.open = true; this.form.name = this.currentDet.detName;
this.form.sectionId = this.currentDet.sectionId;
this.form.remark = this.currentDet.detDesc;
this.form.id = this.currentDet.detId;
this.title = '编辑工序'; this.title = '编辑工序';
this.$nextTick(() => {
this.open = true;
})
}, },
handleDelete(id) { }, async handleDelete(id) {
const { code, data } = await this.delete({ id });
if (code == 0) {
this.$msgSuccess('成功删除一个工序!');
return true;
}
return false;
},
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
@ -498,36 +341,60 @@ export default {
} }
// //
if (this.form.id != null) { if (this.form.id != null) {
this.updateProcess(); this.updateProcess()
.then((form) => {
const { name, sectionId, remark } = form;
getSectionFrom(sectionId).then(sectionName => {
// node
this.currentNode.setAttrs({
detName: { text: name },
sectionId: { text: sectionId },
sectionName: { text: sectionName },
detDesc: { text: remark }
})
})
})
.catch(err => { });
return; return;
} }
const flowId = this.getFlowId();
this.createProcess() this.createProcess()
.then(({ id, name, sectionId, remark }) => { .then(({ id, name, sectionId, remark, flowId }) => {
if (!id || !flowId) return null; if (!id) return null;
return createProcessNode({ return createProcessNode({
flowId: flowId, flowId: flowId,
name, sectionId, remark, name, sectionId, remark,
id, id,
}) })
} }).then(node => {
).then(node => {
if (!node) { if (!node) {
this.$modal.msgError('创建节点失败'); this.$modal.msgError('创建节点失败');
return; return;
}; };
this.graph.addNode(node); this.graph.addNode(node);
}).catch(err => {
return;
}); });
}); });
}, },
updateProcess() { updateProcess() {
return updateEquipmentType(this.form).then((response) => { const flowId = this.getFlowId();
if (!flowId) {
this.$modal.msgError('工艺ID不能为空');
return Promise.reject('工艺ID不能为空');
}
return this.put({ flowId, ...this.form })
.then(({ code, data }) => {
if (code == 0) {
this.$modal.msgSuccess('修改成功'); this.$modal.msgSuccess('修改成功');
} else {
this.$modal.msgError('修改失败');
}
const formCopy = { ...this.form }
this.open = false; this.open = false;
// this.getList(); return formCopy;
}); });
}, },
@ -536,11 +403,11 @@ export default {
const flowId = this.getFlowId(); // it also works const flowId = this.getFlowId(); // it also works
if (!flowId) { if (!flowId) {
this.$modal.msgError('工艺ID不能为空'); this.$modal.msgError('工艺ID不能为空');
return Promise.reject(null); return Promise.reject('工艺ID不能为空');
} }
console.log('create process', this.form) console.log('create process', this.form)
// //
return this.post({ flowId: this.flowId, ...this.form }).then( return this.post({ flowId, ...this.form }).then(
({ code, data }) => { ({ code, data }) => {
this.$modal.msgSuccess('新增成功'); this.$modal.msgSuccess('新增成功');
this.open = false; this.open = false;
@ -548,9 +415,12 @@ export default {
return { return {
id: data, // id id: data, // id
...this.form, // this.form open->false this.form ...this.form, // this.form open->false this.form
flowId
}; };
} }
); ).catch(err => {
this.$msgError(err)
});
}, },
put(payload) { put(payload) {
@ -565,6 +435,9 @@ export default {
info(payload) { info(payload) {
return this.http(this.infoUrl, 'get', payload); return this.http(this.infoUrl, 'get', payload);
}, },
delete(payload) {
return this.http(this.deleteUrl, 'delete', payload);
},
http(url, method, payload) { http(url, method, payload) {
return this.$axios({ return this.$axios({
url, url,

View File

@ -118,20 +118,21 @@ ProcessNode.config({
} }
}, },
propHooks(metadata) { propHooks(metadata) {
const { detId, detName, detDesc, sectionName, processId, ...others } = metadata; const { detId, detName, detDesc, sectionName, processId, sectionId, ...others } = metadata;
// debugger; // debugger;
if (detName) ObjectExt.setByPath(others, 'attrs/detName/text', detName); if (detName) ObjectExt.setByPath(others, 'attrs/detName/text', detName);
if (detDesc) ObjectExt.setByPath(others, 'attrs/detDesc/text', detDesc); if (detDesc) ObjectExt.setByPath(others, 'attrs/detDesc/text', detDesc);
if (sectionName) ObjectExt.setByPath(others, 'attrs/sectionName/text', sectionName); if (sectionName) ObjectExt.setByPath(others, 'attrs/sectionName/text', sectionName);
if (detId) ObjectExt.setByPath(others, 'attrs/detId/text', detId); if (detId) ObjectExt.setByPath(others, 'attrs/detId/text', detId);
if (processId) ObjectExt.setByPath(others, 'attrs/processId/text', processId); if (processId) ObjectExt.setByPath(others, 'attrs/processId/text', processId);
if (sectionId) ObjectExt.setByPath(others, 'attrs/sectionId/text', sectionId);
return others; return others;
} }
}); });
export const CACHE_NAME = 'ProcessDetail::section'; export const CACHE_NAME = 'ProcessDetail::section';
async function getSectionFrom(sectionId) { export async function getSectionFrom(sectionId) {
const sectionList = await cache.getList( const sectionList = await cache.getList(
CACHE_NAME, CACHE_NAME,
async () => { async () => {
@ -154,6 +155,7 @@ export async function createProcessNode({ flowId, id, name, sectionId, remark })
y: 0, y: 0,
detName: name, // 工序名称 detName: name, // 工序名称
sectionName, // 工段 sectionName, // 工段
sectionId,
detDesc: remark, // 工序说明 detDesc: remark, // 工序说明
processId: flowId, // 工艺ID processId: flowId, // 工艺ID
detId: id, // 工序ID detId: id, // 工序ID