Commit 8faefbf3 authored by 郭铭瑶's avatar 郭铭瑶 🤘

拖拽任务功能

parent 76c842c6
...@@ -47,26 +47,39 @@ export default { ...@@ -47,26 +47,39 @@ export default {
for (let key in template) { for (let key in template) {
gantt.templates[key] = template[key] gantt.templates[key] = template[key]
} }
this.addEvents()
gantt.init(this.$refs.gantt)
this.addBaseline()
gantt.parse(this.tasks)
},
addEvents() { // 添加触发事件
// 可以添加法定节假日
this.setHolidays()
// 显示悬浮窗
gantt.showLightbox = (id) => { gantt.showLightbox = (id) => {
const task = gantt.getTask(id) const task = gantt.getTask(id)
this.curTask = task this.curTask = task
this.showModal = true this.showModal = true
} }
// 调整进度或者拖拽柱子触发
gantt.attachEvent('onAfterTaskDrag', (id, mode, e) => { gantt.attachEvent('onAfterTaskDrag', (id, mode, e) => {
const task = gantt.getTask(id) const task = gantt.getTask(id)
if (mode == 'progress') { if (mode == 'progress') {
this.$emit('progressChange', task) this.$emit('progressChange', task)
} }
}) })
this.setHolidays() // 拖拽任务触发
gantt.attachEvent('onTaskLoading', function (task) { gantt.attachEvent('onAfterTaskMove', (id, parentId, tindex) =>{
const task = gantt.getTask(id)
const parentTask = gantt.getTask(parentId)
this.$emit('taskChange', {task, parentTask})
})
// 任务加载后触发
gantt.attachEvent('onTaskLoading', task => {
task.planned_start = gantt.date.parseDate(task.planned_start, 'xml_date') task.planned_start = gantt.date.parseDate(task.planned_start, 'xml_date')
task.planned_end = gantt.date.parseDate(task.planned_end, 'xml_date') task.planned_end = gantt.date.parseDate(task.planned_end, 'xml_date')
return true return true
}) })
gantt.init(this.$refs.gantt)
this.addBaseline()
gantt.parse(this.tasks)
}, },
reset(config = {}){ reset(config = {}){
if (gantt.$container) { if (gantt.$container) {
...@@ -143,11 +156,7 @@ export default { ...@@ -143,11 +156,7 @@ export default {
gantt.config.grid_width = left gantt.config.grid_width = left
gantt.render() gantt.render()
}, },
setHolidays(){ setHolidays(holidays = [new Date(2019,9,1)]){
const holidays = [
new Date(2019,9,1),
new Date(2019,4,1),
]
holidays.forEach(date => { holidays.forEach(date => {
gantt.setWorkTime({date: date, hours: false}) gantt.setWorkTime({date: date, hours: false})
}) })
......
...@@ -13,13 +13,15 @@ export const config = { ...@@ -13,13 +13,15 @@ export const config = {
row_height: 24, row_height: 24,
date_scale: '%M%d日', // 列日期 date_scale: '%M%d日', // 列日期
drag_links: false, drag_links: false,
order_branch: true, // 拖拽任务
order_branch_free: true, // 拖拽任务
} }
export const template = { export const template = {
task_text: (start, end, task) => { // 柱上加进度百分比 task_text: (start, end, task) => { // 柱上加进度百分比
return Math.round(task.progress * 100) + '%' return Math.round(task.progress * 100) + '%'
}, },
tooltip_text: (start, end, task) => { // 浮框 tooltip_text: (start, end, task) => { // 悬浮窗内容
return ` return `
<b>任务名:${task.text}</b><br/> <b>任务名:${task.text}</b><br/>
<b>姓名:${task.name}</b><br/> <b>姓名:${task.name}</b><br/>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</a-dropdown> </a-dropdown>
</a-tabs> </a-tabs>
<div class="container"> <div class="container">
<GanttChart @progressChange="handleProgressChange" ref="gantt" :tasks="tasks"/> <GanttChart @progressChange="handleProgressChange" @taskChange="handleTaskChange" ref="gantt" :tasks="tasks"/>
</div> </div>
</div> </div>
</template> </template>
...@@ -144,6 +144,9 @@ export default { ...@@ -144,6 +144,9 @@ export default {
this.$message.success('调整进度成功') this.$message.success('调整进度成功')
}) })
}, },
handleTaskChange({task, parentTask}) {
console.log(task, parentTask)
},
handleClick({key}) { handleClick({key}) {
switch (key) { switch (key) {
case 'logout': case 'logout':
......
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import Main from '@/components/main' import Cookie from '@/util/local-cookie'
import Login from '@/components/login' import routes from './routes'
Vue.use(Router) Vue.use(Router)
export default new Router({ const config = {
routes: [ routes,
{ }
path: '/', const router = new Router(config)
name: 'main',
component: Main router.beforeEach((to, from, next) => {
}, const token = Cookie.get('token')
{ if (!token && to.name !== 'login') {
path: '/login', next('/login')
name: 'login', } else {
component: Login next()
}, }
]
}) })
export default router
const Main = () => import('@/components/main')
const Login = () => import('@/components/login')
export default [
{
path: '/',
name: 'main',
component: Main
},
{
path: '/login',
name: 'login',
component: Login
},
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment