Gantt.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. {{ src/components/Gantt.vue }}
  2. <template>
  3. <div ref="gantt"></div>
  4. </template>
  5. <script>
  6. import {gantt} from 'dhtmlx-gantt';
  7. import {getDeviceList, getJhList, getManagerList, getCgqList, saveProject} from '@/api/api'
  8. export default {
  9. name: 'gantt',
  10. // props: {
  11. // tasks: {
  12. // type: Object,
  13. // default () {
  14. // return {data: [], links: [], collections:{}}
  15. // }
  16. // }
  17. // },
  18. data () {
  19. return {
  20. tasks: {
  21. data: [
  22. ],
  23. collections: {
  24. staff:[],
  25. manager:[],
  26. chuanganqi:[],
  27. },
  28. queryParam:{
  29. weituoNo: undefined
  30. }
  31. },
  32. }
  33. },
  34. created() {
  35. // 清空数据
  36. gantt.clearAll();
  37. this.getDevicelist();
  38. this.getCgqlist();
  39. this.getManagerList();
  40. console.log(1112,this.tasks)
  41. },
  42. methods: {
  43. // 获取设备下拉列表
  44. getDevicelist(){
  45. getDeviceList().then((res) => {
  46. this.tasks.collections.staff = res.map(response =>{
  47. return {
  48. value: response.id,
  49. label: response.deviceName
  50. }
  51. })
  52. this.initData()
  53. })
  54. },
  55. // 获取项目经理下拉列表
  56. getManagerList(){
  57. var query ={
  58. position: "项目经理"
  59. }
  60. getManagerList(query).then((res) => {
  61. console.log(17,res)
  62. this.tasks.collections.manager = res.map(response =>{
  63. return {
  64. value: response.id,
  65. label: response.name
  66. }
  67. })
  68. this.initData()
  69. })
  70. },
  71. // 获取传感器下拉列表
  72. getCgqlist(){
  73. getCgqList().then((res) => {
  74. this.tasks.collections.chuanganqi = res.map(response =>{
  75. return {
  76. value: response.id,
  77. label: response.xuliehao
  78. }
  79. })
  80. this.initData()
  81. })
  82. },
  83. // 通过委托编号查询检测项目
  84. getinit(queryParam){
  85. console.log(22,queryParam)
  86. getJhList(queryParam).then((res) => {
  87. console.log(res.result)
  88. this.tasks.data = []
  89. gantt.clearAll();
  90. this.tasks.data = res.result.map(res => {
  91. return {
  92. id: res.testItemsId,
  93. // text:res.reportNo,
  94. start_date: res.jihuaStartDate,
  95. // end_date: res.jihuaEndDate,
  96. duration: res.lastTime,
  97. sampleName: res.sampleName,
  98. testItems: res.testItems,
  99. taskProgress: res.status
  100. }
  101. })
  102. console.log(33,this.tasks)
  103. gantt.init(this.$refs.gantt);
  104. // gantt.parse(this.$props.tasks);
  105. gantt.parse(this.tasks);
  106. })
  107. },
  108. // 提交
  109. searchReset() {
  110. var json = gantt.serialize();
  111. console.log(json)
  112. saveProject(json.data).then((res) => {
  113. console.log(res)
  114. })
  115. },
  116. // // 今日线
  117. // createTodayLine() {
  118. // var dateToStr = gantt.date.date_to_str("%Y年%M%d日");
  119. // var markerId = gantt.addMarker({
  120. // id: 'markerLine',
  121. // start_date: new Date(),
  122. // css: "today",
  123. // text: "今日",
  124. // title: dateToStr(new Date())
  125. // });
  126. // gantt.updateMarker(markerId);
  127. // },
  128. // //定位到今日线
  129. // changeToday() {
  130. // this.$nextTick(() => {
  131. // let ganTT = document.getElementsByClassName('gantt_marker today')
  132. // gantt.scrollTo(ganTT[0].offsetLeft-300, null);
  133. // })
  134. // },
  135. initData(){
  136. // 启用动态加载
  137. gantt.config.branch_loading = true
  138. //日期格式化
  139. gantt.config.xml_date = "%Y-%m-%d";
  140. gantt.config.order_branch = true;
  141. gantt.config.order_branch_free = true;
  142. //左侧是否自适应
  143. gantt.config.autofit = true;
  144. gantt.config.drag_links = false;//连线
  145. gantt.config.readonly = false; //只读
  146. gantt.config.date_scale = "%m月%d日"; //右侧显示列名
  147. gantt.config.layout = {//拖拽布局
  148. css: "gantt_container",
  149. rows: [
  150. {
  151. cols: [
  152. { view: "grid", id: "grid", scrollX: "scrollHor", scrollY: "scrollVer" },
  153. { resizer: true, width: 1 },
  154. { view: "timeline", id: "timeline", scrollX: "scrollHor", scrollY: "scrollVer" },
  155. { view: "scrollbar", scroll: "y", id: "scrollVer" }
  156. ]
  157. },
  158. { view: "scrollbar", scroll: "x", id: "scrollHor", height: 20 }
  159. ],
  160. // rows: [
  161. // {
  162. // cols: [
  163. // {
  164. // width:400,
  165. // min_width: 300,
  166. // rows:[
  167. // {view: "grid", scrollX: "gridScroll", scrollable: true, scrollY: "scrollVer"},
  168. // {view: "scrollbar", id: "gridScroll", group:"horizontal"} ]
  169. // },
  170. // {resizer: true, width: 1},
  171. // {
  172. // rows:[
  173. // {view: "timeline", scrollX: "scrollHor", scrollY: "scrollVer"},
  174. // {view: "scrollbar", id: "scrollHor", group:"horizontal"} ]
  175. // },
  176. // {view: "scrollbar", id: "scrollVer"}
  177. // ]
  178. // },
  179. // ],
  180. // cols: [
  181. // {
  182. // width:400,
  183. // min_width: 300,
  184. // rows:[
  185. // {view: "grid", scrollX: "gridScroll", scrollable: true, scrollY: "scrollVer"},
  186. // {view: "scrollbar", id: "gridScroll", group:"horizontal"} ]
  187. // },
  188. // {resizer: true, width: 1},
  189. // {
  190. // rows:[
  191. // {view: "timeline", scrollX: "scrollHor", scrollY: "scrollVer"},
  192. // {view: "scrollbar", id: "scrollHor", group:"horizontal"} ]
  193. // },
  194. // {view: "scrollbar", id: "scrollVer"}
  195. // ]
  196. };
  197. // 重置布局
  198. gantt.resetLayout();
  199. // var state = gantt.getState();
  200. // console.log(55,state.min_date);
  201. // console.log(66,state.max_date);
  202. gantt.config.start_on_monday = true;
  203. gantt.config.work_time = true;
  204. gantt.config.fit_tasks = true; //自动调整图表坐标轴区间用于适配task的长度
  205. // 甘特图汉化
  206. gantt.locale = {
  207. date: {
  208. month_full: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
  209. month_short: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
  210. day_full: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
  211. day_short: ["日", "一", "二", "三", "四", "五", "六"]
  212. },
  213. labels: {
  214. dhx_cal_today_button: "今天",
  215. day_tab: "日",
  216. week_tab: "周",
  217. month_tab: "月",
  218. new_event: "新建日程",
  219. icon_save: "保存",
  220. icon_cancel: "关闭",
  221. icon_details: "详细",
  222. icon_edit: "编辑",
  223. icon_delete: "删除",
  224. confirm_closing: "请确认是否撤销修改!", //Your changes will be lost, are your sure?
  225. confirm_deleting: "是否删除计划?",
  226. section_description: "描述:",
  227. section_time: "时间范围:",
  228. section_type: "类型:",
  229. section_text: "计划名称:",
  230. section_test: "测试:",
  231. section_projectClass: "项目类型:",
  232. taskProjectType_0: "项目任务",
  233. taskProjectType_1: "普通任务",
  234. section_head: "项目经理:",
  235. section_device: "试验设备:",
  236. section_sensor: "传感器:",
  237. section_priority: '优先级:',
  238. taskProgress: '任务状态',
  239. taskProgress_0: "未确认",
  240. taskProgress_1: "已确认",
  241. taskProgress_2: "完成",
  242. taskProgress_3: "已延期",
  243. taskProgress_4: "搁置中",
  244. section_template: 'Details',
  245. /* grid columns */
  246. column_text: "计划名称",
  247. column_sampleName: "样品名称",
  248. column_testItems: "检测项目",
  249. column_start_date: "开始时间",
  250. column_duration: "持续时间",
  251. column_add: "",
  252. column_priority: "难度",
  253. /* link confirmation */
  254. link: "关联",
  255. confirm_link_deleting: "将被删除",
  256. link_start: " (开始)",
  257. link_end: " (结束)",
  258. type_task: "任务",
  259. type_project: "项目",
  260. type_milestone: "里程碑",
  261. minutes: "分钟",
  262. hours: "小时",
  263. days: "天",
  264. weeks: "周",
  265. months: "月",
  266. years: "年"
  267. }
  268. };
  269. //定义各种编辑器及类型(可直接双击左侧进行编辑,不需要弹窗)
  270. // var textEditor = {type: "text", map_to: "text"};
  271. // var startDateEditor = {type: "date", map_to: "start_date"};
  272. // var endDateEditor = {type: "date", map_to: "end_date"};
  273. //设置甘特图中各个列相关配置
  274. // gantt.config.columns = [
  275. // {
  276. // name: 'text',
  277. // label: '项目名称',
  278. // editor: textEditor,
  279. // resize: true,
  280. // tree: true,
  281. // width: '100',
  282. // },
  283. // {
  284. // name: 'start_date',
  285. // label: '项目开始时间',
  286. // align: "center",
  287. // editor: startDateEditor,
  288. // resize:true,
  289. // tree: false,
  290. // width: '130',
  291. // },
  292. // {
  293. // name: 'end_date',
  294. // label: '项目结束时间',
  295. // width: '130',
  296. // align: 'center',
  297. // editor: endDateEditor,
  298. // resize: true,
  299. // },
  300. // ];
  301. // 左侧列表内容
  302. gantt.config.columns = [
  303. // { name: "text", min_width:100,max_width:200, label:"任务", align: "left",resize: true, tree: true },
  304. { name: "testItems", label: "检测项目", width: 130, resize: true, align: "left",resize: true, tree: true },
  305. { name: "sampleName", label: "样品名称", width: 90, resize: true, align: "center" },
  306. { name: "start_date", label: "开始时间", width: 100, resize: true, align: "center" },
  307. { name: "end_date", label: "结束时间", width: 100, resize: true, align: "center" },
  308. // { name: "taskProgress", label: "状态", width: 130, resize: true, align: "center", options: [
  309. // { key: "0", label: gantt.locale.labels.taskProgress_0 },
  310. // { key: "1", label: gantt.locale.labels.taskProgress_1 },
  311. // { key: "2", label: gantt.locale.labels.taskProgress_2 },
  312. // ],
  313. // template:function(obj){
  314. // console.log(obj)
  315. // let re = '';
  316. // switch (obj.taskProgress) {
  317. // case "0":
  318. // re = `<div class='taskProgress color_bg_1' >未开始</div>`
  319. // break;
  320. // case "1":
  321. // re = `<div class='taskProgress color_bg_2' >进行中</div>`
  322. // break;
  323. // case "2":
  324. // re = `<div class='taskProgress color_bg_3' >已完成</div>`
  325. // break;
  326. // }
  327. // return re
  328. // }
  329. // },
  330. { name: "add", label:"", width: 30 }
  331. ];
  332. //弹出层(灯箱)
  333. gantt.config.lightbox.sections = [
  334. // { name: "text", height: 30, map_to: "text", type: "textarea", focus: true, width: "*" },
  335. {
  336. name: "time", height: 40, map_to: "auto", type: "duration",
  337. time_format: ["%Y", "%m", "%d"],
  338. },
  339. { name: "head", height: 30, map_to: "head_id", type: "select", options:gantt.serverList("manager") },
  340. {
  341. name: "device", height: 30, map_to: "device_id", type: "select", options: gantt.serverList('staff',[]),
  342. },
  343. {
  344. name: "sensor", height: 30, map_to: "sensor_id", type: "select", options: gantt.serverList('chuanganqi',[]),
  345. },
  346. // { name: "description", height: 70, map_to: "description", type: "textarea" },
  347. // {
  348. // name: "priority", height: 40, map_to: "priority", type: "radio", options: gantt.serverList("priority")
  349. // },
  350. ];
  351. // 删除灯箱中的删除按钮
  352. gantt.config.buttons_right = [];
  353. gantt.init(this.$refs.gantt);
  354. // gantt.parse(this.$props.tasks);
  355. gantt.parse(this.tasks);
  356. }
  357. }
  358. }
  359. </script>
  360. <style>
  361. @import "~dhtmlx-gantt/codebase/dhtmlxgantt.css";
  362. .taskProgress{
  363. margin: 0 auto;
  364. margin-top: 5px;
  365. height: 24px;
  366. width: 65px;
  367. font-size: 12px;
  368. line-height: 24px;
  369. font-weight: bold;
  370. color: #f7fbfe;
  371. border-radius: 20px;
  372. }
  373. .color_bg_1{
  374. background-color:#60a3bc ;
  375. }
  376. .color_bg_2{
  377. background-color:#079992 ;
  378. }
  379. .color_bg_3{
  380. background-color:#78e08f ;
  381. }
  382. </style>