进度管理-(甘特图)页面

This commit is contained in:
骆乐 2022-11-22 16:31:07 +08:00
parent 98f4621d26
commit ac241956ea
2 changed files with 252 additions and 120 deletions

View File

@ -28,3 +28,11 @@ export const getTaskAlarmApi = data => get('/progressTaskAlarm/selectPage', data
//分布详情--组件 //分布详情--组件
export const getDetailInfoApi = data => post('/xmgl/progressItem/getProjectProgressItemDetail', data);// 获取详情信息 export const getDetailInfoApi = data => post('/xmgl/progressItem/getProjectProgressItemDetail', data);// 获取详情信息
export const addPlanInfoApi = data => post('/xmgl/progressItemFeedback/add', data);// 新增进度反馈 export const addPlanInfoApi = data => post('/xmgl/progressItemFeedback/add', data);// 新增进度反馈
//甘特图-页面
export const addProgressTaskApi = data => post('/xmgl/progressTask/addProgressTask', data);// 新增进度甘特图
export const deleteTaskAlarmApi = data => get('/xmgl/progressTask/deleteById', data);// 根据id删除进度甘特图
export const editProgressTaskApi = data => post('/xmgl/progressTask/updateProgressTask', data);// 修改进度甘特图
export const getParentChildListApi = data => get('/xmgl/progressTask/getParentChildList', data);// 所有进度甘特图, 以父子节点形式呈现

View File

@ -1,67 +1,53 @@
<template> <template>
<div style="height: 900px"> <div style="height: 100%">
<div ref="gantt" style="height: 100%" v-loading="ganttLoading"></div> <div ref="gantt" style="height: 100%"></div>
</div> </div>
</template> </template>
<script> <script>
import {
addProgressTaskApi, //
deleteTaskAlarmApi, //
editProgressTaskApi, //
getParentChildListApi, //
} from "@/assets/js/api/scheduleInfo";
import { gantt } from "dhtmlx-gantt"; import { gantt } from "dhtmlx-gantt";
import moment from "moment"; import moment from "moment";
import {getProgressListDataApi} from "@/assets/js/api/scheduleInfo"; import { Model } from "echarts";
export default { export default {
name: "gantt", name: "gantt",
// props: { props: {
// tasks: { tasks: {
// type: Object, type: Object,
// default() { default() {
// return { data: [], links: [] }; return {
// }, data: [],
// }, links: [
// }, { source: 1, target: 2, type: "1" }, //sourceidtargetpredecessorIds","
{ source: 2, target: 3, type: "0" },
],
};
},
},
},
data() { data() {
return { return {
title: "", title: "",
width: 800, width: 800,
visible: false, visible: false,
disablesubmit: false, disablesubmit: false,
ganttLoading: false, projectSn: "", //sn
tasks: { dataList:[],//
data: [],
links: []
// data: [
// {
// id: 1, text: "Project #2", start_date: "01-04-2018", duration: 18, order: 10,
// progress: 0.4, open: true
// },
// {
// id: 2, text: "Task #1", start_date: "02-04-2018", duration: 8, order: 10,
// progress: 0.6, parent: 1
// },
// {
// id: 3, text: "Task #2", start_date: "11-04-2018", duration: 8, order: 20,
// progress: 0.6, parent: 1
// }
// ],
// links: [
// {id: 1, source: 1, target: 2, type: "1"},
// {id: 2, source: 2, target: 3, type: "0"}
// ]
},
projectSn:''
}; };
}, },
created(){
this.projectSn = this.$store.state.projectSn;
this.getProgressListData()
},
mounted: function () { mounted: function () {
// //
gantt.config.xml_date = "%Y-%m-%d"; gantt.config.xml_date = "%Y-%m-%d";
// //
gantt.config.autofit = true; gantt.config.autofit = true;
// //
gantt.config.grid_width = 800; gantt.config.grid_width = 850;
//线 //线
gantt.config.drag_links = false; gantt.config.drag_links = true;
// //
gantt.config.readonly = false; gantt.config.readonly = false;
// //
@ -125,18 +111,16 @@ export default {
icon_delete: "删除", icon_delete: "删除",
confirm_closing: "请确认是否撤销修改!", //Your changes will be lost, are your sure? confirm_closing: "请确认是否撤销修改!", //Your changes will be lost, are your sure?
confirm_deleting: "是否删除计划?", confirm_deleting: "是否删除计划?",
section_description: "描述:", section_description: "备注:",
section_time: "时间范围:", section_time: "时间范围:",
section_type: "类型", section_type: "类型",
section_text: "计划名称:", section_text: "任务名称:",
section_color: "颜色:", section_color: "颜色:",
//-----
section_duration: "工期", section_status: "完成状态:",
section_actualStartDate: "实际开始时间", section_progress: "进度比例:",
section_actualFinishDate: "实际结束时间", section_taskmode: "任务模式:",
section_progressRatio: "进度比例", section_taskduration: "任务工期:",
section_remark: "备注",
/* grid columns */ /* grid columns */
@ -144,9 +128,11 @@ export default {
column_start_date: "开始时间", column_start_date: "开始时间",
column_duration: "持续时间", column_duration: "持续时间",
column_add: "", column_add: "",
column_id: "",
// column_predecessors: "",
column_actual_start_date: "",
column_actual_end_date: "",
column_duration: "",
/* link confirmation */ /* link confirmation */
@ -167,18 +153,59 @@ export default {
years: "年", years: "年",
}, },
}; };
//
//
gantt.config.columns = [ gantt.config.columns = [
{ name: "taskName", label: "计划名称", tree: true, width: "*" }, { name: "id", label: "id", width: "160", align: "center" },
{ name: "startDate", label: "预计开始时间", align: "center" },
{ name: "finishDate", label: "预计结束时间", align: "center" },
{ name: "actualStartDate", label: "实际开始时间", align: "center" },
{ name: "actualFinishDate", label: "实际结束时间", align: "center" },
{ name: "duration", label: "工期", align: "center" },
{ {
name: "progressRatio", name: "text",
label: "进度", label: "任务名称",
tree: true,
width: "120",
align: "center", align: "center",
resize: true,
},
{
name: "predecessorIds",
label: "前置任务",
width: "100",
align: "center",
resize: true,
},
{
name: "start_date",
label: "计划开始日期",
align: "center",
width: "100",
resize: true,
},
{
name: "end_date",
label: "计划完成日期",
align: "center",
width: "100",
resize: true,
},
{
name: "actual_start_date",
label: "实际开始日期",
align: "center",
width: "100",
resize: true,
},
{
name: "actual_end_date",
label: "实际完成日期",
align: "center",
width: "100",
resize: true,
},
{ name: "duration", label: "任务工期", align: "center" },
{
name: "duration",
label: "进度比例",
align: "center",
resize: true,
template: function (obj) { template: function (obj) {
return Math.floor(obj.progress * 100).toString() + "%"; return Math.floor(obj.progress * 100).toString() + "%";
}, },
@ -187,50 +214,115 @@ export default {
]; ];
// //
gantt.config.lightbox.sections = [ gantt.config.lightbox.sections = [
{name: "text",height: 70,map_to: "text",type: "textarea",focus: true, width: 200,}, // //
{name: "duration",height: 70,map_to: "text",type: "text",focus: true, width: 200,}, {
{name: "actualStartDate", height: 40, map_to: "auto",type:"time", time_format: ["%Y", "%m", "%d"], focus: true}, name: "text",
{name: "actualFinishDate", height: 40, map_to: "auto",type:"time", time_format: ["%Y", "%m", "%d"], focus: true}, height: 30,
{name: "progressRatio", height: 40, map_to: "text", type: "textarea", focus: true}, map_to: "text",
{name: "remark", height: 40, map_to: "text", type: "textarea", focus: true}, type: "textarea",
{name: "time",height: 30,map_to: "auto",type: "time",time_format: ["%Y", "%m", "%d"]}, focus: true,
{name: "color",height: 30,map_to: "color",type: "select",options: [ width: 200,
},
//
{
name: "time",
height: 30,
map_to: "start_date",
type: "time",
time_format: ["%Y", "%m", "%d"],
},
//
{
name: "status",
height: 30,
map_to: "status",
type: "select",
options: [
{ value: 0, label: "未开始" },
{ value: 1, label: "进行中" },
{ value: 2, label: "已完成" },
],
},
//
{
name: "taskmode",
height: 30,
map_to: "taskTypeId",
type: "select",
options: [
{ value: 0, label: "手动" },
{ value: 1, label: "自动" },
],
},
//
{
name: "taskduration",
height: 30,
map_to: "duration",
type: "textarea",
focus: true,
},
//
{
name: "progress",
height: 30,
map_to: "progress",
type: "textarea",
focus: true,
},
//
{
name: "color",
height: 30,
map_to: "color",
type: "select",
options: [
{ key: "#3db9d3", label: "蓝色" }, { key: "#3db9d3", label: "蓝色" },
{ key: "#33cc33", label: "绿色" }, { key: "#3299CC", label: "天蓝色" },
{ key: "#FF8247", label: "橙色" }, { key: "#FF8247", label: "橙色" },
{ key: "#ff6633", label: "红色" }, { key: "#ff6633", label: "红色" },
], ],
}, },
//
{
name: "description",
height: 40,
map_to: "remark",
type: "textarea",
},
]; ];
// //
gantt.templates.task_time = function (start, end, task) { gantt.templates.task_time = function (start, end, task) {
return ( return (
moment(start).format("YYYY-MM-DD") + moment(task.startDate).format("YYYY-MM-DD") +
" - " + " - " +
moment(end).format("YYYY-MM-DD") moment(task.finishDate).format("YYYY-MM-DD")
); );
}; };
// //
gantt.templates.task_text = function (start, end, task,a,b,c,d) { gantt.templates.task_text = function (start, end, task) {
console.log('start, end, task',start, end, task,a,b,c,d)
return task.text; return task.text;
}; };
gantt.init(this.$refs.gantt); gantt.init(this.$refs.gantt);
gantt.parse(this.tasks); gantt.parse(this.$props.tasks);
let this_ = this; let this_ = this;
// //
gantt.attachEvent("onAfterTaskAdd", function (id, item) { gantt.attachEvent("onAfterTaskAdd", function (id, item) {
console.log("添加后触发"); console.log("添加后触发", item);
// addProgressTaskApi(this.dataList).then((res) => {
// console.log("",res);
// });
this_.changeTask(); this_.changeTask();
}); });
// //
gantt.attachEvent("onAfterTaskDrag", function (id, mode, e) { gantt.attachEvent("onAfterTaskDrag", function (id, mode, e) {
console.log("移动进度后触发"); console.log("移动进度后触发mode", mode);
this_.changeTask(); this_.changeTask();
}); });
// //
gantt.attachEvent("onAfterTaskMove", function (id, parent, tindex) { gantt.attachEvent("onAfterTaskMove", function (id, parent, tindex) {
console.log("移动任务后触发"); console.log("移动任务后触发", mode);
this_.changeTask(); this_.changeTask();
}); });
// //
@ -243,79 +335,111 @@ export default {
console.log("修改任务后触发"); console.log("修改任务后触发");
this_.changeTask(); this_.changeTask();
}); });
//
gantt.attachEvent("onTaskDrag", function (id, mode, task, original) {
// console.log("",id, mode, task, original);
});
// //
gantt.attachEvent("onLightboxSave", function (id, item) { gantt.attachEvent("onLightboxSave", function (id, item) {
if (!item.text) { setTimeout(function () {
gantt.message({ type: "error", text: "请填写计划名称!" }); console.log("保存验证,", item);
return false; if (!item.taskName) {
} gantt.message({ type: "error", taskName: "请填写任务名称!" });
return false;
}
}, 2000);
return true; return true;
}); });
}, },
created() {
this.projectSn = this.$store.state.projectSn;
this.getParentChildList();
},
methods: { methods: {
// //
getProgressListData() {
this.ganttLoading= true;
this.tasks.data = [];
let data = {
projectSn: this.projectSn,
};
getProgressListDataApi(data).then((res) => {
if (res.code == 200) {
console.log("获取到的列表", res);
this.tasks.data = res.result;
// :gantt
gantt.parse(this.tasks);
console.log('获取到的列表',this.tasks)
//
gantt.refreshData();
this.ganttLoading= false;
}else{
this.$message.error('查询失败!');
}
});
},
changeTask() { changeTask() {
// return
const taskCount = gantt.getTaskCount(); const taskCount = gantt.getTaskCount();
let taskData = []; let taskData = [];
let openTask = []; let openTask = [];
for (let i = 0; i < taskCount; i++) { for (let i = 0; i < taskCount; i++) {
let taskOne = {}; let taskOne = {};
const obj = gantt.getTaskByIndex(i); const obj = gantt.getTaskByIndex(i);
console.log('======obj',obj) console.log("整理数据的 ", obj);
taskOne.taskName = obj.taskName;
// //
if (obj.$open == true) { if (obj.$open == true) {
openTask.push(obj.id); openTask.push(obj.id);
} }
// //
taskOne.id = obj.id; taskOne.id = obj.id;
taskOne.text = obj.text; taskOne.text = obj.taskName || obj.text;
taskOne.start_date = moment(obj.start_date).format("YYYY-MM-DD"); if (obj.start_date) {
taskOne.end_date = moment(obj.end_date).format("YYYY-MM-DD"); taskOne.start_date = moment(obj.start_date).format("YYYY-MM-DD");
}
if (obj.end_date) {
taskOne.end_date = moment(obj.end_date).format("YYYY-MM-DD");
}
if (obj.startDate != null) {
console.log(111111111111111111);
taskOne.start_date = moment(obj.startDate).format("YYYY-MM-DD");
}
if (obj.finishDate != null) {
taskOne.end_date = moment(obj.finishDate).format("YYYY-MM-DD");
}
if (obj.actualStartDate != null) {
taskOne.actual_start_date = moment(obj.actualStartDate).format(
"YYYY-MM-DD"
);
}
if (obj.actualFinishDate != null) {
taskOne.actual_end_date = moment(obj.actualFinishDate).format(
"YYYY-MM-DD"
);
}
taskOne.duration = obj.duration; taskOne.duration = obj.duration;
taskOne.progress = obj.progress; taskOne.progress = obj.progressRatio;
taskOne.description = obj.description; taskOne.description = obj.remark;
taskOne.color = obj.color; taskOne.predecessorIds = obj.predecessorIds;
if (obj.parent) { taskOne.parent = obj.parent
taskOne.parent = obj.parent; taskOne.color = "#3db9d3";
if (obj.parentId) {
taskOne.parent = obj.parentId;
} }
taskData.push(taskOne); taskData.push(taskOne);
} }
this.tasks.data = taskData; this.$props.tasks.data = taskData;
console.log(this.$props.tasks);
console.log(this.$props.tasks);
// //
gantt.clearAll(); gantt.clearAll();
// //
gantt.parse(this.tasks); gantt.parse(this.$props.tasks);
//使 //使
openTask.forEach((id) => { openTask.forEach((id) => {
gantt.open(id); gantt.open(id);
}); });
}, },
//
getParentChildList() {
getParentChildListApi({ projectSn: this.projectSn }).then((res) => {
this.tasks.data = res.result;
this.dataList=res.result
console.log("甘特图列表数据", this.tasks.data);
console.log(" this.dataList", this.dataList);
gantt.parse(this.$props.tasks);
this.changeTask();
});
},
}, },
}; };
</script> </script>
<style> <style lang="less" scoped>
@import "~dhtmlx-gantt/codebase/dhtmlxgantt.css"; @import "~dhtmlx-gantt/codebase/dhtmlxgantt.css";
</style> </style>