v1.4.5 - add Task drag and drop ender TaskList

This commit is contained in:
LINING-PC\lining
2025-12-06 20:34:33 +08:00
parent 04b9e5fb75
commit 7d81f44778
16 changed files with 1471 additions and 86 deletions
+110 -6
View File
@@ -12,6 +12,7 @@ import VersionHistoryDrawer from './VersionHistoryDrawer.vue'
import HtmlContent from './HtmlContent.vue'
import { useMessage } from '../src/composables/useMessage'
import { useI18n } from '../src/composables/useI18n'
import { useDemoLocale } from './useDemoLocale'
import { getPredecessorIds, predecessorIdsToString } from '../src/utils/predecessorUtils'
import type { Task } from '../src/models/Task'
import type { TaskListConfig, TaskListColumnConfig } from '../src/models/configs/TaskListConfig'
@@ -19,6 +20,7 @@ import type { TaskBarConfig } from '../src/models/configs/TaskBarConfig'
const { showMessage } = useMessage()
const { t, formatTranslation } = useI18n()
const { locale: demoLocale, messages: demoMessages, setLocale: setDemoLocale, formatMessage, getTaskTypeName, getParentName } = useDemoLocale()
const tasks = ref<Task[]>([])
const milestones = ref<Task[]>([])
@@ -182,6 +184,9 @@ const taskListConfig = computed<TaskListConfig>(() => ({
// 控制是否允许拖拽和拉伸
const allowDragAndResize = ref(true)
// 控制是否启用TaskRow拖拽移动
const enableTaskRowMove = ref(true)
// TaskBar配置
const taskBarOptions = ref({
showAvatar: true,
@@ -236,6 +241,17 @@ const toggleTaskBarConfig = () => {
const showTaskClickDialog = ref(false)
const clickedTask = ref<Task | null>(null)
// TaskRow Move 相关(已移除确认对话框,直接显示提示消息)
// 同步语言切换
const handleLanguageChange = (lang: 'zh-CN' | 'en-US') => {
setDemoLocale(lang)
const languageText = lang === 'zh-CN' ? '中文' : 'English'
showMessage(formatTranslation('languageSwitchedTo', { language: languageText }), 'info', {
closable: true,
})
}
// 处理任务点击事件
const handleTaskClick = (task: Task) => {
clickedTask.value = task
@@ -306,12 +322,7 @@ const handleAddMilestone = () => {
showMilestoneDialog.value = true
}
const handleLanguageChange = (lang: 'zh' | 'en') => {
const languageText = lang === 'zh' ? '中文' : 'English'
showMessage(formatTranslation('languageSwitchedTo', { language: languageText }), 'info', {
closable: true,
})
}
const handleThemeChange = (isDark: boolean) => {
const themeText = isDark ? t.value.darkModeText : t.value.lightModeText
@@ -544,6 +555,86 @@ function onTimerStopped(task: Task) {
function taskDebug(item: any) {
// Placeholder for debugging
}
// TaskRow拖拽移动事件处理器
const handleTaskRowMoved = async (payload: {
draggedTask: Task
targetTask: Task
position: 'after' | 'child' // 'after': 放在目标任务之后(同级), 'child': 作为目标任务的子任务
oldParent: Task | null
newParent: Task | null
}) => {
const { draggedTask, targetTask, position, oldParent, newParent } = payload
// 【注意】组件内部已自动完成数据移动,通过对象引用修改实现 TaskList 和 Timeline 的自动同步
// 因此监听此事件是完全可选的,仅用于:
// 1. 显示自定义提示消息
// 2. 调用后端API保存任务层级变更
// 3. 记录操作日志
// 4. 触发其他业务逻辑(如更新关联数据)
// 构建提示消息
const oldParentName = getParentName(oldParent)
const newParentName = position === 'after'
? getParentName(newParent)
: getParentName({ type: targetTask.type, name: targetTask.name })
let message = ''
const msgs = demoMessages.value.taskMoveConfirm.messages
if (position === 'after') {
// 算法#1: 放置在目标任务之后
message = formatMessage(msgs.moveAfter, {
draggedTaskType: getTaskTypeName(draggedTask.type),
draggedTaskName: draggedTask.name,
targetTaskType: getTaskTypeName(targetTask.type),
targetTaskName: targetTask.name,
})
} else {
// 算法#2: 作为子任务放置
if (oldParent && oldParent.id !== targetTask.id) {
message = formatMessage(msgs.moveAsChild, {
draggedTaskName: draggedTask.name,
oldParentName,
newParentName,
})
} else if (!oldParent) {
message = formatMessage(msgs.moveAsChildNoOldParent, {
draggedTaskName: draggedTask.name,
newParentName,
})
} else {
message = formatMessage(msgs.moveAsChildSameParent, {
draggedTaskName: draggedTask.name,
newParentName,
})
}
}
// 显示移动成功提示
const successMsg = demoMessages.value.taskMoveConfirm.messages.moveSuccess
showMessage(`${successMsg}: ${message}`, 'success', { closable: true })
// ⚠️ 重要:必须更新 tasks.value 以同步 TaskList 和 Timeline
// TaskList 已更新内部视图,但 Timeline 依赖 props.tasks
// 此赋值会触发 GanttChart 的 watch,进而触发 Timeline 重新渲染
tasks.value = updatedTasks
// 调用后端API保存任务层级变更
// try {
// await api.updateTaskHierarchy({
// taskId: draggedTask.id,
// targetTaskId: targetTask.id,
// position: position, // 'after' 或 'child'
// oldParentId: oldParent?.id,
// newParentId: newParent?.id,
// })
// console.log('任务层级已保存到后端')
// } catch (error) {
// console.error('保存任务层级失败:', error)
// showMessage('保存失败,请刷新页面', 'error', { closable: true })
// }
}
</script>
<template>
@@ -907,6 +998,17 @@ function taskDebug(item: any) {
{{ t.taskBarConfig.mistouch.allowDragOnClickHint }}
</span>
</div>
<div class="control-row">
<label class="taskbar-control">
<input v-model="enableTaskRowMove" type="checkbox" />
<span class="taskbar-label">
启用TaskRow拖拽移动
</span>
</label>
<span class="control-hint">
允许通过拖拽TaskRow来调整任务的层级和顺序
</span>
</div>
<div class="control-row">
<label class="control-label">
{{ t.taskBarConfig.mistouch.dragThreshold }}:
@@ -985,6 +1087,7 @@ function taskDebug(item: any) {
:working-hours="workingHoursConfig"
:use-default-milestone-dialog="true"
:allow-drag-and-resize="allowDragAndResize"
:enable-task-row-move="enableTaskRowMove"
:on-export-csv="handleCustomCsvExport"
:on-language-change="handleLanguageChange"
:on-theme-change="handleThemeChange"
@@ -1011,6 +1114,7 @@ function taskDebug(item: any) {
@task-deleted="handleTaskDeleteEvent"
@task-added="handleTaskAddEvent"
@task-updated="handleTaskUpdateEvent"
@task-row-moved="handleTaskRowMoved"
>
<template #custom-task-content="item">
<HtmlContent
+241
View File
@@ -0,0 +1,241 @@
<script setup lang="ts">
interface Props {
visible?: boolean
title?: string
message?: string
confirmText?: string
cancelText?: string
}
withDefaults(defineProps<Props>(), {
visible: false,
title: '确认操作',
message: '',
confirmText: '确认',
cancelText: '取消',
})
const emit = defineEmits<{
confirm: []
cancel: []
}>()
const handleConfirm = () => {
emit('confirm')
}
const handleCancel = () => {
emit('cancel')
}
</script>
<template>
<div v-if="visible" class="confirm-overlay" @click="handleCancel">
<div class="confirm-dialog" @click.stop>
<div class="confirm-header">
<h3>{{ title }}</h3>
<button class="close-btn" @click="handleCancel">×</button>
</div>
<div class="confirm-body">
<div class="confirm-icon">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="10" stroke="#409eff" stroke-width="2" />
<path d="M12 8v5M12 16h.01" stroke="#409eff" stroke-width="2" stroke-linecap="round" />
</svg>
</div>
<p class="confirm-message">{{ message }}</p>
</div>
<div class="confirm-footer">
<button class="btn btn-cancel" @click="handleCancel">{{ cancelText }}</button>
<button class="btn btn-confirm" @click="handleConfirm">{{ confirmText }}</button>
</div>
</div>
</div>
</template>
<style scoped>
.confirm-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.4);
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.confirm-dialog {
background: white;
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
min-width: 420px;
max-width: 90vw;
animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
from {
transform: translateY(20px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.confirm-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 24px;
border-bottom: 1px solid #e8e8e8;
}
.confirm-header h3 {
margin: 0;
font-size: 18px;
font-weight: 600;
color: #303133;
}
.close-btn {
background: none;
border: none;
font-size: 28px;
color: #909399;
cursor: pointer;
padding: 0;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
transition: all 0.2s;
}
.close-btn:hover {
background: #f5f7fa;
color: #606266;
}
.confirm-body {
padding: 32px 24px;
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
}
.confirm-icon {
display: flex;
align-items: center;
justify-content: center;
}
.confirm-message {
font-size: 15px;
color: #606266;
line-height: 1.6;
text-align: center;
margin: 0;
white-space: pre-line;
}
.confirm-footer {
padding: 16px 24px;
display: flex;
justify-content: flex-end;
gap: 12px;
border-top: 1px solid #e8e8e8;
}
.btn {
padding: 10px 24px;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
border: none;
transition: all 0.2s;
min-width: 80px;
}
.btn-cancel {
background: #f5f7fa;
color: #606266;
}
.btn-cancel:hover {
background: #e8eaed;
}
.btn-confirm {
background: #409eff;
color: white;
}
.btn-confirm:hover {
background: #66b1ff;
}
.btn-confirm:active {
background: #3a8ee6;
}
</style>
<style>
/* 暗色主题支持 - 非scoped样式以便访问html元素 */
html[data-theme='dark'] .confirm-dialog {
background: #1d1e1f;
}
html[data-theme='dark'] .confirm-header {
border-bottom-color: #414243;
}
html[data-theme='dark'] .confirm-header h3 {
color: #e5e7eb;
}
html[data-theme='dark'] .confirm-message {
color: #b4b6b9;
}
html[data-theme='dark'] .confirm-footer {
border-top-color: #414243;
}
html[data-theme='dark'] .btn-cancel {
background: #2c2d2e;
color: #b4b6b9;
}
html[data-theme='dark'] .btn-cancel:hover {
background: #363738;
}
html[data-theme='dark'] .close-btn {
color: #909399;
}
html[data-theme='dark'] .close-btn:hover {
background: #2c2d2e;
color: #b4b6b9;
}
</style>
+24
View File
@@ -0,0 +1,24 @@
{
"taskMoveConfirm": {
"title": "Confirm Task Move",
"confirmText": "Confirm",
"cancelText": "Cancel",
"messages": {
"moveAfter": "{draggedTaskType} [{draggedTaskName}] will be placed after {targetTaskType} [{targetTaskName}]. Continue?",
"moveAsChild": "Task [{draggedTaskName}] will be unlinked from {oldParentName} and linked to {newParentName}. Continue?",
"moveAsChildNoOldParent": "Task [{draggedTaskName}] will be linked to {newParentName}. Continue?",
"moveAsChildSameParent": "Task [{draggedTaskName}] will be moved to the first position under {newParentName}. Continue?",
"moveCanceled": "Task move canceled",
"moveSuccess": "Task moved successfully"
},
"taskTypes": {
"story": "Story",
"task": "Task"
},
"parentNames": {
"root": "Root",
"story": "Story [{name}]",
"task": "Task [{name}]"
}
}
}
+24
View File
@@ -0,0 +1,24 @@
{
"taskMoveConfirm": {
"title": "确认移动任务",
"confirmText": "确认",
"cancelText": "取消",
"messages": {
"moveAfter": "{draggedTaskType}【{draggedTaskName}】将放置{targetTaskType}【{targetTaskName}】之后,确认是否继续?",
"moveAsChild": "任务【{draggedTaskName}】将解除与{oldParentName}的关系,并设置于{newParentName}的关系,确认是否继续?",
"moveAsChildNoOldParent": "任务【{draggedTaskName}】将设置于{newParentName}的关系,确认是否继续?",
"moveAsChildSameParent": "任务【{draggedTaskName}】将移动到{newParentName}的第一位,确认是否继续?",
"moveCanceled": "任务移动已取消",
"moveSuccess": "任务移动成功"
},
"taskTypes": {
"story": "需求",
"task": "任务"
},
"parentNames": {
"root": "根目录",
"story": "需求【{name}】",
"task": "任务【{name}】"
}
}
}
+89
View File
@@ -0,0 +1,89 @@
import { ref, computed } from 'vue'
import zhCN from './locales/zh-CN.json'
import enUS from './locales/en-US.json'
export type LocaleKey = 'zh-CN' | 'en-US'
interface LocaleMessages {
taskMoveConfirm: {
title: string
confirmText: string
cancelText: string
messages: {
moveAfter: string
moveAsChild: string
moveAsChildNoOldParent: string
moveAsChildSameParent: string
moveCanceled: string
moveSuccess: string
}
taskTypes: {
story: string
task: string
}
parentNames: {
root: string
story: string
task: string
}
}
}
const localeMessages: Record<LocaleKey, LocaleMessages> = {
'zh-CN': zhCN,
'en-US': enUS,
}
const currentLocale = ref<LocaleKey>('zh-CN')
export function useDemoLocale() {
const locale = computed(() => currentLocale.value)
const messages = computed(() => localeMessages[currentLocale.value])
const setLocale = (newLocale: LocaleKey) => {
currentLocale.value = newLocale
}
/**
* 格式化消息,替换占位符
*/
const formatMessage = (template: string | undefined, params: Record<string, string>) => {
if (!template) return ''
return template.replace(/\{(\w+)\}/g, (match, key) => {
return params[key] || match
})
}
/**
* 获取任务类型名称
*/
const getTaskTypeName = (type: string) => {
return messages.value.taskMoveConfirm.taskTypes[type as 'story' | 'task'] || type
}
/**
* 获取父任务名称
*/
const getParentName = (parent: { type: string; name: string } | null) => {
if (!parent) {
return messages.value.taskMoveConfirm.parentNames.root
}
const template = messages.value.taskMoveConfirm.parentNames[parent.type as 'story' | 'task']
// 如果找不到模板,直接返回任务名称
if (!template) {
return parent.name
}
return formatMessage(template, { name: parent.name })
}
return {
locale,
messages,
setLocale,
formatMessage,
getTaskTypeName,
getParentName,
}
}
+20
View File
@@ -322,5 +322,25 @@
"Added: Large data loading demonstration",
"Fix: jspdf vulnerabilies"
]
},
{
"version": "1.4.4",
"date": "2025-12-06",
"notes": [
"新增:任务列表中任务项的移动拖放功能",
"<span style=\"font-weight: bold; color: #f00;\">特别感谢 jun201607@github的使用及反馈的宝贵意见</span>",
"Added: Task item move and drag-and-drop functionality in the task list",
"<span style=\"font-weight: bold; color: #f00;\">Special thanks to jun201607@github for their valuable use and feedback</span>"
]
},
{
"version": "1.4.5",
"date": "2025-12-06",
"notes": [
"优化:任务列表中任务项的移动拖放功能",
"<span style=\"font-weight: bold; color: #f00;\">特别感谢 jun201607@github的使用及反馈的宝贵意见</span>",
"Optimized: Task item move and drag-and-drop functionality in the task list",
"<span style=\"font-weight: bold; color: #f00;\">Special thanks to jun201607@github for their valuable use and feedback</span>"
]
}
]