w-vue-middle
Version:
统一公共服务组件
276 lines (263 loc) • 7.83 kB
JavaScript
/*
* @Author: Jason Liu
* @Date: 2023-08-10 14:10:36
* @Desc:
*/
/**
* @Author: Jason Liu
* @description: 调度服务接口
*/
const $dispatchcenter = require('w-vue-middle/api/dispatchcenter');
/**
* @Author: Jason Liu
* @description: 数据集成服务
*/
const $dataIntegration = require('w-vue-middle/api/dataIntegration');
const layouts = require('./layouts');
export default {
components: { ...layouts },
props: {
value: {
type: Boolean,
default: false,
},
processId: {
//流程ID
type: [String, Number],
},
jobType: {
//流程类型
type: String,
},
jobGroupId: {
//流程分组ID
type: String,
},
},
data() {
return {
loading: false,
show: this.value,
jobs: [],
activeJobId: undefined,
hasSqlInput: false, //是否有sql
activeJob: {
id: undefined,
graph: undefined,
dnd: () => {},
loading: false,
change: undefined,
data: {
id: undefined,
jobType: undefined,
jobGroupId: undefined,
},
},
};
},
created() {},
methods: {
/**
* @Author: Jason Liu
* @description: 初始化选中任务
*/
initActiveJob(
param = {
setBase: true,
putawayNode: true,
},
) {
this.jobs = this.jobs.map((job) => {
// if (!job.graph && this.$refs[job.id]) {
// //未初始化
// this.controlsJobList = []; //重置控件列表
// const graphOpetion = this.getGraphOpetion(job.id);
// job.graph = new Graph(graphOpetion);
// this.bindEvent(job);
// job.dnd = new Addon.Dnd({
// target: job.graph,
// scaled: false,
// animation: true,
// });
// if (job.data.jsonDetail) {
// try {
// let cells = JSON.parse(job.data.jsonDetail);
// this.setCanvas(cells, job);
// } catch (e) {}
// }
// }
if (job.id == this.activeJob.id) {
this.activeJob = {
id: this.activeJob.id,
graph: job.graph,
dnd: () => {
return console.log(arguments);
},
loading: job.loading,
change: job.change,
data: job.data,
sourceStep: job.sourceStep,
};
this.jobExtraList = job.data.jobExtra ? JSON.parse(job.data.jobExtra) : {};
this.setBase = param.setBase; //设置基础信息
this.putawayNode = param.putawayNode; //收起node设置
}
return job;
});
},
/**
* @Author: Jason Liu
* @description: 获取job详情
*/
getJobDetail(processId, jobType, sourceStep) {
if (processId) {
this.loading = true;
switch (jobType) {
case 'flow':
$dispatchcenter
.getFlowInfo({ id: processId })
.then((req) => {
let job = {
createBy: undefined,
createTime: undefined,
id: req.data.id,
isDel: 0,
isEnable: 0,
jobType: jobType,
jobDesc: req.data.flowDesc,
jobGroupId: req.data.workflowGroup.id,
jobName: req.data.flowName,
jsonDetail: req.data.flowContent,
parentId: req.data.parentId,
remark: undefined,
updateBy: undefined,
updateTime: undefined,
};
if (job) {
this.activeJob.id = processId;
this.jobs.push({
id: processId,
graph: undefined, //画布
loading: false,
dnd: undefined, //插画
change: false,
data: job,
});
this.initActiveJob();
} else {
this.$message.error($t('该设计已被删除'));
}
})
.finally(() => {
this.loading = false;
});
break;
default:
$dataIntegration
.getJobDetail({ id: processId })
.then((req) => {
let job = req.data;
if (job) {
this.activeJob.id = processId;
this.jobs.push({
id: processId,
graph: undefined, //画布
loading: false,
dnd: undefined, //插画
change: false,
data: job,
sourceStep: sourceStep,
});
if (job.jsonDetailBak) {
this.hasSqlInput = true;
} else {
this.hasSqlInput = false;
}
this.initActiveJob();
} else {
this.$message.error($t('该设计已被删除'));
}
})
.finally(() => {
this.loading = false;
});
break;
}
} else {
let guid = `new_` + new Date().getTime();
let type = jobType || 'job';
let parentId = undefined;
let jobGroupId = this.jobGroupId;
switch (jobType) {
case 'subtransform':
type = 'transform';
jobGroupId = this.activeJob.data.jobGroupId;
parentId = this.activeJob.data.id;
break;
case 'subjob':
type = 'job';
parentId = this.activeJob.data.id;
jobGroupId = this.activeJob.data.jobGroupId;
break;
}
if (
(jobType == 'subtransform' || jobType == 'subjob') &&
parentId &&
parentId.indexOf('new') > -1
) {
//子数据无父级ID
this.$message.warning({
content: $t('请保存好主作业后再做添加操作'),
key: 'subadd',
});
} else {
let job = {
createBy: undefined,
createTime: undefined,
id: guid,
isDel: 0,
isEnable: 0,
jobType: type,
parentId: parentId,
jobDesc: undefined,
jobGroupId: jobGroupId,
jobName: undefined,
jsonDetail: undefined,
remark: undefined,
updateBy: undefined,
updateTime: undefined,
};
this.jobs.push({
id: guid,
graph: undefined, //画布
loading: false,
dnd: undefined, //插画
change: true,
data: job,
sourceStep: sourceStep,
});
this.activeJob.id = guid;
this.initActiveJob();
}
}
},
},
watch: {
value(val) {
this.show = val;
if (val) {
this.activeJobId = undefined; //选中的job
this.jobs = []; //清空
this.getJobDetail(this.processId, this.jobType);
} else {
this.jobs.forEach((item, i) => {
item.graph.dispose(); //销毁画布
});
this.$emit('update');
}
},
show(val) {
this.$emit('input', val);
},
},
};