From c2cc4580269de69325dc1a7ea65d411228701852 Mon Sep 17 00:00:00 2001
From: 小小儁爺 <1694218219@qq.com>
Date: 星期四, 15 一月 2026 09:52:13 +0800
Subject: [PATCH] 1.甘特图代码优化

---
 src/views/gantt/index.vue |  106 +++--------------------------------------------------
 1 files changed, 6 insertions(+), 100 deletions(-)

diff --git a/src/views/gantt/index.vue b/src/views/gantt/index.vue
index 491fef9..31ac705 100644
--- a/src/views/gantt/index.vue
+++ b/src/views/gantt/index.vue
@@ -63,45 +63,11 @@
         tooltip: true,
         undo: true
       })
+      gantt.i18n.setLocale('cn')
       gantt.config.multiselect = true // 寮�鍚浠诲姟閫夋嫨
+      gantt.config.show_links = false // 涓嶆樉绀鸿繛鎺ョ嚎
       /* 鈫撯啌鈫� Auto-scheduling configuration 鈫撯啌鈫� */
       gantt.config.auto_scheduling = true
-
-      function renderDiv(task, date, className) {
-        const el = document.createElement('div')
-        el.className = className
-        const sizes = gantt.getTaskPosition(task, date)
-        el.style.left = sizes.left + 'px'
-        el.style.top = sizes.top + 'px'
-        return el
-      }
-
-      gantt.attachEvent('onGanttReady', function() {
-        // gantt.addTaskLayer(function draw_deadline(task) {
-        //   const constraintType = gantt.getConstraintType(task);
-        //   const types = gantt.config.constraint_types;
-        //   if (constraintType != types.ASAP && constraintType != types.ALAP && task.constraint_date) {
-        //     const dates = gantt.getConstraintLimitations(task);
-        //
-        //     const els = document.createElement("div");
-        //
-        //     if (dates.earliestStart) {
-        //       els.appendChild(renderDiv(task, dates.earliestStart, 'constraint-marker earliest-start'));
-        //     }
-        //
-        //     if (dates.latestEnd) {
-        //       els.appendChild(renderDiv(task, dates.latestEnd, 'constraint-marker latest-end'));
-        //     }
-        //
-        //     els.title = gantt.locale.labels[constraintType] + " " + gantt.templates.task_date(task.constraint_date);
-        //
-        //     if (els.children.length)
-        //       return els;
-        //   }
-        //   return false;
-        // });
-      })
-      /* 鈫戔啈鈫� Auto-scheduling configuration 鈫戔啈鈫� */
 
       /* 鈫撯啌鈫� Group configuration 鈫撯啌鈫� */
       gantt.serverList('task_priority', [
@@ -117,8 +83,6 @@
         { key: 4, label: 'Complete' }
       ])
 
-      gantt.i18n.setLocale('cn')
-
       function byId(list, id) {
         for (let i = 0; i < list.length; i++) {
           if (list[i].key == id) {
@@ -130,6 +94,7 @@
 
       /* 鈫戔啈鈫� Group configuration 鈫戔啈鈫� */
 
+      // 鏀惧ぇ缂╁皬灞炴��
       /* 鈫撯啌鈫� Zoom configuration 鈫撯啌鈫� */
       const zoomConfig = {
         levels: [
@@ -212,7 +177,6 @@
           return gantt.$root.querySelector('.gantt_task')
         }
       }
-
       gantt.ext.zoom.init(zoomConfig)
       gantt.ext.zoom.setLevel('week')
       /* 鈫戔啈鈫� Zoom configuration 鈫戔啈鈫� */
@@ -248,15 +212,12 @@
       // })
       /* 鈫戔啈鈫� Working Time configuration 鈫戔啈鈫� */
 
+      // 鐢樼壒鍥惧垪鍙傛暟璁剧疆
       /* 鈫撯啌鈫� Grid Columns configuration 鈫撯啌鈫� */
-
       gantt.config.reorder_grid_columns = true
-
       const textEditor = { type: 'text', map_to: 'text' }
       const startDateEditor = { type: 'date', map_to: 'start_date' }
-      const durationEditor = { type: 'number', map_to: 'duration', min: 0, max: 100 }
-
-      // 鐢樼壒鍥惧垪鍚嶇О
+      const durationEditor = { type: 'number', map_to: 'duration', min: 1, max: 100 }
       gantt.config.columns = [
         {
           name: 'checked',
@@ -324,57 +285,7 @@
         },
         { name: 'add', width: 44 }
       ]
-
       /* 鈫戔啈鈫� Grid Columns configuration 鈫戔啈鈫� */
-
-      /* 鈫撯啌鈫� Resource configuration 鈫撯啌鈫� */
-      function getResourceAssignments(resourceId) {
-        let assignments
-        const store = gantt.getDatastore(gantt.config.resource_store)
-        const resource = store.getItem(resourceId)
-
-        if (resource.$level === 0) {
-          assignments = []
-          store.getChildren(resourceId).forEach(function(childId) {
-            assignments = assignments.concat(gantt.getResourceAssignments(childId))
-          })
-        } else if (resource.$level === 1) {
-          assignments = gantt.getResourceAssignments(resourceId)
-        } else {
-          assignments = gantt.getResourceAssignments(resource.$resource_id, resource.$task_id)
-        }
-        return assignments
-      }
-
-      gantt.templates.resource_cell_class = function(start_date, end_date, resource, tasks) {
-        const css = []
-        css.push('resource_marker')
-        if (tasks.length <= 1) {
-          css.push('workday_ok')
-        } else {
-          css.push('workday_over')
-        }
-        return css.join(' ')
-      }
-
-      gantt.templates.resource_cell_value = function(start_date, end_date, resource, tasks) {
-        let result = 0
-        tasks.forEach(function(item) {
-          const assignments = gantt.getResourceAssignments(resource.id, item.id)
-          assignments.forEach(function(assignment) {
-            const task = gantt.getTask(assignment.task_id)
-            result += assignment.value * 1
-          })
-        })
-
-        if (result % 1) {
-          result = Math.round(result * 10) / 10
-        }
-        return '<div>' + result + '</div>'
-      }
-
-      gantt.locale.labels.section_resources = 'Owners'
-      gantt.locale.labels.section_calendar = 'Calendar'
 
       // 姹夊寲绐楀彛
       gantt.locale.labels = {
@@ -495,12 +406,7 @@
       ])
       /* 鈫戔啈鈫� Resource configuration 鈫戔啈鈫� */
 
-      /* 鈫撯啌鈫� Layout configuration 鈫撯啌鈫� */
       gantt.config.grid_elastic_columns = true
-
-      // let currentLayout = 'default'
-
-      /* 鈫戔啈鈫� Layout configuration 鈫戔啈鈫� */
 
       // 鑷畾涔夋诞鍔ㄦ鐨勬樉绀哄唴瀹�   tooltip娴姩妗嗘樉绀虹殑End Date琚拷鍔�1鐨勯棶棰樹慨澶嶏紙搴旇鏄剧ず鏁版嵁搴撶殑鍘熷鍊硷級
       gantt.templates.tooltip_text = function(start, end, task) {
@@ -633,7 +539,7 @@
           },
           {
             'id': 11,
-            'text': '浠诲姟11',
+            'text': '椤圭洰11',
             'type': 'project',
             'progress': 0.6,
             'start_date': '02-04-2025 00:00',

--
Gitblit v1.9.3