| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import request from '@/utils/request' |
| | | |
| | | // è·åå页ççç¹å¾ä»»å¡æ°æ® |
| | | export function getGanttTasksPage(params) { |
| | | return request({ |
| | | url: '/gantt/tasks/page', |
| | | method: 'get', |
| | | params |
| | | }) |
| | | } |
| | | |
| | | // è·åææçç¹å¾ä»»å¡æ°é |
| | | export function getGanttTasksCount(params) { |
| | | return request({ |
| | | url: '/gantt/tasks/count', |
| | | method: 'get', |
| | | params |
| | | }) |
| | | } |
| | | |
| | | // è·åçç¹å¾ä»»å¡è¯¦æ
|
| | | export function getGanttTaskDetail(id) { |
| | | return request({ |
| | | url: `/gantt/tasks/${id}`, |
| | | method: 'get' |
| | | }) |
| | | } |
| | | |
| | | // å建çç¹å¾ä»»å¡ |
| | | export function createGanttTask(data) { |
| | | return request({ |
| | | url: '/gantt/tasks', |
| | | method: 'post', |
| | | data |
| | | }) |
| | | } |
| | | |
| | | // æ´æ°çç¹å¾ä»»å¡ |
| | | export function updateGanttTask(id, data) { |
| | | return request({ |
| | | url: `/gantt/tasks/${id}`, |
| | | method: 'put', |
| | | data |
| | | }) |
| | | } |
| | | |
| | | // å é¤çç¹å¾ä»»å¡ |
| | | export function deleteGanttTask(id) { |
| | | return request({ |
| | | url: `/gantt/tasks/${id}`, |
| | | method: 'delete' |
| | | }) |
| | | } |
| | |
| | | </el-button> |
| | | </div> |
| | | |
| | | <div id="gantt_here" style="width:100%; height:90vh;" /> |
| | | <div id="gantt_here" style="width:100%; height:calc(90vh - 50px);" /> |
| | | |
| | | <!-- å页ç»ä»¶ --> |
| | | <div class="pagination-container"> |
| | | <el-pagination |
| | | :current-page="currentPage" |
| | | :page-sizes="[10, 20, 50, 100]" |
| | | :page-size="pageSize" |
| | | layout="total, sizes, prev, pager, next, jumper" |
| | | :total="totalTasks" |
| | | @size-change="handleSizeChange" |
| | | @current-change="handleCurrentChange" |
| | | /> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import { gantt } from '@/components/dhtmlxGantt' |
| | | import '@/components/dhtmlxGantt/codebase/dhtmlxgantt.css' |
| | | import { handleDateReduceOneDay } from '@/utils/global' |
| | | import { handleDateReduceOneDay, handleDatetime } from '@/utils/global' |
| | | |
| | | export default { |
| | | data() { |
| | | return { |
| | | value: 'default', |
| | | ganttDateRange: ['2025-04-01', '2025-05-10'], |
| | | selectedIds: [] |
| | | selectedIds: [], |
| | | // å页ç¸å
³æ°æ® |
| | | currentPage: 1, |
| | | pageSize: 10, |
| | | totalTasks: 0, |
| | | allTasks: [], // å卿æä»»å¡æ°æ® |
| | | paginatedTasks: [] // å½å页ç任塿°æ® |
| | | } |
| | | }, |
| | | mounted() { |
| | | // å
æ¹åæ¥æèå´é
ç½® |
| | | this.ganttDateRangeChange(this.ganttDateRange) |
| | | this.init() |
| | | |
| | | // åå§åçç¹å¾é
ç½® |
| | | this.initGantt() |
| | | |
| | | // ç¶åå è½½ä»»å¡æ°æ®ï¼ä¼èªå¨æ¸²æå½åé¡µï¼ |
| | | this.loadTasks() |
| | | }, |
| | | methods: { |
| | | |
| | | init() { |
| | | // gantt.clearAll() |
| | | |
| | | initGantt() { |
| | | gantt.plugins({ |
| | | auto_scheduling: true, |
| | | critical_path: true, |
| | |
| | | }, |
| | | { |
| | | name: 'owner', align: 'center', width: 75, label: 'è´è´£äºº', template: function(task) { |
| | | if (task.type == gantt.config.types.project) { |
| | | return '' |
| | | } |
| | | |
| | | const store = gantt.getDatastore('resource') |
| | | const assignments = task[gantt.config.resource_property] |
| | | |
| | | if (!assignments || !assignments.length) { |
| | | return 'Unassigned' |
| | | } |
| | | |
| | | if (assignments.length == 1) { |
| | | return store.getItem(assignments[0].resource_id).text |
| | | } |
| | | |
| | | let result = '' |
| | | assignments.forEach(function(assignment) { |
| | | const owner = store.getItem(assignment.resource_id) |
| | | if (!owner) { |
| | | return |
| | | } |
| | | result += '<div class=\'owner-label\' title=\'' + owner.text + '\'>' + owner.text.substr(0, 1) + '</div>' |
| | | }) |
| | | |
| | | return result |
| | | // if (task.type == gantt.config.types.project) { |
| | | // return '' |
| | | // } |
| | | // |
| | | // const store = gantt.getDatastore('resource') |
| | | // const assignments = task[gantt.config.resource_property] |
| | | // |
| | | // if (!assignments || !assignments.length) { |
| | | // return 'Unassigned' |
| | | // } |
| | | // |
| | | // if (assignments.length === 1) { |
| | | // return store.getItem(assignments[0].resource_id).text |
| | | // } |
| | | // |
| | | // let result = '' |
| | | // assignments.forEach(function(assignment) { |
| | | // const owner = store.getItem(assignment.resource_id) |
| | | // if (!owner) { |
| | | // return |
| | | // } |
| | | // result += '<div class=\'owner-label\' title=\'' + owner.text + '\'>' + owner.text.substr(0, 1) + '</div>' |
| | | // }) |
| | | // |
| | | // return result |
| | | return 'å¼ ä¸' |
| | | }, |
| | | resize: true |
| | | }, |
| | |
| | | } |
| | | |
| | | gantt.init('gantt_here') |
| | | gantt.parse({ |
| | | 'data': [ |
| | | { |
| | | // 注æï¼è¿éä¸ç«å³å è½½æ°æ®ï¼èæ¯çå¾
loadTasks被è°ç¨ |
| | | |
| | | 'id': 1, |
| | | 'text': '项ç®1', |
| | | 'type': 'project', |
| | | 'start_date': '2025-04-02 00:00', |
| | | 'end_date': '2025-04-07 00:00', |
| | | 'duration': 5, |
| | | 'progress': 0.4, |
| | | 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | 'parent': 0, |
| | | 'checked': false |
| | | }, |
| | | { |
| | | 'id': 2, |
| | | 'text': '项ç®2', |
| | | 'type': 'project', |
| | | 'start_date': '02-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'parent': '1', |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 3, |
| | | 'text': '项ç®3', |
| | | 'type': 'project', |
| | | 'start_date': '11-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'parent': '1', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '5', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 4, |
| | | 'text': '项ç®4', |
| | | 'type': 'project', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '1', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'priority': 3, |
| | | checked: true |
| | | }, |
| | | { |
| | | 'id': 5, |
| | | 'text': 'ä»»å¡5', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 7, |
| | | 'parent': '2', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '6', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: true |
| | | }, |
| | | { |
| | | 'id': 6, |
| | | 'text': 'ä»»å¡6', |
| | | 'type': 'task', |
| | | 'calendar_id': 'custom1', |
| | | 'start_date': '03-04-2025 12:00', |
| | | 'duration': 7, |
| | | 'parent': '2', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '7', 'value': 1 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 7, |
| | | 'text': 'ä»»å¡7', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '12-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'parent': '3', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '10', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 8, |
| | | 'text': 'ä»»å¡8', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '14-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '10', 'value': 4 }, { 'resource_id': '9', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 9, |
| | | 'text': 'ä»»å¡9', |
| | | 'type': 'task', |
| | | 'start_date': '21-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '7', 'value': 3 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 10, |
| | | 'text': 'ä»»å¡10', |
| | | 'type': 'task', |
| | | 'start_date': '27-04-2025 00:00', |
| | | 'duration': 3, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '8', 'value': 5 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 11, |
| | | 'text': '项ç®11', |
| | | 'type': 'project', |
| | | 'progress': 0.6, |
| | | 'start_date': '02-04-2025 00:00', |
| | | 'duration': 13, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'parent': 0, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 12, |
| | | 'text': 'ä»»å¡12', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '11', |
| | | 'progress': 1, |
| | | 'owner': [{ 'resource_id': '7', 'value': 6 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 13, |
| | | 'text': '项ç®13', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 11, |
| | | 'parent': '11', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '5', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 14, |
| | | 'text': 'ä»»å¡14', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 6, |
| | | 'parent': '11', |
| | | 'owner': [], |
| | | 'progress': 0.8, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 15, |
| | | 'text': '项ç®15', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '11', |
| | | 'progress': 0.2, |
| | | 'owner': [{ 'resource_id': '5', 'value': 5 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 16, |
| | | 'text': 'ä»»å¡16', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 7, |
| | | 'parent': '11', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '7', 'value': 2 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 17, |
| | | 'text': 'ä»»å¡17', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 2, |
| | | 'parent': '13', |
| | | 'progress': 1, |
| | | 'owner': [{ 'resource_id': '8', 'value': 1 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 25, |
| | | 'text': 'ä»»å¡18', |
| | | 'type': 'task', |
| | | 'start_date': '06-04-2025 00:00', |
| | | 'parent': '13', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '5', 'value': 1 }], |
| | | 'duration': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 18, |
| | | 'text': 'ä»»å¡19', |
| | | 'type': 'task', |
| | | 'start_date': '10-04-2025 00:00', |
| | | 'duration': 2, |
| | | 'parent': '13', |
| | | 'progress': 0.8, |
| | | 'owner': [{ 'resource_id': '6', 'value': 2 }], |
| | | 'priority': 3, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 19, |
| | | 'text': 'ä»»å¡20', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '13', |
| | | 'progress': 0.2, |
| | | 'owner': [{ 'resource_id': '6', 'value': 3 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 20, |
| | | 'text': 'ä»»å¡21', |
| | | 'type': 'task', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '13', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '8', 'value': 4 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 21, |
| | | 'text': 'ä»»å¡22', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '15', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '6', 'value': 5 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 22, |
| | | 'text': 'ä»»å¡23', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '15', |
| | | 'progress': 0.1, |
| | | 'owner': [{ 'resource_id': '8', 'value': 3 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 23, |
| | | 'text': 'ä»»å¡24', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '15', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '8', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 24, |
| | | 'text': 'ä»»å¡25', |
| | | // 'type': 'milestone', |
| | | 'type': 'task', |
| | | 'start_date': '20-04-2025 00:00', |
| | | 'parent': '11', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | 'duration': 2, |
| | | checked: false |
| | | } |
| | | ] |
| | | |
| | | }) |
| | | |
| | | // ç»å®çç¹å¾ç¹å»äºä»¶ï¼å®æ¹æ¨èçäºä»¶å§æç¨æ³ï¼<span data-allow-html class='source-item source-aggregated' data-group-key='source-group-2' data-url='https://juejin.cn/post/7352376280387764278' data-id='turn0fetch0'><span data-allow-html class='source-item-num' data-group-key='source-group-2' data-id='turn0fetch0' data-url='https://juejin.cn/post/7352376280387764278'><span class='source-item-num-name' data-allow-html>https://juejin.cn/post/7352376280387764278</span></span></span> |
| | | // ç»å®çç¹å¾ç¹å»äºä»¶ï¼å®æ¹æ¨èçäºä»¶å§æç¨æ³ï¼ |
| | | gantt.attachEvent('onTaskClick', (id, e) => { |
| | | // æ¾å°ç¹å»çæ¯å¦æ¯å¤éæ¡ |
| | | const checkbox = e.target.closest('[data-action="check-row"]') |
| | |
| | | const task = gantt.getTask(id) |
| | | if (task) { |
| | | task.checked = !task.checked |
| | | // åæ¶æ´æ°å
¨å±æ°æ® |
| | | const globalTask = this.allTasks.find(t => t.id === id) |
| | | if (globalTask) { |
| | | globalTask.checked = task.checked |
| | | } |
| | | gantt.updateTask(id) // åªå·æ°è¿ä¸è¡ï¼æ§è½æ´å¥½ |
| | | this.syncSelected() // åæ¥å° Vue ç selectedIds |
| | | } |
| | |
| | | this.syncSelected() |
| | | }, |
| | | |
| | | // å è½½ä»»å¡æ°æ® |
| | | loadTasks() { |
| | | // 使ç¨åæçç¤ºä¾æ°æ®ä½ä¸ºåºç¡ |
| | | this.allTasks = [ |
| | | { |
| | | 'id': 1, |
| | | 'text': '项ç®1', |
| | | 'type': 'project', |
| | | 'start_date': '2025-04-02 00:00', |
| | | 'end_date': '2025-04-07 00:00', |
| | | 'duration': 5, |
| | | 'progress': 0.4, |
| | | 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | 'parent': 0, |
| | | 'checked': false |
| | | }, |
| | | { |
| | | 'id': 2, |
| | | 'text': '项ç®2', |
| | | 'type': 'project', |
| | | 'start_date': '02-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'parent': '1', |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 3, |
| | | 'text': '项ç®3', |
| | | 'type': 'project', |
| | | 'start_date': '11-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'parent': '1', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '5', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 4, |
| | | 'text': '项ç®4', |
| | | 'type': 'project', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '1', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'priority': 3, |
| | | checked: true |
| | | }, |
| | | { |
| | | 'id': 5, |
| | | 'text': 'ä»»å¡5', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 7, |
| | | 'parent': '2', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '6', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: true |
| | | }, |
| | | { |
| | | 'id': 6, |
| | | 'text': 'ä»»å¡6', |
| | | 'type': 'task', |
| | | 'calendar_id': 'custom1', |
| | | 'start_date': '03-04-2025 12:00', |
| | | 'duration': 7, |
| | | 'parent': '2', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '7', 'value': 1 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 7, |
| | | 'text': 'ä»»å¡7', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '12-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'parent': '3', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '10', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 8, |
| | | 'text': 'ä»»å¡8', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '14-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '10', 'value': 4 }, { 'resource_id': '9', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 9, |
| | | 'text': 'ä»»å¡9', |
| | | 'type': 'task', |
| | | 'start_date': '21-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '7', 'value': 3 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 10, |
| | | 'text': 'ä»»å¡10', |
| | | 'type': 'task', |
| | | 'start_date': '27-04-2025 00:00', |
| | | 'duration': 3, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '8', 'value': 5 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 11, |
| | | 'text': '项ç®11', |
| | | 'type': 'project', |
| | | 'progress': 0.6, |
| | | 'start_date': '02-04-2025 00:00', |
| | | 'duration': 13, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'parent': 0, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 12, |
| | | 'text': 'ä»»å¡12', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '11', |
| | | 'progress': 1, |
| | | 'owner': [{ 'resource_id': '7', 'value': 6 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 13, |
| | | 'text': '项ç®13', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 11, |
| | | 'parent': '11', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '5', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 14, |
| | | 'text': 'ä»»å¡14', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 6, |
| | | 'parent': '11', |
| | | 'owner': [], |
| | | 'progress': 0.8, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 15, |
| | | 'text': '项ç®15', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '11', |
| | | 'progress': 0.2, |
| | | 'owner': [{ 'resource_id': '5', 'value': 5 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 16, |
| | | 'text': 'ä»»å¡16', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 7, |
| | | 'parent': '11', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '7', 'value': 2 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 17, |
| | | 'text': 'ä»»å¡17', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 2, |
| | | 'parent': '13', |
| | | 'progress': 1, |
| | | 'owner': [{ 'resource_id': '8', 'value': 1 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | |
| | | { |
| | | 'id': 18, |
| | | 'text': 'ä»»å¡19', |
| | | 'type': 'task', |
| | | 'start_date': '10-04-2025 00:00', |
| | | 'duration': 2, |
| | | 'parent': '13', |
| | | 'progress': 0.8, |
| | | 'owner': [{ 'resource_id': '6', 'value': 2 }], |
| | | 'priority': 3, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 19, |
| | | 'text': 'ä»»å¡20', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '13', |
| | | 'progress': 0.2, |
| | | 'owner': [{ 'resource_id': '6', 'value': 3 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 20, |
| | | 'text': 'ä»»å¡21', |
| | | 'type': 'task', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '13', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '8', 'value': 4 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 21, |
| | | 'text': 'ä»»å¡22', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '0', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '6', 'value': 5 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 22, |
| | | 'text': 'ä»»å¡23', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '21', |
| | | 'progress': 0.1, |
| | | 'owner': [{ 'resource_id': '8', 'value': 3 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 23, |
| | | 'text': 'ä»»å¡24', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '21', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '8', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 24, |
| | | 'text': 'ä»»å¡25', |
| | | // 'type': 'milestone', |
| | | 'type': 'task', |
| | | 'start_date': '20-04-2025 00:00', |
| | | 'parent': '21', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | 'duration': 2, |
| | | checked: false |
| | | } |
| | | ] |
| | | |
| | | // æ·»å æ´å¤ç¤ºä¾æ°æ®ï¼ä½¿åé¡µæææ´ææ¾ |
| | | // for (let i = 25; i <= 100; i++) { |
| | | // this.allTasks.push({ |
| | | // 'id': i, |
| | | // 'text': 'ä»»å¡' + i, |
| | | // 'type': 'task', |
| | | // // 'start_date': handleDatetime(`0${Math.floor(Math.random() * 9 + 1)}-04-2025 00:00`), |
| | | // 'start_date': `0${Math.floor(Math.random() * 9 + 1)}-04-2025 00:00`, |
| | | // 'duration': Math.floor(Math.random() * 5) + 1, |
| | | // 'parent': Math.floor(Math.random() * 10) + 1, |
| | | // 'progress': Math.random(), |
| | | // 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | // 'priority': Math.floor(Math.random() * 3) + 1, |
| | | // 'checked': false |
| | | // }) |
| | | // } |
| | | console.log(JSON.parse(JSON.stringify(this.allTasks))) |
| | | this.totalTasks = this.allTasks.length |
| | | this.updatePaginatedTasks() |
| | | this.renderGanttChart() |
| | | }, |
| | | |
| | | // æ´æ°å页åç任塿°æ® |
| | | updatePaginatedTasks() { |
| | | const startIndex = (this.currentPage - 1) * this.pageSize |
| | | const endIndex = Math.min(startIndex + this.pageSize, this.allTasks.length) |
| | | this.paginatedTasks = this.allTasks.slice(startIndex, endIndex) |
| | | }, |
| | | |
| | | // 渲æçç¹å¾ |
| | | renderGanttChart() { |
| | | gantt.clearAll() |
| | | console.log(JSON.parse(JSON.stringify(this.paginatedTasks))) |
| | | gantt.parse({ |
| | | 'data': this.paginatedTasks |
| | | }) |
| | | // ç¡®ä¿çç¹å¾éæ°æ¸²æ |
| | | // gantt.render() |
| | | }, |
| | | |
| | | // 页大尿¹å |
| | | handleSizeChange(newSize) { |
| | | this.pageSize = newSize |
| | | this.currentPage = 1 // éç½®å°ç¬¬ä¸é¡µ |
| | | this.updatePaginatedTasks() |
| | | this.renderGanttChart() |
| | | this.syncSelected() |
| | | }, |
| | | |
| | | // å½å页æ¹å |
| | | handleCurrentChange(newPage) { |
| | | // è®¡ç®æå¤§é¡µæ°ï¼é²æ¢è¶
åºèå´ |
| | | const maxPage = Math.ceil(this.totalTasks / this.pageSize) |
| | | if (newPage > maxPage) { |
| | | this.currentPage = maxPage |
| | | } else if (newPage < 1) { |
| | | this.currentPage = 1 |
| | | } else { |
| | | this.currentPage = newPage |
| | | } |
| | | |
| | | this.updatePaginatedTasks() |
| | | this.renderGanttChart() |
| | | this.syncSelected() |
| | | }, |
| | | // çç¹å¾æ¥ææ¹å |
| | | ganttDateRangeChange(val) { |
| | | gantt.config.start_date = val[0] |
| | | gantt.config.end_date = val[1] |
| | | gantt.render() |
| | | }, |
| | | |
| | | // åéæå¨æä½ |
| | | ganttUndo() { |
| | | gantt.undo() |
| | | }, |
| | | // åè¿æå¨æä½ |
| | | ganttRedo() { |
| | | gantt.redo() |
| | | }, |
| | | // æ¾å¤§ |
| | | ganttZoomIn() { |
| | | gantt.ext.zoom.zoomIn() |
| | | }, |
| | | // ç¼©å° |
| | | ganttZoomOut() { |
| | | gantt.ext.zoom.zoomOut() |
| | | }, |
| | | |
| | | // ä»çç¹å¾ä¸åæ¥éä¸ç id å° Vue data |
| | | syncSelected() { |
| | | const tasks = gantt.serialize().data || [] |
| | | this.selectedIds = tasks.filter(t => t.checked).map(t => t.id) |
| | | // 忥å½å页é¢ä»»å¡å°å
¨å±æ°æ® |
| | | gantt.eachTask((task) => { |
| | | const globalTask = this.allTasks.find(t => t.id === task.id) |
| | | if (globalTask) { |
| | | globalTask.checked = task.checked |
| | | } |
| | | }) |
| | | |
| | | // è·åææéä¸çä»»å¡ID |
| | | this.selectedIds = this.allTasks.filter(t => t.checked).map(t => t.id) |
| | | console.log(this.selectedIds) |
| | | }, |
| | | |
| | | // è·åéä¸ä»»å¡ï¼ç¤ºä¾ï¼ |
| | | handleGetSelected() { |
| | | const tasks = gantt.serialize().data || [] |
| | | const selected = tasks.filter(t => t.checked) |
| | | const selected = this.allTasks.filter(t => t.checked) |
| | | this.$notify.success(`å½åå·²éä¸${selected.length} æ¡ä»»å¡`) |
| | | }, |
| | | |
| | | // æ¸
空ææéæ© |
| | | handleClearSelection() { |
| | | // è·åææä»»å¡ |
| | | const tasks = gantt.serialize().data || [] |
| | | |
| | | // éåææä»»å¡ï¼å° checked 屿§è®¾ç½®ä¸º false |
| | | tasks.forEach(task => { |
| | | this.allTasks.forEach(task => { |
| | | task.checked = false |
| | | }) |
| | | |
| | | // æ´æ°ææä»»å¡æ¾ç¤º |
| | | // æ´æ°å½å页颿¾ç¤ºçä»»å¡ |
| | | gantt.eachTask((task) => { |
| | | task.checked = false |
| | | gantt.updateTask(task.id) |
| | |
| | | margin: unset; |
| | | } |
| | | |
| | | .local_storage { |
| | | background: lavender; |
| | | border: 2px dotted orange; |
| | | font-weight: bold; |
| | | } |
| | | |
| | | .gantt_grid_scale .gantt_grid_head_cell, |
| | | .gantt_task .gantt_task_scale .gantt_scale_cell { |
| | | font-weight: bold; |
| | | font-size: 14px; |
| | | color: rgba(0, 0, 0, 0.7); |
| | | } |
| | | |
| | | .resource_marker { |
| | | text-align: center; |
| | | } |
| | | |
| | | .resource_marker div { |
| | | width: 28px; |
| | | height: 28px; |
| | | line-height: 29px; |
| | | display: inline-block; |
| | | border-radius: 15px; |
| | | color: #FFF; |
| | | margin: 3px; |
| | | } |
| | | |
| | | .resource_marker.workday_ok div { |
| | | background: #51c185; |
| | | } |
| | | |
| | | .resource_marker.workday_over div { |
| | | background: #ff8686; |
| | | } |
| | | |
| | | .owner-label { |
| | | width: 20px; |
| | | height: 20px; |
| | | line-height: 20px; |
| | | font-size: 12px; |
| | | display: inline-block; |
| | | border: 1px solid #cccccc; |
| | | border-radius: 25px; |
| | | background: #e6e6e6; |
| | | color: #6f6f6f; |
| | | margin: 0 3px; |
| | | font-weight: bold; |
| | | } |
| | | |
| | | .weekend { |
| | | background: LightGoldenrodYellow; |
| | | } |
| | | |
| | | .constraint-marker { |
| | | position: absolute; |
| | | |
| | | -moz-box-sizing: border-box; |
| | | box-sizing: border-box; |
| | | |
| | | width: 56px; |
| | | height: 56px; |
| | | margin-top: -11px; |
| | | |
| | | opacity: 0.4; |
| | | z-index: 1; |
| | | background: url("https://docs.dhtmlx.com/gantt/samples/common/constraint-arrow.svg") center no-repeat; |
| | | background-size: cover; |
| | | } |
| | | |
| | | .constraint-marker.earliest-start { |
| | | margin-left: -53px; |
| | | } |
| | | |
| | | .constraint-marker.latest-end { |
| | | margin-left: -3px; |
| | | transform: rotate(180deg); |
| | | } |
| | | |
| | | .taskCheckBox { |
| | | cursor: pointer; |
| | | z-index: 99999 !important; |
| | | } |
| | | |
| | | /* å页容卿 ·å¼ */ |
| | | .pagination-container { |
| | | margin-top: 10px; |
| | | display: flex; |
| | | justify-content: end; |
| | | padding: 10px 0; |
| | | background-color: #fff; |
| | | border-top: 1px solid #ebeef5; |
| | | } |
| | | </style> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div style="padding: 0 10px"> |
| | | |
| | | <div style="padding: 10px 0;display: flex;"> |
| | | <el-button type="primary" size="mini" @click="ganttUndo">åéæå¨æä½</el-button> |
| | | <el-button type="primary" size="mini" @click="ganttRedo">åè¿æå¨æä½</el-button> |
| | | <el-button type="primary" size="mini" @click="ganttZoomIn">æ¾å¤§</el-button> |
| | | <el-button type="primary" size="mini" @click="ganttZoomOut">缩å°</el-button> |
| | | <el-date-picker |
| | | v-model="ganttDateRange" |
| | | style="margin-left: 10px;" |
| | | size="mini" |
| | | value-format="yyyy-MM-dd" |
| | | type="daterange" |
| | | :clearable="false" |
| | | range-separator="è³" |
| | | start-placeholder="å¼å§æ¥æ" |
| | | end-placeholder="ç»ææ¥æ" |
| | | @change="ganttDateRangeChange" |
| | | /> |
| | | <el-button type="primary" style="margin-left: 10px;" size="mini" @click="handleGetSelected"> |
| | | è·åå¤éæ¡éä¸ä»»å¡ |
| | | </el-button> |
| | | <el-button size="mini" @click="handleClearSelection"> |
| | | æ¸
空å¤éæ¡éæ© |
| | | </el-button> |
| | | </div> |
| | | |
| | | <div id="gantt_here" style="width:100%; height:90vh;" /> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import { gantt } from '@/components/dhtmlxGantt' |
| | | import '@/components/dhtmlxGantt/codebase/dhtmlxgantt.css' |
| | | import { handleDateReduceOneDay } from '@/utils/global' |
| | | |
| | | export default { |
| | | data() { |
| | | return { |
| | | value: 'default', |
| | | ganttDateRange: ['2025-04-01', '2025-05-10'], |
| | | selectedIds: [] |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.ganttDateRangeChange(this.ganttDateRange) |
| | | this.initGantt() |
| | | }, |
| | | methods: { |
| | | |
| | | initGantt() { |
| | | // gantt.clearAll() |
| | | |
| | | gantt.plugins({ |
| | | auto_scheduling: true, |
| | | critical_path: true, |
| | | drag_timeline: true, |
| | | grouping: true, |
| | | keyboard_navigation: true, |
| | | marker: true, |
| | | multiselect: true, |
| | | 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 |
| | | |
| | | /* âââ Group configuration âââ */ |
| | | gantt.serverList('task_priority', [ |
| | | { key: 1, label: 'é«' }, |
| | | { key: 2, label: 'ä¸ç' }, |
| | | { key: 3, label: 'ä½' } |
| | | ]) |
| | | |
| | | gantt.serverList('task_status', [ |
| | | { key: 1, label: 'Planning' }, |
| | | { key: 2, label: 'Not started' }, |
| | | { key: 3, label: 'In Progress' }, |
| | | { key: 4, label: 'Complete' } |
| | | ]) |
| | | |
| | | function byId(list, id) { |
| | | for (let i = 0; i < list.length; i++) { |
| | | if (list[i].key == id) { |
| | | return list[i].label || '' |
| | | } |
| | | } |
| | | return '' |
| | | } |
| | | |
| | | /* âââ Group configuration âââ */ |
| | | |
| | | // æ¾å¤§ç¼©å°å±æ§ |
| | | /* âââ Zoom configuration âââ */ |
| | | const zoomConfig = { |
| | | levels: [ |
| | | { |
| | | name: 'hour', |
| | | scale_height: 27, |
| | | min_column_width: 50, |
| | | scales: [ |
| | | { unit: 'day', format: '%Yå¹´%M%då·' }, |
| | | { unit: 'hour', format: '%Hæ¶' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'day', |
| | | scale_height: 27, |
| | | min_column_width: 80, |
| | | scales: [ |
| | | // { unit: 'day', step: 1, format: '%d %M' } |
| | | { unit: 'day', step: 1, format: '%M%då·' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'week', |
| | | scale_height: 50, |
| | | min_column_width: 70, |
| | | scales: [ |
| | | // { |
| | | // unit: 'week', step: 1, format: function(date) { |
| | | // const dateToStr = gantt.date.date_to_str('%d %M') |
| | | // const endDate = gantt.date.add(date, -6, 'day') |
| | | // const weekNum = gantt.date.date_to_str('%W')(date) |
| | | // return '第' + weekNum + 'å¨, ' + dateToStr(date) + ' - ' + dateToStr(endDate) |
| | | // } |
| | | // }, |
| | | // %M |
| | | { unit: 'week', format: '%Y年第%Wå¨' }, |
| | | { unit: 'day', step: 1, format: '%M%då·' } |
| | | // { unit: 'day', step: 1, format: '%j %D' } |
| | | // { unit: 'day', step: 1, format: 'ææ%D' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'month', |
| | | scale_height: 50, |
| | | min_column_width: 120, |
| | | scales: [ |
| | | // { unit: 'month', format: '%Yå¹´%F' }, |
| | | { unit: 'month', format: '%Yå¹´%M' }, |
| | | { unit: 'week', format: '第%Wå¨' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'quarter', |
| | | height: 50, |
| | | min_column_width: 90, |
| | | scales: [ |
| | | // { |
| | | // unit: 'quarter', step: 1, format: function(date) { |
| | | // const dateToStr = gantt.date.date_to_str('%M') |
| | | // const endDate = gantt.date.add(gantt.date.add(date, 3, 'month'), -1, 'day') |
| | | // return dateToStr(date) + ' - ' + dateToStr(endDate) |
| | | // } |
| | | // }, |
| | | { unit: 'month', step: 1, format: '%Yå¹´%M' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'year', |
| | | scale_height: 50, |
| | | min_column_width: 30, |
| | | scales: [ |
| | | { unit: 'year', step: 1, format: '%Yå¹´' } |
| | | |
| | | ] |
| | | } |
| | | ], |
| | | useKey: 'ctrlKey', |
| | | trigger: 'wheel', |
| | | element: function() { |
| | | return gantt.$root.querySelector('.gantt_task') |
| | | } |
| | | } |
| | | gantt.ext.zoom.init(zoomConfig) |
| | | gantt.ext.zoom.setLevel('week') |
| | | /* âââ Zoom configuration âââ */ |
| | | |
| | | // æ¯å¦æ¯å·¥ä½æ¶é´ |
| | | /* âââ Working Time configuration âââ */ |
| | | gantt.templates.scale_cell_class = function(date) { |
| | | if (!gantt.isWorkTime(date)) { |
| | | return 'weekend' |
| | | } |
| | | } |
| | | |
| | | gantt.templates.timeline_cell_class = function(item, date) { |
| | | if (!gantt.isWorkTime({ date: date, task: item })) { |
| | | return 'weekend' |
| | | } |
| | | } |
| | | |
| | | gantt.config.work_time = true |
| | | |
| | | gantt.addCalendar({ |
| | | id: 'custom1', |
| | | worktime: { |
| | | hours: ['8:00-12:30', '13:00-17:30'], // global work hours for weekdays |
| | | days: [0, 1, 1, 1, 1, 1, 1] |
| | | } |
| | | }) |
| | | |
| | | // gantt.addCalendar({ |
| | | // id: 'custom2', |
| | | // hours: ['12:00-21:00'], |
| | | // days: [1, 0, 1, 0, 1, 0, 1] |
| | | // }) |
| | | /* âââ 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: 1, max: 100 } |
| | | gantt.config.columns = [ |
| | | { |
| | | name: 'checked', |
| | | label: 'éæ©', |
| | | align: 'center', |
| | | width: 35, |
| | | resize: false, |
| | | // å
³é®ï¼ç¨ template è¿åä¸ä¸ªå¤éæ¡ |
| | | template: (task) => { |
| | | const checked = task.checked ? 'checked' : '' |
| | | // data-action ç¨äºå¨äºä»¶å§ææ¶è¯å«æ¯å¤éæ¡ |
| | | return `<input type="checkbox" class="taskCheckBox" data-action="check-row" ${checked} />` |
| | | } |
| | | }, |
| | | { name: 'wbs', label: 'èç¹', width: 80, template: gantt.getWBSCode }, |
| | | { name: 'text', tree: true, label: 'ä»»å¡åç§°', width: 200, resize: true, editor: textEditor }, |
| | | { name: 'start_date', align: 'center', label: 'å¼å§æ¥æ', width: 80, resize: true, editor: startDateEditor }, |
| | | { |
| | | name: 'duration', |
| | | width: 60, |
| | | align: 'center', |
| | | label: 'å·¥æ(天)', |
| | | resize: true, |
| | | editor: durationEditor, |
| | | template: function(task) { |
| | | // 妿durationæ¯nullæundefinedï¼è¿å0 |
| | | // return (task.duration || 0) + 1 // å¨å½ådurationçåºç¡ä¸å 1 |
| | | return task.duration |
| | | } |
| | | }, |
| | | { |
| | | name: 'owner', align: 'center', width: 75, label: 'è´è´£äºº', template: function(task) { |
| | | if (task.type == gantt.config.types.project) { |
| | | return '' |
| | | } |
| | | |
| | | const store = gantt.getDatastore('resource') |
| | | const assignments = task[gantt.config.resource_property] |
| | | |
| | | if (!assignments || !assignments.length) { |
| | | return 'Unassigned' |
| | | } |
| | | |
| | | if (assignments.length == 1) { |
| | | return store.getItem(assignments[0].resource_id).text |
| | | } |
| | | |
| | | let result = '' |
| | | assignments.forEach(function(assignment) { |
| | | const owner = store.getItem(assignment.resource_id) |
| | | if (!owner) { |
| | | return |
| | | } |
| | | result += '<div class=\'owner-label\' title=\'' + owner.text + '\'>' + owner.text.substr(0, 1) + '</div>' |
| | | }) |
| | | |
| | | return result |
| | | }, |
| | | resize: true |
| | | }, |
| | | { |
| | | name: 'priority', width: 60, label: 'ä¼å
级', align: 'center', resize: true, template: function(task) { |
| | | return byId(gantt.serverList('task_priority'), task.priority) |
| | | } |
| | | }, |
| | | { name: 'add', width: 44 } |
| | | ] |
| | | /* âââ Grid Columns configuration âââ */ |
| | | |
| | | // æ±åçªå£ |
| | | gantt.locale.labels = { |
| | | dhx_cal_today_button: 'ä»å¤©', |
| | | day_tab: 'æ¥', |
| | | week_tab: 'å¨', |
| | | month_tab: 'æ', |
| | | new_event: 'æ°å»ºæ¥ç¨', |
| | | icon_save: 'ä¿å', |
| | | icon_cancel: 'å
³é', |
| | | icon_details: '详ç»', |
| | | icon_edit: 'ç¼è¾', |
| | | icon_delete: 'å é¤', |
| | | confirm_closing: '请确认æ¯å¦æ¤éä¿®æ¹!', // Your changes will be lost, are your sure? |
| | | confirm_deleting: 'æ¯å¦å é¤è®¡å?', |
| | | section_description: 'æè¿°:', |
| | | section_resources: 'èªå®ä¹éæ©:', |
| | | section_calendar: 'èªå®ä¹éæ©2:', |
| | | section_time: 'æ¶é´èå´:', |
| | | section_type: 'ç±»å:', |
| | | section_text: '计ååç§°:', |
| | | section_test: 'æµè¯:', |
| | | section_projectClass: '项ç®ç±»å:', |
| | | taskProjectType_0: '项ç®ä»»å¡', |
| | | taskProjectType_1: 'æ®éä»»å¡', |
| | | section_head: 'è´è´£äºº:', |
| | | section_priority: 'ä¼å
级:', |
| | | taskProgress: 'ä»»å¡ç¶æ', |
| | | taskProgress_0: 'æªå¼å§', |
| | | taskProgress_1: 'è¿è¡ä¸', |
| | | taskProgress_2: '已宿', |
| | | taskProgress_3: '已延æ', |
| | | taskProgress_4: 'æç½®ä¸', |
| | | section_template: 'Details', |
| | | /* grid columns */ |
| | | column_text: '计ååç§°', |
| | | column_start_date: 'å¼å§æ¶é´', |
| | | column_duration: 'æç»æ¶é´', |
| | | column_add: '', |
| | | column_priority: 'é¾åº¦', |
| | | /* link confirmation */ |
| | | link: 'å
³è', |
| | | confirm_link_deleting: 'å°è¢«å é¤', |
| | | message_ok: 'ç¡®å®', |
| | | message_cancel: 'åæ¶', |
| | | link_start: ' (å¼å§)', |
| | | link_end: ' (ç»æ)', |
| | | |
| | | type_task: 'ä»»å¡', |
| | | type_project: '项ç®', |
| | | type_milestone: 'éç¨ç¢', |
| | | minutes: 'åé', |
| | | hours: 'å°æ¶', |
| | | days: '天', |
| | | weeks: 'å¨', |
| | | months: 'æ', |
| | | years: 'å¹´' |
| | | } |
| | | |
| | | gantt.config.lightbox.sections = [ |
| | | { name: 'description', height: 38, map_to: 'text', type: 'textarea', focus: true }, |
| | | { |
| | | name: 'resources', type: 'resources', map_to: 'owner', options: gantt.serverList('people'), default_value: 8 |
| | | }, |
| | | { |
| | | name: 'calendar', height: 25, map_to: 'calendar_id', type: 'select', options: [ |
| | | { key: '', label: 'é»è®¤' }, |
| | | { key: 'custom1', label: 'é项ä¸' }, |
| | | { key: 'custom2', label: 'é项äº' } |
| | | ] |
| | | }, |
| | | |
| | | { name: 'time', type: 'duration', map_to: 'auto' } |
| | | ] |
| | | |
| | | gantt.config.resource_store = 'resource' |
| | | gantt.config.resource_property = 'owner' |
| | | gantt.config.order_branch = true |
| | | gantt.config.open_tree_initially = true |
| | | |
| | | gantt.config.show_errors = false // åçå¼å¸¸æ¶ï¼ä¸å
许弹åºè¦åå° UI çé¢ |
| | | |
| | | const resourcesStore = gantt.createDatastore({ |
| | | name: gantt.config.resource_store, |
| | | type: 'treeDatastore', |
| | | initItem: function(item) { |
| | | item.parent = item.parent || gantt.config.root_id |
| | | item[gantt.config.resource_property] = item.parent |
| | | item.open = true |
| | | return item |
| | | } |
| | | }) |
| | | |
| | | resourcesStore.attachEvent('onParse', function() { |
| | | const people = [] |
| | | resourcesStore.eachItem(function(res) { |
| | | if (!resourcesStore.hasChild(res.id)) { |
| | | const copy = gantt.copy(res) |
| | | copy.key = res.id |
| | | copy.label = res.text |
| | | people.push(copy) |
| | | } |
| | | }) |
| | | gantt.updateCollection('people', people) |
| | | }) |
| | | |
| | | resourcesStore.parse([ |
| | | { id: 1, text: 'QA', parent: null }, |
| | | { id: 2, text: 'Development', parent: null }, |
| | | { id: 3, text: 'Sales', parent: null }, |
| | | { id: 4, text: 'Other', parent: null }, |
| | | { id: 5, text: 'Unassigned', parent: 4 }, |
| | | { id: 6, text: 'John', parent: 1, unit: 'hours/day' }, |
| | | { id: 7, text: 'Mike', parent: 2, unit: 'hours/day' }, |
| | | { id: 8, text: 'Anna', parent: 2, unit: 'hours/day' }, |
| | | { id: 9, text: 'Bill', parent: 3, unit: 'hours/day' }, |
| | | { id: 10, text: 'Floe', parent: 3, unit: 'hours/day' } |
| | | ]) |
| | | /* âââ Resource configuration âââ */ |
| | | |
| | | gantt.config.grid_elastic_columns = true |
| | | |
| | | // èªå®ä¹æµ®å¨æ¡çæ¾ç¤ºå
容 tooltipæµ®å¨æ¡æ¾ç¤ºçEnd Date被追å 1çé®é¢ä¿®å¤ï¼åºè¯¥æ¾ç¤ºæ°æ®åºçåå§å¼ï¼ |
| | | gantt.templates.tooltip_text = function(start, end, task) { |
| | | return '<b>ä»»å¡:</b> ' + task.text + '<br/><b>å¼å§æ¶é´:</b> ' + `${gantt.date.date_to_str('%Y-%m-%d')(start)}` + '<br/><b>ç»ææ¶é´:</b> ' + handleDateReduceOneDay(end) |
| | | } |
| | | |
| | | gantt.init('gantt_here') |
| | | gantt.parse({ |
| | | 'data': [ |
| | | { |
| | | |
| | | 'id': 1, |
| | | 'text': '项ç®1', |
| | | 'type': 'project', |
| | | 'start_date': '2025-04-02 00:00', |
| | | 'end_date': '2025-04-07 00:00', |
| | | 'duration': 5, |
| | | 'progress': 0.4, |
| | | 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | 'parent': 0, |
| | | 'checked': false |
| | | }, |
| | | { |
| | | 'id': 2, |
| | | 'text': '项ç®2', |
| | | 'type': 'project', |
| | | 'start_date': '02-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'parent': '1', |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 3, |
| | | 'text': '项ç®3', |
| | | 'type': 'project', |
| | | 'start_date': '11-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'parent': '1', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '5', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 4, |
| | | 'text': '项ç®4', |
| | | 'type': 'project', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '1', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'priority': 3, |
| | | checked: true |
| | | }, |
| | | { |
| | | 'id': 5, |
| | | 'text': 'ä»»å¡5', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 7, |
| | | 'parent': '2', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '6', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: true |
| | | }, |
| | | { |
| | | 'id': 6, |
| | | 'text': 'ä»»å¡6', |
| | | 'type': 'task', |
| | | 'calendar_id': 'custom1', |
| | | 'start_date': '03-04-2025 12:00', |
| | | 'duration': 7, |
| | | 'parent': '2', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '7', 'value': 1 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 7, |
| | | 'text': 'ä»»å¡7', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '12-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'parent': '3', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '10', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 8, |
| | | 'text': 'ä»»å¡8', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '14-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '10', 'value': 4 }, { 'resource_id': '9', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 9, |
| | | 'text': 'ä»»å¡9', |
| | | 'type': 'task', |
| | | 'start_date': '21-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '7', 'value': 3 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 10, |
| | | 'text': 'ä»»å¡10', |
| | | 'type': 'task', |
| | | 'start_date': '27-04-2025 00:00', |
| | | 'duration': 3, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '8', 'value': 5 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 11, |
| | | 'text': '项ç®11', |
| | | 'type': 'project', |
| | | 'progress': 0.6, |
| | | 'start_date': '02-04-2025 00:00', |
| | | 'duration': 13, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'parent': 0, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 12, |
| | | 'text': 'ä»»å¡12', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '11', |
| | | 'progress': 1, |
| | | 'owner': [{ 'resource_id': '7', 'value': 6 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 13, |
| | | 'text': '项ç®13', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 11, |
| | | 'parent': '11', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '5', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 14, |
| | | 'text': 'ä»»å¡14', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 6, |
| | | 'parent': '11', |
| | | 'owner': [], |
| | | 'progress': 0.8, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 15, |
| | | 'text': '项ç®15', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '11', |
| | | 'progress': 0.2, |
| | | 'owner': [{ 'resource_id': '5', 'value': 5 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 16, |
| | | 'text': 'ä»»å¡16', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 7, |
| | | 'parent': '11', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '7', 'value': 2 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 17, |
| | | 'text': 'ä»»å¡17', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 2, |
| | | 'parent': '13', |
| | | 'progress': 1, |
| | | 'owner': [{ 'resource_id': '8', 'value': 1 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 25, |
| | | 'text': 'ä»»å¡18', |
| | | 'type': 'task', |
| | | 'start_date': '06-04-2025 00:00', |
| | | 'parent': '13', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '5', 'value': 1 }], |
| | | 'duration': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 18, |
| | | 'text': 'ä»»å¡19', |
| | | 'type': 'task', |
| | | 'start_date': '10-04-2025 00:00', |
| | | 'duration': 2, |
| | | 'parent': '13', |
| | | 'progress': 0.8, |
| | | 'owner': [{ 'resource_id': '6', 'value': 2 }], |
| | | 'priority': 3, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 19, |
| | | 'text': 'ä»»å¡20', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '13', |
| | | 'progress': 0.2, |
| | | 'owner': [{ 'resource_id': '6', 'value': 3 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 20, |
| | | 'text': 'ä»»å¡21', |
| | | 'type': 'task', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '13', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '8', 'value': 4 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 21, |
| | | 'text': 'ä»»å¡22', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '15', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '6', 'value': 5 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 22, |
| | | 'text': 'ä»»å¡23', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '15', |
| | | 'progress': 0.1, |
| | | 'owner': [{ 'resource_id': '8', 'value': 3 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 23, |
| | | 'text': 'ä»»å¡24', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '15', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '8', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 24, |
| | | 'text': 'ä»»å¡25', |
| | | // 'type': 'milestone', |
| | | 'type': 'task', |
| | | 'start_date': '20-04-2025 00:00', |
| | | 'parent': '11', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | 'duration': 2, |
| | | checked: false |
| | | } |
| | | ] |
| | | |
| | | }) |
| | | |
| | | // ç»å®çç¹å¾ç¹å»äºä»¶ï¼å®æ¹æ¨èçäºä»¶å§æç¨æ³ï¼<span data-allow-html class='source-item source-aggregated' data-group-key='source-group-2' data-url='https://juejin.cn/post/7352376280387764278' data-id='turn0fetch0'><span data-allow-html class='source-item-num' data-group-key='source-group-2' data-id='turn0fetch0' data-url='https://juejin.cn/post/7352376280387764278'><span class='source-item-num-name' data-allow-html>https://juejin.cn/post/7352376280387764278</span></span></span> |
| | | gantt.attachEvent('onTaskClick', (id, e) => { |
| | | // æ¾å°ç¹å»çæ¯å¦æ¯å¤éæ¡ |
| | | const checkbox = e.target.closest('[data-action="check-row"]') |
| | | if (!checkbox) { |
| | | // 䏿¯ç¹å¤éæ¡ï¼å°±ä¿æé»è®¤è¡ä¸º |
| | | return true |
| | | } |
| | | |
| | | // æ¯å¤éæ¡ï¼åæ¢éä¸ç¶æ |
| | | const task = gantt.getTask(id) |
| | | if (task) { |
| | | task.checked = !task.checked |
| | | gantt.updateTask(id) // åªå·æ°è¿ä¸è¡ï¼æ§è½æ´å¥½ |
| | | this.syncSelected() // åæ¥å° Vue ç selectedIds |
| | | } |
| | | |
| | | // 黿¢é»è®¤ç¹å»è¡è¡ä¸ºï¼é¿å
误触åå
¶ä»é»è¾ï¼ |
| | | return false |
| | | }) |
| | | |
| | | // åå§å宿å忥䏿¬¡éä¸ç¶æ |
| | | this.syncSelected() |
| | | }, |
| | | |
| | | ganttDateRangeChange(val) { |
| | | gantt.config.start_date = val[0] |
| | | gantt.config.end_date = val[1] |
| | | gantt.render() |
| | | }, |
| | | |
| | | ganttUndo() { |
| | | gantt.undo() |
| | | }, |
| | | ganttRedo() { |
| | | gantt.redo() |
| | | }, |
| | | ganttZoomIn() { |
| | | gantt.ext.zoom.zoomIn() |
| | | }, |
| | | ganttZoomOut() { |
| | | gantt.ext.zoom.zoomOut() |
| | | }, |
| | | |
| | | // ä»çç¹å¾ä¸åæ¥éä¸ç id å° Vue data |
| | | syncSelected() { |
| | | const tasks = gantt.serialize().data || [] |
| | | this.selectedIds = tasks.filter(t => t.checked).map(t => t.id) |
| | | console.log(this.selectedIds) |
| | | }, |
| | | |
| | | // è·åéä¸ä»»å¡ï¼ç¤ºä¾ï¼ |
| | | handleGetSelected() { |
| | | const tasks = gantt.serialize().data || [] |
| | | const selected = tasks.filter(t => t.checked) |
| | | this.$notify.success(`å½åå·²éä¸${selected.length} æ¡ä»»å¡`) |
| | | }, |
| | | |
| | | // æ¸
空ææéæ© |
| | | handleClearSelection() { |
| | | // è·åææä»»å¡ |
| | | const tasks = gantt.serialize().data || [] |
| | | |
| | | // éåææä»»å¡ï¼å° checked 屿§è®¾ç½®ä¸º false |
| | | tasks.forEach(task => { |
| | | task.checked = false |
| | | }) |
| | | |
| | | // æ´æ°ææä»»å¡æ¾ç¤º |
| | | gantt.eachTask((task) => { |
| | | task.checked = false |
| | | gantt.updateTask(task.id) |
| | | }) |
| | | |
| | | // åæ¥å° Vue ç»ä»¶æ°æ® |
| | | this.syncSelected() |
| | | |
| | | // æ¾ç¤ºæç¤ºä¿¡æ¯ |
| | | this.$notify.success('å·²æ¸
空ææéæ©') |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | </script> |
| | | |
| | | <style> |
| | | body, |
| | | html { |
| | | width: 100%; |
| | | height: 100%; |
| | | margin: unset; |
| | | } |
| | | |
| | | .local_storage { |
| | | background: lavender; |
| | | border: 2px dotted orange; |
| | | font-weight: bold; |
| | | } |
| | | |
| | | .gantt_grid_scale .gantt_grid_head_cell, |
| | | .gantt_task .gantt_task_scale .gantt_scale_cell { |
| | | font-weight: bold; |
| | | font-size: 14px; |
| | | color: rgba(0, 0, 0, 0.7); |
| | | } |
| | | |
| | | .resource_marker { |
| | | text-align: center; |
| | | } |
| | | |
| | | .resource_marker div { |
| | | width: 28px; |
| | | height: 28px; |
| | | line-height: 29px; |
| | | display: inline-block; |
| | | border-radius: 15px; |
| | | color: #FFF; |
| | | margin: 3px; |
| | | } |
| | | |
| | | .resource_marker.workday_ok div { |
| | | background: #51c185; |
| | | } |
| | | |
| | | .resource_marker.workday_over div { |
| | | background: #ff8686; |
| | | } |
| | | |
| | | .owner-label { |
| | | width: 20px; |
| | | height: 20px; |
| | | line-height: 20px; |
| | | font-size: 12px; |
| | | display: inline-block; |
| | | border: 1px solid #cccccc; |
| | | border-radius: 25px; |
| | | background: #e6e6e6; |
| | | color: #6f6f6f; |
| | | margin: 0 3px; |
| | | font-weight: bold; |
| | | } |
| | | |
| | | .weekend { |
| | | background: LightGoldenrodYellow; |
| | | } |
| | | |
| | | .constraint-marker { |
| | | position: absolute; |
| | | |
| | | -moz-box-sizing: border-box; |
| | | box-sizing: border-box; |
| | | |
| | | width: 56px; |
| | | height: 56px; |
| | | margin-top: -11px; |
| | | |
| | | opacity: 0.4; |
| | | z-index: 1; |
| | | background: url("https://docs.dhtmlx.com/gantt/samples/common/constraint-arrow.svg") center no-repeat; |
| | | background-size: cover; |
| | | } |
| | | |
| | | .constraint-marker.earliest-start { |
| | | margin-left: -53px; |
| | | } |
| | | |
| | | .constraint-marker.latest-end { |
| | | margin-left: -3px; |
| | | transform: rotate(180deg); |
| | | } |
| | | |
| | | .taskCheckBox { |
| | | cursor: pointer; |
| | | z-index: 99999 !important; |
| | | } |
| | | </style> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div style="padding: 0 10px"> |
| | | |
| | | <div style="padding: 10px 0;display: flex;"> |
| | | <el-button type="primary" size="mini" @click="ganttUndo">åéæå¨æä½</el-button> |
| | | <el-button type="primary" size="mini" @click="ganttRedo">åè¿æå¨æä½</el-button> |
| | | <el-button type="primary" size="mini" @click="ganttZoomIn">æ¾å¤§</el-button> |
| | | <el-button type="primary" size="mini" @click="ganttZoomOut">缩å°</el-button> |
| | | <el-date-picker |
| | | v-model="ganttDateRange" |
| | | style="margin-left: 10px;" |
| | | size="mini" |
| | | value-format="yyyy-MM-dd" |
| | | type="daterange" |
| | | :clearable="false" |
| | | range-separator="è³" |
| | | start-placeholder="å¼å§æ¥æ" |
| | | end-placeholder="ç»ææ¥æ" |
| | | @change="ganttDateRangeChange" |
| | | /> |
| | | <el-button type="primary" style="margin-left: 10px;" size="mini" @click="handleGetSelected"> |
| | | è·åå¤éæ¡éä¸ä»»å¡ |
| | | </el-button> |
| | | <el-button size="mini" @click="handleClearSelection"> |
| | | æ¸
空å¤éæ¡éæ© |
| | | </el-button> |
| | | </div> |
| | | |
| | | <div id="gantt_here" style="width:100%; height:calc(90vh - 50px);" /> |
| | | |
| | | <!-- å页ç»ä»¶ --> |
| | | <div class="pagination-container"> |
| | | <el-pagination |
| | | :current-page="currentPage" |
| | | :page-sizes="[10, 20, 50, 100]" |
| | | :page-size="pageSize" |
| | | layout="total, sizes, prev, pager, next, jumper" |
| | | :total="totalTasks" |
| | | @size-change="handleSizeChange" |
| | | @current-change="handleCurrentChange" |
| | | /> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import { gantt } from '@/components/dhtmlxGantt' |
| | | import '@/components/dhtmlxGantt/codebase/dhtmlxgantt.css' |
| | | import { handleDateReduceOneDay, handleDatetime } from '@/utils/global' |
| | | |
| | | export default { |
| | | data() { |
| | | return { |
| | | value: 'default', |
| | | ganttDateRange: ['2025-04-01', '2025-05-10'], |
| | | selectedIds: [], |
| | | // å页ç¸å
³æ°æ® |
| | | currentPage: 1, |
| | | pageSize: 10, |
| | | totalTasks: 0, |
| | | allTasks: [], // å卿æä»»å¡æ°æ® |
| | | paginatedTasks: [] // å½å页ç任塿°æ® |
| | | } |
| | | }, |
| | | mounted() { |
| | | // å
æ¹åæ¥æèå´é
ç½® |
| | | this.ganttDateRangeChange(this.ganttDateRange) |
| | | |
| | | // åå§åçç¹å¾é
ç½® |
| | | this.initGantt() |
| | | |
| | | // ç¶åå è½½ä»»å¡æ°æ®ï¼ä¼èªå¨æ¸²æå½åé¡µï¼ |
| | | this.loadTasks() |
| | | }, |
| | | methods: { |
| | | |
| | | initGantt() { |
| | | gantt.plugins({ |
| | | auto_scheduling: true, |
| | | critical_path: true, |
| | | drag_timeline: true, |
| | | grouping: true, |
| | | keyboard_navigation: true, |
| | | marker: true, |
| | | multiselect: true, |
| | | 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 |
| | | |
| | | /* âââ Group configuration âââ */ |
| | | gantt.serverList('task_priority', [ |
| | | { key: 1, label: 'é«' }, |
| | | { key: 2, label: 'ä¸ç' }, |
| | | { key: 3, label: 'ä½' } |
| | | ]) |
| | | |
| | | gantt.serverList('task_status', [ |
| | | { key: 1, label: 'Planning' }, |
| | | { key: 2, label: 'Not started' }, |
| | | { key: 3, label: 'In Progress' }, |
| | | { key: 4, label: 'Complete' } |
| | | ]) |
| | | |
| | | function byId(list, id) { |
| | | for (let i = 0; i < list.length; i++) { |
| | | if (list[i].key == id) { |
| | | return list[i].label || '' |
| | | } |
| | | } |
| | | return '' |
| | | } |
| | | |
| | | /* âââ Group configuration âââ */ |
| | | |
| | | // æ¾å¤§ç¼©å°å±æ§ |
| | | /* âââ Zoom configuration âââ */ |
| | | const zoomConfig = { |
| | | levels: [ |
| | | { |
| | | name: 'hour', |
| | | scale_height: 27, |
| | | min_column_width: 50, |
| | | scales: [ |
| | | { unit: 'day', format: '%Yå¹´%M%då·' }, |
| | | { unit: 'hour', format: '%Hæ¶' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'day', |
| | | scale_height: 27, |
| | | min_column_width: 80, |
| | | scales: [ |
| | | // { unit: 'day', step: 1, format: '%d %M' } |
| | | { unit: 'day', step: 1, format: '%M%då·' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'week', |
| | | scale_height: 50, |
| | | min_column_width: 70, |
| | | scales: [ |
| | | // { |
| | | // unit: 'week', step: 1, format: function(date) { |
| | | // const dateToStr = gantt.date.date_to_str('%d %M') |
| | | // const endDate = gantt.date.add(date, -6, 'day') |
| | | // const weekNum = gantt.date.date_to_str('%W')(date) |
| | | // return '第' + weekNum + 'å¨, ' + dateToStr(date) + ' - ' + dateToStr(endDate) |
| | | // } |
| | | // }, |
| | | // %M |
| | | { unit: 'week', format: '%Y年第%Wå¨' }, |
| | | { unit: 'day', step: 1, format: '%M%då·' } |
| | | // { unit: 'day', step: 1, format: '%j %D' } |
| | | // { unit: 'day', step: 1, format: 'ææ%D' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'month', |
| | | scale_height: 50, |
| | | min_column_width: 120, |
| | | scales: [ |
| | | // { unit: 'month', format: '%Yå¹´%F' }, |
| | | { unit: 'month', format: '%Yå¹´%M' }, |
| | | { unit: 'week', format: '第%Wå¨' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'quarter', |
| | | height: 50, |
| | | min_column_width: 90, |
| | | scales: [ |
| | | // { |
| | | // unit: 'quarter', step: 1, format: function(date) { |
| | | // const dateToStr = gantt.date.date_to_str('%M') |
| | | // const endDate = gantt.date.add(gantt.date.add(date, 3, 'month'), -1, 'day') |
| | | // return dateToStr(date) + ' - ' + dateToStr(endDate) |
| | | // } |
| | | // }, |
| | | { unit: 'month', step: 1, format: '%Yå¹´%M' } |
| | | ] |
| | | }, |
| | | { |
| | | name: 'year', |
| | | scale_height: 50, |
| | | min_column_width: 30, |
| | | scales: [ |
| | | { unit: 'year', step: 1, format: '%Yå¹´' } |
| | | |
| | | ] |
| | | } |
| | | ], |
| | | useKey: 'ctrlKey', |
| | | trigger: 'wheel', |
| | | element: function() { |
| | | return gantt.$root.querySelector('.gantt_task') |
| | | } |
| | | } |
| | | gantt.ext.zoom.init(zoomConfig) |
| | | gantt.ext.zoom.setLevel('week') |
| | | /* âââ Zoom configuration âââ */ |
| | | |
| | | // æ¯å¦æ¯å·¥ä½æ¶é´ |
| | | /* âââ Working Time configuration âââ */ |
| | | gantt.templates.scale_cell_class = function(date) { |
| | | if (!gantt.isWorkTime(date)) { |
| | | return 'weekend' |
| | | } |
| | | } |
| | | |
| | | gantt.templates.timeline_cell_class = function(item, date) { |
| | | if (!gantt.isWorkTime({ date: date, task: item })) { |
| | | return 'weekend' |
| | | } |
| | | } |
| | | |
| | | gantt.config.work_time = true |
| | | |
| | | gantt.addCalendar({ |
| | | id: 'custom1', |
| | | worktime: { |
| | | hours: ['8:00-12:30', '13:00-17:30'], // global work hours for weekdays |
| | | days: [0, 1, 1, 1, 1, 1, 1] |
| | | } |
| | | }) |
| | | |
| | | // gantt.addCalendar({ |
| | | // id: 'custom2', |
| | | // hours: ['12:00-21:00'], |
| | | // days: [1, 0, 1, 0, 1, 0, 1] |
| | | // }) |
| | | /* âââ 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: 1, max: 100 } |
| | | gantt.config.columns = [ |
| | | { |
| | | name: 'checked', |
| | | label: 'éæ©', |
| | | align: 'center', |
| | | width: 35, |
| | | resize: false, |
| | | // å
³é®ï¼ç¨ template è¿åä¸ä¸ªå¤éæ¡ |
| | | template: (task) => { |
| | | const checked = task.checked ? 'checked' : '' |
| | | // data-action ç¨äºå¨äºä»¶å§ææ¶è¯å«æ¯å¤éæ¡ |
| | | return `<input type="checkbox" class="taskCheckBox" data-action="check-row" ${checked} />` |
| | | } |
| | | }, |
| | | { name: 'wbs', label: 'èç¹', width: 80, template: gantt.getWBSCode }, |
| | | { name: 'text', tree: true, label: 'ä»»å¡åç§°', width: 200, resize: true, editor: textEditor }, |
| | | { name: 'start_date', align: 'center', label: 'å¼å§æ¥æ', width: 80, resize: true, editor: startDateEditor }, |
| | | { |
| | | name: 'duration', |
| | | width: 60, |
| | | align: 'center', |
| | | label: 'å·¥æ(天)', |
| | | resize: true, |
| | | editor: durationEditor, |
| | | template: function(task) { |
| | | // 妿durationæ¯nullæundefinedï¼è¿å0 |
| | | // return (task.duration || 0) + 1 // å¨å½ådurationçåºç¡ä¸å 1 |
| | | return task.duration |
| | | } |
| | | }, |
| | | { |
| | | name: 'owner', align: 'center', width: 75, label: 'è´è´£äºº', template: function(task) { |
| | | // if (task.type == gantt.config.types.project) { |
| | | // return '' |
| | | // } |
| | | // |
| | | // const store = gantt.getDatastore('resource') |
| | | // const assignments = task[gantt.config.resource_property] |
| | | // |
| | | // if (!assignments || !assignments.length) { |
| | | // return 'Unassigned' |
| | | // } |
| | | // |
| | | // if (assignments.length === 1) { |
| | | // return store.getItem(assignments[0].resource_id).text |
| | | // } |
| | | // |
| | | // let result = '' |
| | | // assignments.forEach(function(assignment) { |
| | | // const owner = store.getItem(assignment.resource_id) |
| | | // if (!owner) { |
| | | // return |
| | | // } |
| | | // result += '<div class=\'owner-label\' title=\'' + owner.text + '\'>' + owner.text.substr(0, 1) + '</div>' |
| | | // }) |
| | | // |
| | | // return result |
| | | return 'å¼ ä¸' |
| | | }, |
| | | resize: true |
| | | }, |
| | | { |
| | | name: 'priority', width: 60, label: 'ä¼å
级', align: 'center', resize: true, template: function(task) { |
| | | return byId(gantt.serverList('task_priority'), task.priority) |
| | | } |
| | | }, |
| | | { name: 'add', width: 44 } |
| | | ] |
| | | /* âââ Grid Columns configuration âââ */ |
| | | |
| | | // æ±åçªå£ |
| | | gantt.locale.labels = { |
| | | dhx_cal_today_button: 'ä»å¤©', |
| | | day_tab: 'æ¥', |
| | | week_tab: 'å¨', |
| | | month_tab: 'æ', |
| | | new_event: 'æ°å»ºæ¥ç¨', |
| | | icon_save: 'ä¿å', |
| | | icon_cancel: 'å
³é', |
| | | icon_details: '详ç»', |
| | | icon_edit: 'ç¼è¾', |
| | | icon_delete: 'å é¤', |
| | | confirm_closing: '请确认æ¯å¦æ¤éä¿®æ¹!', // Your changes will be lost, are your sure? |
| | | confirm_deleting: 'æ¯å¦å é¤è®¡å?', |
| | | section_description: 'æè¿°:', |
| | | section_resources: 'èªå®ä¹éæ©:', |
| | | section_calendar: 'èªå®ä¹éæ©2:', |
| | | section_time: 'æ¶é´èå´:', |
| | | section_type: 'ç±»å:', |
| | | section_text: '计ååç§°:', |
| | | section_test: 'æµè¯:', |
| | | section_projectClass: '项ç®ç±»å:', |
| | | taskProjectType_0: '项ç®ä»»å¡', |
| | | taskProjectType_1: 'æ®éä»»å¡', |
| | | section_head: 'è´è´£äºº:', |
| | | section_priority: 'ä¼å
级:', |
| | | taskProgress: 'ä»»å¡ç¶æ', |
| | | taskProgress_0: 'æªå¼å§', |
| | | taskProgress_1: 'è¿è¡ä¸', |
| | | taskProgress_2: '已宿', |
| | | taskProgress_3: '已延æ', |
| | | taskProgress_4: 'æç½®ä¸', |
| | | section_template: 'Details', |
| | | /* grid columns */ |
| | | column_text: '计ååç§°', |
| | | column_start_date: 'å¼å§æ¶é´', |
| | | column_duration: 'æç»æ¶é´', |
| | | column_add: '', |
| | | column_priority: 'é¾åº¦', |
| | | /* link confirmation */ |
| | | link: 'å
³è', |
| | | confirm_link_deleting: 'å°è¢«å é¤', |
| | | message_ok: 'ç¡®å®', |
| | | message_cancel: 'åæ¶', |
| | | link_start: ' (å¼å§)', |
| | | link_end: ' (ç»æ)', |
| | | |
| | | type_task: 'ä»»å¡', |
| | | type_project: '项ç®', |
| | | type_milestone: 'éç¨ç¢', |
| | | minutes: 'åé', |
| | | hours: 'å°æ¶', |
| | | days: '天', |
| | | weeks: 'å¨', |
| | | months: 'æ', |
| | | years: 'å¹´' |
| | | } |
| | | |
| | | gantt.config.lightbox.sections = [ |
| | | { name: 'description', height: 38, map_to: 'text', type: 'textarea', focus: true }, |
| | | { |
| | | name: 'resources', type: 'resources', map_to: 'owner', options: gantt.serverList('people'), default_value: 8 |
| | | }, |
| | | { |
| | | name: 'calendar', height: 25, map_to: 'calendar_id', type: 'select', options: [ |
| | | { key: '', label: 'é»è®¤' }, |
| | | { key: 'custom1', label: 'é项ä¸' }, |
| | | { key: 'custom2', label: 'é项äº' } |
| | | ] |
| | | }, |
| | | |
| | | { name: 'time', type: 'duration', map_to: 'auto' } |
| | | ] |
| | | |
| | | gantt.config.resource_store = 'resource' |
| | | gantt.config.resource_property = 'owner' |
| | | gantt.config.order_branch = true |
| | | gantt.config.open_tree_initially = true |
| | | |
| | | gantt.config.show_errors = false // åçå¼å¸¸æ¶ï¼ä¸å
许弹åºè¦åå° UI çé¢ |
| | | |
| | | const resourcesStore = gantt.createDatastore({ |
| | | name: gantt.config.resource_store, |
| | | type: 'treeDatastore', |
| | | initItem: function(item) { |
| | | item.parent = item.parent || gantt.config.root_id |
| | | item[gantt.config.resource_property] = item.parent |
| | | item.open = true |
| | | return item |
| | | } |
| | | }) |
| | | |
| | | resourcesStore.attachEvent('onParse', function() { |
| | | const people = [] |
| | | resourcesStore.eachItem(function(res) { |
| | | if (!resourcesStore.hasChild(res.id)) { |
| | | const copy = gantt.copy(res) |
| | | copy.key = res.id |
| | | copy.label = res.text |
| | | people.push(copy) |
| | | } |
| | | }) |
| | | gantt.updateCollection('people', people) |
| | | }) |
| | | |
| | | resourcesStore.parse([ |
| | | { id: 1, text: 'QA', parent: null }, |
| | | { id: 2, text: 'Development', parent: null }, |
| | | { id: 3, text: 'Sales', parent: null }, |
| | | { id: 4, text: 'Other', parent: null }, |
| | | { id: 5, text: 'Unassigned', parent: 4 }, |
| | | { id: 6, text: 'John', parent: 1, unit: 'hours/day' }, |
| | | { id: 7, text: 'Mike', parent: 2, unit: 'hours/day' }, |
| | | { id: 8, text: 'Anna', parent: 2, unit: 'hours/day' }, |
| | | { id: 9, text: 'Bill', parent: 3, unit: 'hours/day' }, |
| | | { id: 10, text: 'Floe', parent: 3, unit: 'hours/day' } |
| | | ]) |
| | | /* âââ Resource configuration âââ */ |
| | | |
| | | gantt.config.grid_elastic_columns = true |
| | | |
| | | // èªå®ä¹æµ®å¨æ¡çæ¾ç¤ºå
容 tooltipæµ®å¨æ¡æ¾ç¤ºçEnd Date被追å 1çé®é¢ä¿®å¤ï¼åºè¯¥æ¾ç¤ºæ°æ®åºçåå§å¼ï¼ |
| | | gantt.templates.tooltip_text = function(start, end, task) { |
| | | return '<b>ä»»å¡:</b> ' + task.text + '<br/><b>å¼å§æ¶é´:</b> ' + `${gantt.date.date_to_str('%Y-%m-%d')(start)}` + '<br/><b>ç»ææ¶é´:</b> ' + handleDateReduceOneDay(end) |
| | | } |
| | | |
| | | gantt.init('gantt_here') |
| | | // 注æï¼è¿éä¸ç«å³å è½½æ°æ®ï¼èæ¯çå¾
loadTasks被è°ç¨ |
| | | |
| | | // ç»å®çç¹å¾ç¹å»äºä»¶ï¼å®æ¹æ¨èçäºä»¶å§æç¨æ³ï¼ |
| | | gantt.attachEvent('onTaskClick', (id, e) => { |
| | | // æ¾å°ç¹å»çæ¯å¦æ¯å¤éæ¡ |
| | | const checkbox = e.target.closest('[data-action="check-row"]') |
| | | if (!checkbox) { |
| | | // 䏿¯ç¹å¤éæ¡ï¼å°±ä¿æé»è®¤è¡ä¸º |
| | | return true |
| | | } |
| | | |
| | | // æ¯å¤éæ¡ï¼åæ¢éä¸ç¶æ |
| | | const task = gantt.getTask(id) |
| | | if (task) { |
| | | task.checked = !task.checked |
| | | // åæ¶æ´æ°å
¨å±æ°æ® |
| | | const globalTask = this.allTasks.find(t => t.id === id) |
| | | if (globalTask) { |
| | | globalTask.checked = task.checked |
| | | } |
| | | gantt.updateTask(id) // åªå·æ°è¿ä¸è¡ï¼æ§è½æ´å¥½ |
| | | this.syncSelected() // åæ¥å° Vue ç selectedIds |
| | | } |
| | | |
| | | // 黿¢é»è®¤ç¹å»è¡è¡ä¸ºï¼é¿å
误触åå
¶ä»é»è¾ï¼ |
| | | return false |
| | | }) |
| | | |
| | | // åå§å宿å忥䏿¬¡éä¸ç¶æ |
| | | this.syncSelected() |
| | | }, |
| | | |
| | | // å è½½ä»»å¡æ°æ® |
| | | loadTasks() { |
| | | // 使ç¨åæçç¤ºä¾æ°æ®ä½ä¸ºåºç¡ |
| | | this.allTasks = [ |
| | | { |
| | | 'id': 1, |
| | | 'text': '项ç®1', |
| | | 'type': 'project', |
| | | 'start_date': '2025-04-02 00:00', |
| | | 'end_date': '2025-04-07 00:00', |
| | | 'duration': 5, |
| | | 'progress': 0.4, |
| | | 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | 'parent': 0, |
| | | 'checked': false |
| | | }, |
| | | { |
| | | 'id': 2, |
| | | 'text': '项ç®2', |
| | | 'type': 'project', |
| | | 'start_date': '02-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'parent': '1', |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 3, |
| | | 'text': '项ç®3', |
| | | 'type': 'project', |
| | | 'start_date': '11-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'parent': '1', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '5', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 4, |
| | | 'text': '项ç®4', |
| | | 'type': 'project', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '1', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'priority': 3, |
| | | checked: true |
| | | }, |
| | | { |
| | | 'id': 5, |
| | | 'text': 'ä»»å¡5', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 7, |
| | | 'parent': '2', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '6', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: true |
| | | }, |
| | | { |
| | | 'id': 6, |
| | | 'text': 'ä»»å¡6', |
| | | 'type': 'task', |
| | | 'calendar_id': 'custom1', |
| | | 'start_date': '03-04-2025 12:00', |
| | | 'duration': 7, |
| | | 'parent': '2', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '7', 'value': 1 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 7, |
| | | 'text': 'ä»»å¡7', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '12-04-2025 00:00', |
| | | 'duration': 8, |
| | | 'parent': '3', |
| | | 'progress': 0.6, |
| | | 'owner': [{ 'resource_id': '10', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 8, |
| | | 'text': 'ä»»å¡8', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '14-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '10', 'value': 4 }, { 'resource_id': '9', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 9, |
| | | 'text': 'ä»»å¡9', |
| | | 'type': 'task', |
| | | 'start_date': '21-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '7', 'value': 3 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 10, |
| | | 'text': 'ä»»å¡10', |
| | | 'type': 'task', |
| | | 'start_date': '27-04-2025 00:00', |
| | | 'duration': 3, |
| | | 'parent': '4', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '8', 'value': 5 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 11, |
| | | 'text': '项ç®11', |
| | | 'type': 'project', |
| | | 'progress': 0.6, |
| | | 'start_date': '02-04-2025 00:00', |
| | | 'duration': 13, |
| | | 'owner': [{ 'resource_id': '5', 'value': 4 }], |
| | | 'parent': 0, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 12, |
| | | 'text': 'ä»»å¡12', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '11', |
| | | 'progress': 1, |
| | | 'owner': [{ 'resource_id': '7', 'value': 6 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 13, |
| | | 'text': '项ç®13', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 11, |
| | | 'parent': '11', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '5', 'value': 2 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 14, |
| | | 'text': 'ä»»å¡14', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 6, |
| | | 'parent': '11', |
| | | 'owner': [], |
| | | 'progress': 0.8, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 15, |
| | | 'text': '项ç®15', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '11', |
| | | 'progress': 0.2, |
| | | 'owner': [{ 'resource_id': '5', 'value': 5 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 16, |
| | | 'text': 'ä»»å¡16', |
| | | 'calendar_id': 'custom2', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 7, |
| | | 'parent': '11', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '7', 'value': 2 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 17, |
| | | 'text': 'ä»»å¡17', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 2, |
| | | 'parent': '13', |
| | | 'progress': 1, |
| | | 'owner': [{ 'resource_id': '8', 'value': 1 }], |
| | | 'priority': 2, |
| | | checked: false |
| | | }, |
| | | |
| | | { |
| | | 'id': 18, |
| | | 'text': 'ä»»å¡19', |
| | | 'type': 'task', |
| | | 'start_date': '10-04-2025 00:00', |
| | | 'duration': 2, |
| | | 'parent': '13', |
| | | 'progress': 0.8, |
| | | 'owner': [{ 'resource_id': '6', 'value': 2 }], |
| | | 'priority': 3, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 19, |
| | | 'text': 'ä»»å¡20', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '13', |
| | | 'progress': 0.2, |
| | | 'owner': [{ 'resource_id': '6', 'value': 3 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 20, |
| | | 'text': 'ä»»å¡21', |
| | | 'type': 'task', |
| | | 'start_date': '13-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '13', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '8', 'value': 4 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 21, |
| | | 'text': 'ä»»å¡22', |
| | | 'type': 'project', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '0', |
| | | 'progress': 0.5, |
| | | 'owner': [{ 'resource_id': '6', 'value': 5 }], |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 22, |
| | | 'text': 'ä»»å¡23', |
| | | 'calendar_id': 'custom1', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 4, |
| | | 'parent': '21', |
| | | 'progress': 0.1, |
| | | 'owner': [{ 'resource_id': '8', 'value': 3 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 23, |
| | | 'text': 'ä»»å¡24', |
| | | 'type': 'task', |
| | | 'start_date': '03-04-2025 00:00', |
| | | 'duration': 5, |
| | | 'parent': '21', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '8', 'value': 5 }], |
| | | 'priority': 1, |
| | | checked: false |
| | | }, |
| | | { |
| | | 'id': 24, |
| | | 'text': 'ä»»å¡25', |
| | | // 'type': 'milestone', |
| | | 'type': 'task', |
| | | 'start_date': '20-04-2025 00:00', |
| | | 'parent': '21', |
| | | 'progress': 0, |
| | | 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | 'duration': 2, |
| | | checked: false |
| | | } |
| | | ] |
| | | |
| | | // æ·»å æ´å¤ç¤ºä¾æ°æ®ï¼ä½¿åé¡µæææ´ææ¾ |
| | | // for (let i = 25; i <= 100; i++) { |
| | | // this.allTasks.push({ |
| | | // 'id': i, |
| | | // 'text': 'ä»»å¡' + i, |
| | | // 'type': 'task', |
| | | // // 'start_date': handleDatetime(`0${Math.floor(Math.random() * 9 + 1)}-04-2025 00:00`), |
| | | // 'start_date': `0${Math.floor(Math.random() * 9 + 1)}-04-2025 00:00`, |
| | | // 'duration': Math.floor(Math.random() * 5) + 1, |
| | | // 'parent': Math.floor(Math.random() * 10) + 1, |
| | | // 'progress': Math.random(), |
| | | // 'owner': [{ 'resource_id': '5', 'value': 3 }], |
| | | // 'priority': Math.floor(Math.random() * 3) + 1, |
| | | // 'checked': false |
| | | // }) |
| | | // } |
| | | console.log(JSON.parse(JSON.stringify(this.allTasks))) |
| | | this.totalTasks = this.allTasks.length |
| | | this.updatePaginatedTasks() |
| | | this.renderGanttChart() |
| | | }, |
| | | |
| | | // æ´æ°å页åç任塿°æ® |
| | | updatePaginatedTasks() { |
| | | const startIndex = (this.currentPage - 1) * this.pageSize |
| | | const endIndex = Math.min(startIndex + this.pageSize, this.allTasks.length) |
| | | this.paginatedTasks = this.allTasks.slice(startIndex, endIndex) |
| | | }, |
| | | |
| | | // 渲æçç¹å¾ |
| | | renderGanttChart() { |
| | | gantt.clearAll() |
| | | console.log(JSON.parse(JSON.stringify(this.paginatedTasks))) |
| | | gantt.parse({ |
| | | 'data': this.paginatedTasks |
| | | }) |
| | | // ç¡®ä¿çç¹å¾éæ°æ¸²æ |
| | | // gantt.render() |
| | | }, |
| | | |
| | | // 页大尿¹å |
| | | handleSizeChange(newSize) { |
| | | this.pageSize = newSize |
| | | this.currentPage = 1 // éç½®å°ç¬¬ä¸é¡µ |
| | | this.updatePaginatedTasks() |
| | | this.renderGanttChart() |
| | | this.syncSelected() |
| | | }, |
| | | |
| | | // å½å页æ¹å |
| | | handleCurrentChange(newPage) { |
| | | // è®¡ç®æå¤§é¡µæ°ï¼é²æ¢è¶
åºèå´ |
| | | const maxPage = Math.ceil(this.totalTasks / this.pageSize) |
| | | if (newPage > maxPage) { |
| | | this.currentPage = maxPage |
| | | } else if (newPage < 1) { |
| | | this.currentPage = 1 |
| | | } else { |
| | | this.currentPage = newPage |
| | | } |
| | | |
| | | this.updatePaginatedTasks() |
| | | this.renderGanttChart() |
| | | this.syncSelected() |
| | | }, |
| | | // çç¹å¾æ¥ææ¹å |
| | | ganttDateRangeChange(val) { |
| | | gantt.config.start_date = val[0] |
| | | gantt.config.end_date = val[1] |
| | | gantt.render() |
| | | }, |
| | | // åéæå¨æä½ |
| | | ganttUndo() { |
| | | gantt.undo() |
| | | }, |
| | | // åè¿æå¨æä½ |
| | | ganttRedo() { |
| | | gantt.redo() |
| | | }, |
| | | // æ¾å¤§ |
| | | ganttZoomIn() { |
| | | gantt.ext.zoom.zoomIn() |
| | | }, |
| | | // ç¼©å° |
| | | ganttZoomOut() { |
| | | gantt.ext.zoom.zoomOut() |
| | | }, |
| | | |
| | | // ä»çç¹å¾ä¸åæ¥éä¸ç id å° Vue data |
| | | syncSelected() { |
| | | // 忥å½å页é¢ä»»å¡å°å
¨å±æ°æ® |
| | | gantt.eachTask((task) => { |
| | | const globalTask = this.allTasks.find(t => t.id === task.id) |
| | | if (globalTask) { |
| | | globalTask.checked = task.checked |
| | | } |
| | | }) |
| | | |
| | | // è·åææéä¸çä»»å¡ID |
| | | this.selectedIds = this.allTasks.filter(t => t.checked).map(t => t.id) |
| | | console.log(this.selectedIds) |
| | | }, |
| | | |
| | | // è·åéä¸ä»»å¡ï¼ç¤ºä¾ï¼ |
| | | handleGetSelected() { |
| | | const selected = this.allTasks.filter(t => t.checked) |
| | | this.$notify.success(`å½åå·²éä¸${selected.length} æ¡ä»»å¡`) |
| | | }, |
| | | |
| | | // æ¸
空ææéæ© |
| | | handleClearSelection() { |
| | | // éåææä»»å¡ï¼å° checked 屿§è®¾ç½®ä¸º false |
| | | this.allTasks.forEach(task => { |
| | | task.checked = false |
| | | }) |
| | | |
| | | // æ´æ°å½å页颿¾ç¤ºçä»»å¡ |
| | | gantt.eachTask((task) => { |
| | | task.checked = false |
| | | gantt.updateTask(task.id) |
| | | }) |
| | | |
| | | // åæ¥å° Vue ç»ä»¶æ°æ® |
| | | this.syncSelected() |
| | | |
| | | // æ¾ç¤ºæç¤ºä¿¡æ¯ |
| | | this.$notify.success('å·²æ¸
空ææéæ©') |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | </script> |
| | | |
| | | <style> |
| | | body, |
| | | html { |
| | | width: 100%; |
| | | height: 100%; |
| | | margin: unset; |
| | | } |
| | | |
| | | .taskCheckBox { |
| | | cursor: pointer; |
| | | } |
| | | |
| | | /* å页容卿 ·å¼ */ |
| | | .pagination-container { |
| | | margin-top: 10px; |
| | | display: flex; |
| | | justify-content: end; |
| | | padding: 10px 0; |
| | | background-color: #fff; |
| | | border-top: 1px solid #ebeef5; |
| | | } |
| | | </style> |