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

View File

@ -217,7 +217,7 @@ export function getTime(type) {
export function debounce(func, wait, immediate) { export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result let timeout, args, context, timestamp, result
const later = function() { const later = function () {
// 据上一次触发时间间隔 // 据上一次触发时间间隔
const last = +new Date() - timestamp const last = +new Date() - timestamp
@ -234,7 +234,7 @@ export function debounce(func, wait, immediate) {
} }
} }
return function(...args) { return function (...args) {
context = this context = this
timestamp = +new Date() timestamp = +new Date()
const callNow = immediate && !timeout const callNow = immediate && !timeout
@ -438,3 +438,7 @@ export function toCamelCase(str, upperCaseFirst) {
return str; return str;
} }
export function IdToName(targetId, source, prop = 'name') {
return source.find(item => item.id === targetId)?.[prop]
}

View File

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

View File

@ -9,193 +9,477 @@
<section class="process-graph"> <section class="process-graph">
<SearchBar :formConfigs="searchBarFormConfig" ref="search-bar" /> <SearchBar :formConfigs="searchBarFormConfig" ref="search-bar" />
<div <div class="btns" style="text-align: right; position: absolute; top: 20px; right: 20px">
class="btns" <el-button type="warning" @click="undo" plain v-if="allowUndo" :disabled="!allowUndo" icon="el-icon-back">
style="text-align: right; position: absolute; top: 20px; right: 20px"> 撤销
<el-button </el-button>
type="primary" <el-button type="warning" @click="redo" plain v-if="allowRedo" :disabled="!allowRedo">
plain 下一步
class="btn-create" <i class="el-icon-right el-icon--right"></i>
icon="el-icon-plus" </el-button>
@click="createDet"> <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>
<el-button class="btn-serialize" @click="graphToJson">序列化</el-button> <el-button class="btn-serialize" @click="handleToJson">序列化</el-button>
<el-button class="btn-antiserialize" @click="jsonToGraph"> <el-button class="btn-antiserialize" @click="handleLoadJson">
反序列化 反序列化
</el-button> </el-button>
<el-button class="btn-edit" @click="handleEdit">编辑</el-button>
<el-button type="error" 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"
@confirm="submitForm">
<DialogForm v-if="open" ref="form" v-model="form" :rows="rows" />
</base-dialog>
</section> </section>
</template> </template>
<script> <script>
import { Graph } from '@antv/x6'; 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); Graph.registerNode('process-node', ProcessNode);
export default { export default {
name: 'ProcessGraph', name: 'ProcessGraph',
components: {}, components: { DialogForm },
props: {}, props: {},
inject: ['getFlowId'],
data() { data() {
return { return {
allowRedo: false,
allowUndo: false,
graph: null, graph: null,
searchBarFormConfig: [{ label: '工序列表' }], 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() { watch: {
const graph = new Graph({ 'form.sectionId': {
container: this.$refs.panel, handler(id) {
grid: { // const { form } = this;
size: 10, // const { sectionId } = form;
visible: false, // if (sectionId) {
type: 'dot', // const { label } = this.$refs['form'].getSelectItem(
args: { // 'sectionId',
color: '#f005', // sectionId
thickness: 1, // );
}, // form.workshopName = label;
// }
}, },
}); immediate: false,
},
},
activated() {
this.loadLayout().then(json => {
this.initGraph(json)
})
const pn1 = graph.addNode({ // const pn1 = graph.addNode({
shape: 'process-node', // shape: 'process-node',
x: 30, // x: 30,
y: 30, // y: 30,
processName: '工序00A', // processName: '00A',
workshopName: '工段1', // workshopName: '1',
processDesc: 'test test test', // processDesc: 'test test test',
processId: '1', // processId: '1',
}); // tools: [{ name: 'button-remove' }],
const pn2 = graph.addNode({ // });
shape: 'process-node', // const pn2 = graph.addNode({
x: 240, // shape: 'process-node',
y: 30, // x: 240,
processName: '工序00B', // y: 30,
workshopName: '工段1', // processName: '00B',
processDesc: 'test test test', // workshopName: '1',
processId: '1', // processDesc: 'test test test',
}); // processId: '1',
// });
const pn3 = graph.addNode({ // const pn3 = graph.addNode({
shape: 'process-node', // shape: 'process-node',
x: 360, // x: 360,
y: 30, // y: 30,
processName: '工序00C', // processName: '00C',
workshopName: '工段1', // workshopName: '1',
processDesc: 'test test test', // processDesc: 'test test test',
processId: '1', // processId: '1',
}); // });
const pn4 = graph.addNode({ // const pn4 = graph.addNode({
shape: 'process-node', // shape: 'process-node',
x: 360, // x: 360,
y: 120, // y: 120,
processName: '工序00D', // processName: '00D',
workshopName: '工段1', // workshopName: '1',
processDesc: 'test test test', // processDesc: 'test test test',
processId: '1', // processId: '1',
}); // });
const pn5 = graph.addNode({ // const pn5 = graph.addNode({
shape: 'process-node', // shape: 'process-node',
x: 500, // x: 500,
y: 30, // y: 30,
processName: '工序00E', // processName: '00E',
workshopName: '工段1', // workshopName: '1',
processDesc: 'test test test', // processDesc: 'test test test',
processId: '1', // processId: '1',
}); // });
graph.addEdge({ // graph.addEdge({
source: pn1, // source: pn1,
target: pn2, // target: pn2,
attrs: { // router: {
line: { // name: 'er',
stroke: '#0b58ff', // },
strokeWidth: 1, // attrs: {
targetMarker: { // line: {
// name: 'classic', // stroke: '#0b58ff',
// name: 'async', // strokeWidth: 1,
size: 0, // targetMarker: {
}, // // name: 'classic',
}, // // name: 'async',
}, // size: 0,
}); // },
graph.addEdge({ // },
source: pn2, // },
target: pn3, // });
attrs: { // graph.addEdge({
line: { // source: pn2,
stroke: '#0b58ff', // target: pn3,
strokeWidth: 1, // router: {
targetMarker: { // name: 'er',
// name: 'classic', // },
// name: 'async', // attrs: {
size: 0, // line: {
}, // stroke: '#0b58ff',
}, // strokeWidth: 1,
}, // targetMarker: {
}); // // name: 'classic',
graph.addEdge({ // // name: 'async',
source: pn2, // size: 0,
target: pn4, // },
attrs: { // },
line: { // },
stroke: '#0b58ff', // });
strokeWidth: 1, // graph.addEdge({
targetMarker: { // source: pn2,
// name: 'classic', // target: pn4,
// name: 'async', // router: {
size: 0, // name: 'er',
}, // },
}, // attrs: {
}, // line: {
}); // stroke: '#0b58ff',
graph.addEdge({ // strokeWidth: 1,
source: pn3, // targetMarker: {
target: pn5, // // name: 'classic',
attrs: { // // name: 'async',
line: { // size: 0,
stroke: '#0b58ff', // },
strokeWidth: 1, // },
targetMarker: { // },
// name: 'classic', // });
// name: 'async', // graph.addEdge({
size: 0, // source: pn3,
}, // target: pn5,
}, // router: {
}, // name: 'er',
}); // },
graph.addEdge({ // attrs: {
source: pn4, // line: {
target: pn5, // stroke: '#0b58ff',
attrs: { // strokeWidth: 1,
line: { // targetMarker: {
stroke: '#0b58ff', // // name: 'classic',
strokeWidth: 1, // // name: 'async',
targetMarker: { // size: 0,
// 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: {}, computed: {},
methods: { methods: {
createDet() {}, initGraph(json) {
jsonToGraph() {}, const graph = new Graph({
graphToJson() { 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) { if (this.graph) {
console.log(JSON.stringify(this.graph.toJSON(), null, 2)); 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> </script>
@ -212,3 +496,9 @@ export default {
height: 300px; height: 300px;
} }
</style> </style>
<style>
.x6-widget-selection-selected {
border: 1px solid red;
}
</style>

View File

@ -11,37 +11,34 @@
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="6"> <el-col :span="6">
<InfoItem label="工艺名称" value="测试工艺" /> <InfoItem label="工艺名称" :value="form.name" />
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
<InfoItem label="产线" value="A4" /> <InfoItem label="产线" :value="form.lineName" />
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<InfoItem <InfoItem label="工艺描述" :value="form.remark" />
label="工艺描述"
value="咯热门asdfkj alsdfk ;lkj flskdjf sadf" />
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="20" style="margin-top: 12px;"> <el-row :gutter="20" style="margin-top: 12px;">
<el-col :span="6"> <el-col :span="6">
<InfoItem label="创建人" value="xxse" /> <!-- <InfoItem label="创建人" value="xxse" /> -->
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
<InfoItem label="创建时间" value="2023-10-22 10:11:00" /> <InfoItem label="创建时间" :value="form.createTime" />
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
<InfoItem label="更新人" value="xxse" /> <!-- <InfoItem label="更新人" value="xxse" /> -->
</el-col> </el-col>
<el-col :span="6"> <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-col>
</el-row> </el-row>
</section> </section>
</template> </template>
<script> <script>
import basicPageMixin from '@/mixins/lb/basicPageMixin';
const InfoItem = { const InfoItem = {
name: 'InfoItem', name: 'InfoItem',
@ -67,16 +64,63 @@ const InfoItem = {
export default { export default {
name: 'ProcessInfo', name: 'ProcessInfo',
components: { InfoItem }, components: { InfoItem },
mixins: [basicPageMixin],
props: {}, props: {},
inject: ['getFlowId'],
data() { data() {
return { return {
infoUrl: '/extend/process-flow/get', infoUrl: '/extend/process-flow/get',
searchBarFormConfig: [{ label: '工艺详情' }], searchBarFormConfig: [{ label: '工艺详情' }],
form: {
id: null,
name: null,
lineName: null,
createTime: null,
remark: null,
enable: null,
code: null
},
}; };
}, },
activated() {
this.getInfo()
},
computed: {}, 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> </script>

View File

@ -1,23 +1,23 @@
import { Node, ObjectExt } from '@antv/x6'; 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({ ProcessNode.config({
width: 240, width: 240,
height: 100, height: 100,
markup: [ markup: [
{ {
tagName: 'rect', tagName: 'rect',
selector: 'container',
attrs: { attrs: {
x: 0, x: 0,
y: 0, y: 0,
width: 200, width: 200,
height: 100, height: 100,
fill: 'transparent', fill: 'transparent',
stroke: '#0b58ff' stroke: '#ccc'
}, },
}, },
{ {
@ -42,94 +42,75 @@ ProcessNode.config({
}, },
{ {
tagName: 'text', tagName: 'text',
selector: 'processName', selector: 'detName',
attrs: { attrs: {
x: 20, x: 20,
y: 30, y: 30,
// fill: '#777',
// fontSize: 14
}, },
}, },
{ {
tagName: 'text', tagName: 'text',
selector: 'workshopName', selector: 'sectionName',
attrs: { attrs: {
x: 115, x: 115,
y: 30, y: 30,
// fill: '#777',
// fontSize: 14
}, },
}, },
{ {
tagName: 'text', tagName: 'text',
selector: 'processDesc', selector: 'detDesc',
// textContent: '工序00A',
attrs: { attrs: {
x: 26, x: 26,
y: 80, y: 80,
fill: '#777', 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) { propHooks(metadata) {
const { processName, workshopName, processDesc, processId, ...others } = metadata; const { detId, detName, detDesc, sectionName, processId, ...others } = metadata;
// debugger; // debugger;
if (processName) { if (detName) ObjectExt.setByPath(others, 'attrs/detName/text', detName);
console.log("processName", processName) if (detDesc) ObjectExt.setByPath(others, 'attrs/detDesc/text', detDesc);
ObjectExt.setByPath(others, 'attrs/processName/text', processName); if (sectionName) ObjectExt.setByPath(others, 'attrs/sectionName/text', sectionName);
} if (detId) ObjectExt.setByPath(others, 'attrs/detId/text', detId);
if (workshopName) { if (processId) ObjectExt.setByPath(others, 'attrs/processId/text', processId);
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);
}
return others; 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 }, components: { ProcessInfo, ProcessDetail, ProcessBomList },
props: {}, props: {},
data() { data() {
return {}; return {
flowId: null,
};
},
provide() {
const that = this;
return {
getFlowId() {
return that.flowId;
},
};
}, },
activated() { activated() {
console.log('activated...', this.$route.params); console.log('activated...', this.$route.params);
this.flowId = this.$route.params.id;
}, },
computed: {}, computed: {},
methods: {}, methods: {},