轉帖|行業資訊|編輯:胡濤|2023-02-03 11:13:38.780|閱讀 415 次
概述:本文介紹項目管理工具DHTMLX Gantt 閉坑指南,歡迎查閱
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
DHTMLX Gantt是用于跨瀏覽器和跨平臺應用程序的功能齊全的Gantt圖表。可滿足項目管理應用程序的大部分開發需求,具備完善的甘特圖圖表庫,功能強大,價格便宜,提供豐富而靈活的JavaScript API接口,與各種服務器端技術(PHP,ASP.NET,Java等)簡單集成,滿足多種定制開發需求。
公司業務需要,管理層做項目管理就會制定項目計劃,為了更好的的做好項目計劃就需要用到做計劃常用的工具甘特圖,而且做好計劃管理對項目的風險管控也有很大的好處。
1.引入
1.引入js
import {gantt , Gantt} from "yys-pro-gantt";2.導入css
import "yys-pro-gantt/codebase/dhtmlxgantt.css"; import "yys-pro-gantt/codebase/skins/dhtmlxgantt_terrace.css";b、style中導入方式
@import "~yys-pro-gantt/codebase/dhtmlxgantt.css"; /*@import "~yys-pro-gantt/codebase/skins/dhtmlxgantt_terrace.css"; // 皮膚*/ @import "./skins/dhtmlxgantt_yys.css"; // 自定義皮膚 不需要下面可以不引入 // import "dhtmlx-gantt/codebase/locale/locale_cn" ; // 本地化 // import "dhtmlx-gantt/codebase/ext/dhtmlxgantt_tooltip.js"; // 任務條懸浮提示 // this.createScript("http://export.dhtmlx.com/gantt/api.js"); // 使用甘特圖自帶的導出功能必須引入 createScript createScript(url: string) { const scriptElement = document.createElement("script"); scriptElement.src = url; const headerElement = document.querySelector("head") as any; if (headerElement) { headerElement.appendChild(scriptElement); } }
2、甘特圖初始化
template <div ref="gantt" id="yys-gantt"> </div> vuejs gantt() { // 獲取到dom元素 return this.$refs.gantt as any; } get ganttInstance() { // 獲取到甘特圖實例便能調用甘特圖的所有方法 return gantt || Gantt.getGanttInstance(); } this.ganttInstance.init(this.gantt()); this.ganttInstance.clearAll(); this.ganttInstance.parse(this.tasks);
3、甘特圖更新
a. tasks變更甘特圖更新
@Watch("config", { immediate: true, deep: true }) updateConfig(nConfig: any, oConfig: any) { if (JSON.stringify(nConfig) === JSON.stringify(oConfig)) { return; } this.$nextTick(() => { if (this.config) { Object.assign(this.ganttInstance.config, this.defaultConfig, this.config); } if (this.gantt()) { this.ganttInstance.init(this.gantt()); gantt.clearAll(); this.ganttInstance.parse(this.tasks); } }) }
b. config變更甘特圖更新
@Watch("config", { deep: true }) updateConfig() { if (this.config) { Object.assign(this.ganttInstance.config, this.defaultConfig, this.config); } if (this.gantt()) { this.ganttInstance.init(this.gantt()); gantt.clearAll(); this.ganttInstance.parse(this.tasks); } }
4、甘特圖銷毀
gantt.destructor()
1、data里面的部分屬性的key是不能更改的,比如id,parent,start_date、end_date、progress、open
links里面的全部屬性的key是不能更改的id source target type
2、data如果type是project,那么這條數據的開始時間會取其里面所有數據的最早開始時間,結束時間會取里面所有數據的最晚開始時間,如果這條數據里面的所有數據都是空數據,那么start_date會甘特圖渲染的最早時間,end_date是start_date的后一天,這樣數據就會不準確?
解決方案: data里加個unscheduled屬性來控制是否渲染這條數據,需要注意的是在所有涉及到日期的地方都要加,如tooltips_text 、columns、 拖拽等等
3、 dhtmlx-gantt都是下劃線分割,而且api中都是這樣,但在layout中min_width、max_width不生效,要用minWidth、maxWidth替換才生效。
4、排序后的數據默認從頁面獲取的row元素可能是不準確的,需要從dataStroe中獲取。
5、在左側表格和列都能拖拽的情況下,會突然彈回到默認寬度?
解決方案:監控config阻止掉更新;
@Watch("config", { deep: true }) updateConfig(nConfig: any, oConfig: any) { if (JSON.stringify(nConfig) === JSON.stringify(oConfig)) return; }
6、默認情況下甘特圖經常出現錯誤提示?
解決方案:將show_errors設為false
7、link添加類型&&計劃和里程碑規則
link_class: (link: any) => { // console.log(link) const {type} = link; return `link-type-${type}`; }, target.forEach((linkId: any) => { const link = this.gantt.getLink(linkId); const { sourceTask, targetTask, type, } = this.getSourceTaskAndTargetTaskByLink(link); switch (type) { case LinkType.fs: if ( +targetTask.start_date < +sourceTask.end_date ) { fsLimit(task, sourceTask); } break; case LinkType.ss: if (+targetTask.start_date > +sourceTask.start_date) { limitLeft(task, targetTask); } break; case LinkType.ff: if (+targetTask.end_date > +sourceTask.end_date) { limitRight(task, targetTask); } break; case LinkType.sf: if (+targetTask.start_date > +sourceTask.end_date) { limitRight(task, targetTask); } break; default: break; } fsMoveLimit(task: any, limit: any) { const dur = task.end_date - task.start_date; if (task.type === GANTT_TYPE.計劃 && limit.type === GANTT_TYPE.計劃) { task.start_date = new Date(limit.end_date); task.end_date = new Date(limit.start_date + dur); } if (task.type === GANTT_TYPE.計劃 && limit.type === GANTT_TYPE.里程碑) { task.start_date = new Date(limit.end_date); task.end_date = new Date(limit.start_date + dur); } if (task.type === GANTT_TYPE.里程碑 && limit.type === GANTT_TYPE.里程碑) { task.start_date = new Date(limit.start_date); } if (task.type === GANTT_TYPE.里程碑 && limit.type === GANTT_TYPE.計劃) { task.start_date = new Date(limit.end_date); } } fsResizeLimit(task: any, limit: any) { const dur = task.end_date - task.start_date; if (task.type === GANTT_TYPE.計劃 && limit.type === GANTT_TYPE.計劃) { task.start_date = new Date(limit.end_date); } if (task.type === GANTT_TYPE.計劃 && limit.type === GANTT_TYPE.里程碑) { task.start_date = new Date(limit.end_date); } } .gantt_task_link.link-type-0 .gantt_line_wrapper:nth-of-type(2)::before{ content: "fs"; position: absolute; top: 10px; left: 15px; font-size: 16px; } .gantt_task_link.link-type-1 .gantt_line_wrapper:nth-of-type(2)::before{ content: "ss"; position: absolute; top: 10px; left: 15px; font-size: 16px; } .gantt_task_link.link-type-2 .gantt_line_wrapper:nth-of-type(2)::before{ content: "ff"; position: absolute; top: 10px; left: 15px; font-size: 16px; } .gantt_task_link.link-type-3 .gantt_line_wrapper:nth-of-type(2)::before{ content: "sf"; position: absolute; top: 10px; left: 15px; font-size: 16px; }
本文轉自://juejin.cn/post/6930900493602390024 ,如有侵權,請聯系刪除
DHTMLX Gantt享有超十年聲譽,支持跨瀏覽器和跨平臺,性價比高,可滿足項目管理控件應用的所有需求,是最完善的甘特圖圖表庫。
甘特圖控件交流群:764148812
歡迎進群交流討論,獲取更多幫助請聯系
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn