projects/mes-test #132

Manually merged
gtz217 merged 281 commits from projects/mes-test into projects/mes 2023-11-30 09:11:34 +08:00
3 changed files with 209 additions and 118 deletions
Showing only changes of commit 3c31e5d63a - Show all commits

View File

@ -438,3 +438,7 @@ export function toCamelCase(str, upperCaseFirst) {
return str;
}
export function IdToName(targetId, source, prop = 'name') {
return source.find(item => item.id === targetId)?.[prop]
}

View File

@ -9,37 +9,20 @@
<section class="process-graph">
<SearchBar :formConfigs="searchBarFormConfig" ref="search-bar" />
<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">
<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">
撤销
</el-button>
<el-button
type="warning"
@click="redo"
plain
v-if="allowRedo"
:disabled="!allowRedo">
<el-button type="warning" @click="redo" plain v-if="allowRedo" :disabled="!allowRedo">
下一步
<i class="el-icon-right el-icon--right"></i>
</el-button>
<el-button
type="primary"
plain
class="btn-create"
icon="el-icon-plus"
@click="handleAdd">
<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">
新建工序
</el-button>
<el-button class="btn-serialize" @click="graphToJson">序列化</el-button>
<el-button class="btn-antiserialize" @click="jsonToGraph">
<el-button class="btn-serialize" @click="handleToJson">序列化</el-button>
<el-button class="btn-antiserialize" @click="handleLoadJson">
反序列化
</el-button>
<el-button class="btn-edit" @click="handleEdit">编辑</el-button>
@ -51,12 +34,7 @@
<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">
<DialogForm v-if="open" ref="form" v-model="form" :rows="rows" />
</base-dialog>
@ -65,8 +43,9 @@
<script>
import { Graph } from '@antv/x6';
import ProcessNode from './ProcessNode';
import ProcessNode, { createProcessNode, CACHE_NAME } from './ProcessNode';
import DialogForm from '@/components/DialogForm';
// import { IdToName } from '@/utils'
Graph.registerNode('process-node', ProcessNode);
@ -107,6 +86,7 @@ export default {
bind: {
filterable: true,
},
cache: CACHE_NAME
},
],
[
@ -121,6 +101,8 @@ export default {
addUrl: '/extend/process-flow-det/create',
// pageUrl: '/extend/process-flow-det/get',
infoUrl: '/extend/process-flow-det/get',
jsonData: '',
};
},
watch: {
@ -140,30 +122,85 @@ export default {
},
},
mounted() {
const graph = new Graph({
container: this.$refs.panel,
grid: {
size: 10,
visible: true,
const fakeJson = {
"cells": [
{
"position": {
"x": 20,
"y": 30
},
history: true,
selecting: {
enabled: true,
rubberband: true,
movable: true,
showNodeSelectionBox: true,
className: 'process-selected',
"size": {
"width": 240,
"height": 100
},
snapline: true,
scroller: {
enabled: true,
"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
}
]
}
graph.on('node:click', ({ node }) => {
const { processId } = node.attrs;
console.log('node:click', processId.text);
});
this.loadLayout().then(json => {
this.initGraph(fakeJson)
})
// const pn1 = graph.addNode({
// shape: 'process-node',
@ -306,17 +343,17 @@ export default {
// },
// });
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 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,
@ -335,24 +372,41 @@ export default {
// return ctn;
// },
// });
graph.on('cell:selected', ({ cell, options }) => {
console.log('cell:selected', cell, options);
});
this.graph = graph;
// console.log('selected:', this.graph.selection.widget.container)
},
computed: {},
methods: {
createDet() {},
jsonToGraph() {},
graphToJson() {
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() {
if (this.graph) {
console.log(JSON.stringify(this.graph.toJSON(), null, 2));
}
},
handleUpdateLayout() {
//
},
reset() {
this.form = {
name: '', //
@ -361,21 +415,26 @@ export default {
};
this.resetForm('form');
},
/** 取消按钮 */
cancel() {
this.open = false;
this.reset();
},
handleAdd() {
this.reset();
this.open = true;
this.title = '添加工序';
},
handleEdit() {
this.open = true;
this.title = '编辑工序';
},
handleDelete(id) { },
/** 提交按钮 */
submitForm() {
this.$refs['form'].validate((valid) => {
@ -387,31 +446,28 @@ export default {
this.updateProcess();
return;
}
this.createProcess().then((id) => {
if (!id) return;
this.graph.addNode(
this.createProcessNode({
flowId: this.flowId,
...this.form,
const flowId = this.getFlowId();
this.createProcess()
.then(({ id, name, sectionId, remark }) => {
if (!id || !flowId) return null;
return createProcessNode({
flowId: flowId,
name, sectionId, remark,
id,
})
);
});
});
},
createProcessNode({ flowId, name, id, remark, sectionId }) {
return {
shape: 'process-node',
x: 0,
y: 0,
detName: name, //
sectionName: 'default', //
detDesc: remark, //
processId: flowId, // ID
detId: id, // ID
tools: [{ name: 'button-remove' }],
}
).then(node => {
if (!node) {
this.$modal.msgError('创建节点失败');
return;
};
this.graph.addNode(node);
});
});
},
updateProcess() {
return updateEquipmentType(this.form).then((response) => {
this.$modal.msgSuccess('修改成功');
@ -419,23 +475,29 @@ export default {
// this.getList();
});
},
createProcess() {
const flowId = this.$route.params.id;
// const t = this.getFlowId(); // it also works
// const flowId = this.$route.params.id;
const flowId = this.getFlowId(); // it also works
if (!flowId) {
this.$modal.msgError('工艺ID不能为空');
return Promise.reject(null);
}
console.log('create process', this.form)
//
return this.post({ flowId: this.flowId, ...this.form }).then(
({ code, data }) => {
this.$modal.msgSuccess('新增成功');
this.open = false;
// this.getList();
return data;
return {
id: data, // id
...this.form, // this.form open->false this.form
};
}
);
},
put(payload) {
return this.http(this.updateUrl, 'put', payload);
},

View File

@ -1,10 +1,9 @@
import { Node, ObjectExt } from '@antv/x6';
import { IdToName } from '@/utils'
import cache from '@/utils/cache'
import axios from '@/utils/request'
export default class ProcessNode extends Node {
}
export default class ProcessNode extends Node { }
ProcessNode.config({
width: 240,
height: 100,
@ -47,8 +46,6 @@ ProcessNode.config({
attrs: {
x: 20,
y: 30,
// fill: '#777',
// fontSize: 14
},
},
{
@ -57,22 +54,17 @@ ProcessNode.config({
attrs: {
x: 115,
y: 30,
// fill: '#777',
// fontSize: 14
},
},
{
tagName: 'text',
selector: 'detDesc',
// textContent: '工序00A',
attrs: {
x: 26,
y: 80,
fill: '#777',
fontSize: 14,
fill: '#1a90fc',
// lengthAdjust: 'spacingAndGlyphs',
// textLength: 180
},
},
],
@ -82,8 +74,41 @@ ProcessNode.config({
if (detName) ObjectExt.setByPath(others, 'attrs/detName/text', detName);
if (detDesc) ObjectExt.setByPath(others, 'attrs/detDesc/text', detDesc);
if (sectionName) ObjectExt.setByPath(others, 'attrs/sectionName/text', sectionName);
if (detId) ObjectExt.setByPath(others, 'attrs/detId', detId);
if (processId) ObjectExt.setByPath(others, 'attrs/processId', processId);
if (detId) ObjectExt.setByPath(others, 'attrs/detId/text', detId);
if (processId) ObjectExt.setByPath(others, 'attrs/processId/text', processId);
return others;
}
})
});
export const CACHE_NAME = 'ProcessDetail::section';
async function getSectionFrom(sectionId) {
const sectionList = await cache.getList(
CACHE_NAME,
async () => {
const { code, data } = await axios(
'/base/core-production-line/listAll'
);
if (code == 0) {
return data;
}
}
);
debugger;
return IdToName(sectionId, sectionList);
}
export async function createProcessNode({ flowId, id, name, sectionId, remark }) {
const sectionName = await getSectionFrom(sectionId);
return {
shape: 'process-node',
x: 0,
y: 0,
detName: name, // 工序名称
sectionName, // 工段
detDesc: remark, // 工序说明
processId: flowId, // 工艺ID
detId: id, // 工序ID
tools: [{ name: 'button-remove' }],
};
}