甘特图显示

This commit is contained in:
JinLu.Yin 2022-05-16 21:39:22 +08:00
parent 5a914e25a0
commit f2b2dbc363
4 changed files with 110 additions and 20 deletions

View File

@ -9,6 +9,16 @@ export function listProtask(query) {
}) })
} }
// 查询生产任务列表
export function listGanttTaskList(query) {
return request({
url: '/mes/pro/protask/listGanttTaskList',
method: 'get',
params: query
})
}
// 查询生产任务详细 // 查询生产任务详细
export function getProtask(taskId) { export function getProtask(taskId) {
return request({ return request({

View File

@ -26,7 +26,9 @@ export default {
mounted: function () { mounted: function () {
// //
this.initConfig(); this.initConfig();
gantt.plugins({
marker: true
});
// //
gantt.init(this.$refs.gantt); gantt.init(this.$refs.gantt);
gantt.parse(this.tasks); gantt.parse(this.tasks);
@ -36,6 +38,23 @@ export default {
// //
initData() { initData() {
},
reload() {
gantt.clearAll();
this.addTodayLine();
gantt.parse(this.$props.tasks);
gantt.render();
},
addTodayLine() {
// 线
var date_to_str = gantt.date.date_to_str(gantt.config.task_date);
var today = new Date();
gantt.addMarker({
start_date: today,
css: "today",
text: "今天",
title: "今天: " + date_to_str(today)
});
}, },
// //
initConfig() { initConfig() {
@ -43,38 +62,84 @@ export default {
// 1.1 // 1.1
gantt.config.readonly = true; gantt.config.readonly = true;
// 1.2 // 1.2
gantt.config.duration_unit="hour";
gantt.config.duration_step=8;
gantt.config.grid_width=520;
gantt.config.columns = [ gantt.config.columns = [
{name:"text", label:"任务名", tree:true, width:'100' }, {name:"text", label:"任务名", tree:true, width:'200' },
{name:"workstation",label:"工作站",align:"center",width:'*'}, {name:"workstation",label:"工作站",align:"center",width:'*'},
{name:"process",label:"工序",align:"center",width:'*'},
{name:"start_date", label:"开始时间", align:"center", width:'*' }, {name:"start_date", label:"开始时间", align:"center", width:'*' },
{name:"end_date", label:"结束时间", align:"center" , width:'*'}, {name:"end_date", label:"结束时间", align:"center" , width:'*'},
// {name:"duration", label:"Duration", align: "center" },
]; ];
// 1.3 // 1.3
gantt.i18n.setLocale("cn"); gantt.i18n.setLocale("cn");
// 1.4 // 1.4
gantt.plugins({tooltip: true});// tooltip gantt.plugins({tooltip: true});// tooltip
gantt.templates.tooltip_text = function(start, end, task) { gantt.templates.tooltip_text = function(start, end, task) {
return "<b>任务名称:</b> "+task.text+"<br/><b>时长:</b> " + task.duration+"天<br/><b>说明:</b>" +task.toolTipsTxt; if(task.type=='project'){
} return "<b style='text-align:left;'>生产工单:</b> " + task.text +" <span style='text-align:left;'>" +" 完成比例:"+ Math.round(task.progress * 100) + "% </span>";
}else{
return "<b style='text-align:left;'>生产任务:</b> "+task.process+" "+ task.text +" <span style='text-align:left;'>" +" 完成比例:"+ Math.round(task.progress * 100) + "% </span>";
}
};
// 1.5 // 1.5
gantt.config.open_tree_initially = true; gantt.config.open_tree_initially = true;
// 1.6 // 1.6
gantt.templates.task_text = function (start, end, task) { gantt.templates.task_text = function (start, end, task) {
return "<b style='text-align:left;'>计划名称:</b> " + task.text +" <span style='text-align:left;'>" +" 完成计划:"+ Math.round(task.progress * 100) + "% </span>"; if(task.type=='project'){
return "<b style='text-align:left;'>生产工单:</b> " + task.text +" <span style='text-align:left;'>" +" 完成比例:"+ Math.round(task.progress * 100) + "% </span>";
}else{
return "<b style='text-align:left;'>生产任务:</b> "+task.process+" "+ task.text +" <span style='text-align:left;'>" +" 完成比例:"+ Math.round(task.progress * 100) + "% </span>";
}
}; };
// 1.7 // 1.7
gantt.config.show_task_cells = true; gantt.config.show_task_cells = true;
// 2 // 2
// 2.1 minute/hour/day/week/quarter/month/year // 2.1 minute/hour/day/week/quarter/month/year
gantt.config.scale_unit = "day"; // gantt.config.scale_unit = "hour";
// 2.2 // 2.2
gantt.config.date_scale = "%d"; // gantt.config.date_scale = "%H";
// 2.3 // 2.3
gantt.config.subscales = [{unit: "month", step: 1, date: "%Y,%F"}]; // gantt.config.subscales = [{unit: "month", step: 1, date: "%Y,%F"}];
var weekScaleTemplate = function (date) {
var dateToStr = gantt.date.date_to_str("%M %d");
var endDate = gantt.date.add(gantt.date.add(date, 1, "week"), -1, "day");
return dateToStr(date) + " - " + dateToStr(endDate);
};
var dayTemplate = function(date){
var dateToStr = gantt.date.date_to_str("%M %d");
var weekDay = gantt.date.date_to_str("%D");
return dateToStr(date); + "(" + weekDay(date) + ")";
};
var daysStyle = function(date){
// you can use gantt.isWorkTime(date)
// when gantt.config.work_time config is enabled
// In this sample it's not so we just check week days
if(date.getDay() === 0 || date.getDay() === 6){
return "weekend";
}
return "";
};
gantt.config.scales =[
{unit:"week", step:1,format: weekScaleTemplate},
{unit:"day", step:1,format: dayTemplate,css: daysStyle},
{unit:"hour", step:8,format: "%H:%i"}, //step812
]
gantt.config.scale_height = 50;
// 2.4 // 2.4
gantt.config.xml_date = "%Y-%m-%d"; gantt.config.xml_date = "%Y-%m-%d %H:%i:%s";
// 3 // 3
// 3.1 ,project // 3.1 ,project
@ -82,7 +147,7 @@ export default {
// 3.2 // 3.2
gantt.config.drag_progress = true; gantt.config.drag_progress = true;
// 3.3 Task // 3.3 Task
gantt.config.drag_move = false; gantt.config.drag_move = true;
// 3.4 // 3.4
gantt.config.drag_links = true; gantt.config.drag_links = true;
// 3.5 Task // 3.5 Task
@ -189,4 +254,13 @@ export default {
width: calc(100% - 199px) !important; width: calc(100% - 199px) !important;
left: 199px; left: 199px;
} }
.scaleStyle{
height: 20px;
}
/* 周末背景颜色 */
.weekend{
background: rgb(189, 185, 186) !important;
width: 30s
}
</style> </style>

View File

@ -268,6 +268,7 @@
<script> <script>
import { listWorkorder, getWorkorder, delWorkorder, addWorkorder, updateWorkorder } from "@/api/mes/pro/workorder"; import { listWorkorder, getWorkorder, delWorkorder, addWorkorder, updateWorkorder } from "@/api/mes/pro/workorder";
import {listGanttTaskList} from "@/api/mes/pro/protask";
import { listProductprocess } from "@/api/mes/pro/routeprocess"; import { listProductprocess } from "@/api/mes/pro/routeprocess";
import ProTask from "./proTask.vue"; import ProTask from "./proTask.vue";
import GanttChar from "./ganttx.vue"; import GanttChar from "./ganttx.vue";
@ -330,14 +331,8 @@ export default {
status: null, status: null,
}, },
tasks:{ tasks:{
data: [ data: [],
{id: "MO202205150001", text: '移液盒【黑色】10000个', start_date: '2020-01-17', duration: 23, progress: 0.6,type: 1}, links: []
{id: 2, text: 'Task #1', start_date: '2020-01-20', duration: 30, progress: 0.4, parent:"MO202205150001", type: 2},
{id: 3, text: 'Task #2', start_date: '2020-01-20', duration: 3, progress: 0.4, parent: "MO202205150001", type: 2},
{id: "MO202205150002", text: '96孔孔板 10000个', start_date: '2020-01-17', duration: 23, progress: 0.6, parent:"MO202205150001", type: 1},
{id: 4, text: 'Task #3', start_date: '2020-01-20', duration: 30, progress: 0.4, parent:"MO202205150002", type: 2},
{id: 5, text: 'Task #4', start_date: '2020-01-20', duration: 3, progress: 0.4, parent: "MO202205150002", type: 2},
],
}, },
// //
form: {}, form: {},
@ -345,6 +340,7 @@ export default {
}, },
created() { created() {
this.getList(); this.getList();
this.getGanttTasks();
}, },
methods: { methods: {
/** 查询生产工单列表 */ /** 查询生产工单列表 */
@ -355,6 +351,16 @@ export default {
this.loading = false; this.loading = false;
}); });
}, },
getGanttTasks(){
listGanttTaskList(this.queryParams).then(response =>{
debugger;
this.tasks.data = response.data.data;
this.tasks.links = response.data.links;
this.$refs.ganttChar.reload();
});
},
getProcess(){ getProcess(){
listProductprocess(this.form.productId).then(response =>{ listProductprocess(this.form.productId).then(response =>{
this.processOptions = response.data; this.processOptions = response.data;

View File

@ -272,7 +272,7 @@ export default {
+ '00'; + '00';
this.form.startTime = startDate; this.form.startTime = startDate;
startDate = Date.parse(new Date(startDate))/1000; startDate = Date.parse(new Date(startDate))/1000;
startDate += (3600) * this.form.duration; startDate += (3600)* 8 * this.form.duration; //8
let endDate = new Date(parseInt(startDate) * 1000); let endDate = new Date(parseInt(startDate) * 1000);
this.form.endTime =endDate.getFullYear() + '-' this.form.endTime =endDate.getFullYear() + '-'
+ (endDate.getMonth()+1) + '-' + (endDate.getMonth()+1) + '-'