Compare commits

...

3 Commits

Author SHA1 Message Date
lb
e153d7e077 update 流程图 2023-10-24 17:07:32 +08:00
lb
3c31e5d63a done 新建工序 2023-10-24 15:56:15 +08:00
lb
6006ae13d9 update flow 2023-10-24 11:17:07 +08:00
8 changed files with 568 additions and 238 deletions

View File

@ -109,7 +109,7 @@
<script>
import { getAccessToken } from '@/utils/auth';
import tupleImg from '@/assets/images/tuple.png';
import cache from '@/views/extend/processFlow/cache';
import cache from '@/utils/cache';
/**
* 找到最长的label

View File

@ -217,7 +217,7 @@ export function getTime(type) {
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result
const later = function() {
const later = function () {
// 据上一次触发时间间隔
const last = +new Date() - timestamp
@ -234,7 +234,7 @@ export function debounce(func, wait, immediate) {
}
}
return function(...args) {
return function (...args) {
context = this
timestamp = +new Date()
const callNow = immediate && !timeout
@ -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

@ -44,7 +44,7 @@
<script>
import basicPageMixin from '@/mixins/lb/basicPageMixin';
// import cache from './cache';
// import cache from '@/utils/cache';
const ProcessItem = {
name: 'ProcessItem',

View File

@ -9,193 +9,477 @@
<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="primary"
plain
class="btn-create"
icon="el-icon-plus"
@click="createDet">
<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">
下一步
<i class="el-icon-right el-icon--right"></i>
</el-button>
<el-button class="btn-refresh" @click="handleUpdateLayout" 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>
<el-button type="error" class="btn-delete" @click="handleDelete">
删除
</el-button>
</div>
<div class="process-graph__panel" ref="panel"></div>
<!-- 对话框(添加 / 修改) -->
<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>
</section>
</template>
<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);
export default {
name: 'ProcessGraph',
components: {},
components: { DialogForm },
props: {},
inject: ['getFlowId'],
data() {
return {
allowRedo: false,
allowUndo: false,
graph: null,
searchBarFormConfig: [{ label: '工序列表' }],
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,
},
cache: CACHE_NAME
},
],
[
{
textarea: true,
label: '工序说明',
prop: 'remark',
},
],
],
updateUrl: '/extend/process-flow-view/update',
addUrl: '/extend/process-flow-view/create',
// pageUrl: '/extend/process-flow-det/get',
infoUrl: '/extend/process-flow-view/get',
layout: {
id: null,
flowId: null,
content: '',
createTime: null
},
};
},
mounted() {
const graph = new Graph({
container: this.$refs.panel,
grid: {
size: 10,
visible: false,
type: 'dot',
args: {
color: '#f005',
thickness: 1,
},
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,
},
},
activated() {
this.loadLayout().then(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',
});
const pn2 = graph.addNode({
shape: 'process-node',
x: 240,
y: 30,
processName: '工序00B',
workshopName: '工段1',
processDesc: 'test test test',
processId: '1',
});
// 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 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 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',
});
// 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,
attrs: {
line: {
stroke: '#0b58ff',
strokeWidth: 1,
targetMarker: {
// name: 'classic',
// name: 'async',
size: 0,
},
},
},
});
graph.addEdge({
source: pn2,
target: pn3,
attrs: {
line: {
stroke: '#0b58ff',
strokeWidth: 1,
targetMarker: {
// name: 'classic',
// name: 'async',
size: 0,
},
},
},
});
graph.addEdge({
source: pn2,
target: pn4,
attrs: {
line: {
stroke: '#0b58ff',
strokeWidth: 1,
targetMarker: {
// name: 'classic',
// name: 'async',
size: 0,
},
},
},
});
graph.addEdge({
source: pn3,
target: pn5,
attrs: {
line: {
stroke: '#0b58ff',
strokeWidth: 1,
targetMarker: {
// name: 'classic',
// name: 'async',
size: 0,
},
},
},
});
graph.addEdge({
source: pn4,
target: pn5,
attrs: {
line: {
stroke: '#0b58ff',
strokeWidth: 1,
targetMarker: {
// name: 'classic',
// name: 'async',
size: 0,
},
},
},
});
// 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,
// },
// },
// },
// });
this.graph = graph;
// 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;
// },
// });
},
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;
},
resetLayout() {
this.layout = {
id: null,
flowId: null,
content: '',
createTime: null
}
},
async loadLayout() {
const flowId = this.$route.params.id;
if (!flowId) return { cells: [] }
const { code, data } = await this.info({ id: flowId });
if (code == 0) {
if (data) {
this.layout = data;
return JSON.parse(data?.content) || { cells: [] };
}
return { cells: [] };
}
this.resetLayout();
return Promise.reject(this.infoUrl + ' 接口出错!');
},
handleToJson() { },
handleLoadJson() { },
handleDumpJson() {
if (this.graph) {
console.log(JSON.stringify(this.graph.toJSON(), null, 2));
}
},
async handleUpdateLayout() {
this.layout.content = JSON.stringify(this.graph.toJSON());
let code, data;
//
if (this.layout.id) {
({ code, data } = await this.put(this.layout));
} else {
this.layout.flowId = this.$route.params.id;
({ code, data } = await this.post(this.layout));
}
if (code == 0) {
this.$modal.msgSuccess('布局已刷新!')
}
},
reset() {
this.form = {
name: '', //
sectionId: '', // id
remark: '', //
};
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) => {
if (!valid) {
return;
}
//
if (this.form.id != null) {
this.updateProcess();
return;
}
const flowId = this.getFlowId();
this.createProcess()
.then(({ id, name, sectionId, remark }) => {
if (!id || !flowId) return null;
return createProcessNode({
flowId: flowId,
name, sectionId, remark,
id,
})
}
).then(node => {
if (!node) {
this.$modal.msgError('创建节点失败');
return;
};
this.graph.addNode(node);
});
});
},
updateProcess() {
return updateEquipmentType(this.form).then((response) => {
this.$modal.msgSuccess('修改成功');
this.open = false;
// this.getList();
});
},
createProcess() {
// 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 {
id: data, // id
...this.form, // this.form open->false this.form
};
}
);
},
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,
})
},
},
};
</script>
@ -212,3 +496,9 @@ export default {
height: 300px;
}
</style>
<style>
.x6-widget-selection-selected {
border: 1px solid red;
}
</style>

View File

@ -11,37 +11,34 @@
<el-row :gutter="20">
<el-col :span="6">
<InfoItem label="工艺名称" value="测试工艺" />
<InfoItem label="工艺名称" :value="form.name" />
</el-col>
<el-col :span="6">
<InfoItem label="产线" value="A4" />
<InfoItem label="产线" :value="form.lineName" />
</el-col>
<el-col :span="12">
<InfoItem
label="工艺描述"
value="咯热门asdfkj alsdfk ;lkj flskdjf sadf" />
<InfoItem label="工艺描述" :value="form.remark" />
</el-col>
</el-row>
<el-row :gutter="20" style="margin-top: 12px;">
<el-col :span="6">
<InfoItem label="创建人" value="xxse" />
<!-- <InfoItem label="创建人" value="xxse" /> -->
</el-col>
<el-col :span="6">
<InfoItem label="创建时间" value="2023-10-22 10:11:00" />
<InfoItem label="创建时间" :value="form.createTime" />
</el-col>
<el-col :span="6">
<InfoItem label="更新人" value="xxse" />
<!-- <InfoItem label="更新人" value="xxse" /> -->
</el-col>
<el-col :span="6">
<InfoItem label="更新时间" value="2023-10-22 10:11:00" />
<!-- <InfoItem label="更新时间" value="2023-10-22 10:11:00" /> -->
</el-col>
</el-row>
</section>
</template>
<script>
import basicPageMixin from '@/mixins/lb/basicPageMixin';
const InfoItem = {
name: 'InfoItem',
@ -67,16 +64,63 @@ const InfoItem = {
export default {
name: 'ProcessInfo',
components: { InfoItem },
mixins: [basicPageMixin],
props: {},
inject: ['getFlowId'],
data() {
return {
infoUrl: '/extend/process-flow/get',
searchBarFormConfig: [{ label: '工艺详情' }],
form: {
id: null,
name: null,
lineName: null,
createTime: null,
remark: null,
enable: null,
code: null
},
};
},
activated() {
this.getInfo()
},
computed: {},
methods: {},
methods: {
// utils
http(url, method, payload) {
return this.$axios({
url,
method,
params: method === 'get' ? payload : null,
data: method !== 'get' ? payload : null,
})
},
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);
},
async getInfo() {
const flowId = this.$route.params.id;
if (!flowId) this.$router.go(-1);
const { code, data } = await this.info({ id: flowId });
// debugger;
if (code == 0) {
this.form = {
...data
};
} else {
this.$modal.msgError('工艺信息获取失败')
}
}
},
};
</script>

View File

@ -1,23 +1,23 @@
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,
markup: [
{
tagName: 'rect',
selector: 'container',
attrs: {
x: 0,
y: 0,
width: 200,
height: 100,
fill: 'transparent',
stroke: '#0b58ff'
stroke: '#ccc'
},
},
{
@ -42,94 +42,75 @@ ProcessNode.config({
},
{
tagName: 'text',
selector: 'processName',
selector: 'detName',
attrs: {
x: 20,
y: 30,
// fill: '#777',
// fontSize: 14
},
},
{
tagName: 'text',
selector: 'workshopName',
selector: 'sectionName',
attrs: {
x: 115,
y: 30,
// fill: '#777',
// fontSize: 14
},
},
{
tagName: 'text',
selector: 'processDesc',
// textContent: '工序00A',
selector: 'detDesc',
attrs: {
x: 26,
y: 80,
fill: '#777',
fontSize: 14
fontSize: 14,
fill: '#1a90fc',
},
},
// {
// tagName: 'text',
// textContent: '工序名称',
// attrs: {
// x: 20,
// y: 30,
// },
// },
// {
// tagName: 'text',
// textContent: '工段名称',
// attrs: {
// x: 115,
// y: 30,
// },
// },
// {
// tagName: 'text',
// selector: 'processName',
// // textContent: '工序00A',
// attrs: {
// x: 26,
// y: 80,
// fill: '#777',
// fontSize: 14
// },
// },
// {
// tagName: 'text',
// selector: 'workshopName',
// // textContent: '工段1',
// attrs: {
// x: 128,
// y: 80,
// fill: '#777',
// fontSize: 14
// },
// },
],
//
propHooks(metadata) {
const { processName, workshopName, processDesc, processId, ...others } = metadata;
const { detId, detName, detDesc, sectionName, processId, ...others } = metadata;
// debugger;
if (processName) {
console.log("processName", processName)
ObjectExt.setByPath(others, 'attrs/processName/text', processName);
}
if (workshopName) {
console.log("workshopName", workshopName)
ObjectExt.setByPath(others, 'attrs/workshopName/text', workshopName);
}
if (processDesc) {
console.log("processDesc", processDesc)
ObjectExt.setByPath(others, 'attrs/processDesc/text', processDesc);
}
if (processId) {
console.log("processId", processId)
ObjectExt.setByPath(others, 'processId', processId);
}
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/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' }],
};
}
export async function createEdge(src, dest) { }

View File

@ -23,10 +23,21 @@ export default {
components: { ProcessInfo, ProcessDetail, ProcessBomList },
props: {},
data() {
return {};
return {
flowId: null,
};
},
provide() {
const that = this;
return {
getFlowId() {
return that.flowId;
},
};
},
activated() {
console.log('activated...', this.$route.params);
this.flowId = this.$route.params.id;
},
computed: {},
methods: {},