Vue2实战教程:构建企业级任务管理系统 | 前端开发指南

2025-08-21 0 1,013


任务列表

所有任务
待处理
进行中
已完成

{{ task.title }}

{{ task.description }}

优先级: {{ task.priority }}
截止日期: {{ formatDate(task.deadline) }}
状态: {{ getStatusText(task.status) }}



暂无任务,请添加新任务

{{ editingTask ? ‘编辑任务’ : ‘添加新任务’ }}




待处理
进行中
已完成


任务统计

总任务数

{{ tasks.length }}

待处理

{{ pendingTasksCount }}

进行中

{{ inProgressTasksCount }}

已完成

{{ completedTasksCount }}

任务优先级分布

{{ getPriorityText(priority) }}: {{ count }}

new Vue({
el: ‘#app’,
data: {
currentView: ‘task-list’,
tasks: [
{
id: 1,
title: ‘学习Vue组件开发‘,
description: ‘深入学习Vue组件的生命周期和通信方式’,
priority: ‘high’,
deadline: ‘2023-12-15’,
status: ‘in-progress’
},
{
id: 2,
title: ‘编写项目文档’,
description: ‘为当前项目编写详细的技术文档’,
priority: ‘medium’,
deadline: ‘2023-12-20’,
status: ‘pending’
}
],
taskForm: {
id: null,
title: ”,
description: ”,
priority: ‘medium’,
deadline: ”,
status: ‘pending’
},
editingTask: null,
filterStatus: ‘all’,
searchQuery: ”,
nextId: 3
},
computed: {
filteredTasks() {
let filtered = this.tasks;

// 状态过滤
if (this.filterStatus !== ‘all’) {
filtered = filtered.filter(task => task.status === this.filterStatus);
}

// 搜索过滤
if (this.searchQuery) {
const query = this.searchQuery.toLowerCase();
filtered = filtered.filter(task =>
task.title.toLowerCase().includes(query) ||
task.description.toLowerCase().includes(query)
);
}

return filtered;
},
pendingTasksCount() {
return this.tasks.filter(task => task.status === ‘pending’).length;
},
inProgressTasksCount() {
return this.tasks.filter(task => task.status === ‘in-progress’).length;
},
completedTasksCount() {
return this.tasks.filter(task => task.status === ‘completed’).length;
},
priorityStats() {
const stats = { low: 0, medium: 0, high: 0 };
this.tasks.forEach(task => {
stats[task.priority]++;
});
return stats;
}
},
methods: {
saveTask() {
if (this.editingTask) {
// 更新现有任务
const index = this.tasks.findIndex(task => task.id === this.editingTask.id);
if (index !== -1) {
this.tasks.splice(index, 1, { …this.taskForm });
}
} else {
// 添加新任务
this.tasks.push({
…this.taskForm,
id: this.nextId++
});
}

this.resetForm();
this.currentView = ‘task-list’;
this.saveToLocalStorage();
},
editTask(task) {
this.editingTask = task;
this.taskForm = { …task };
this.currentView = ‘add-task’;
},
cancelEdit() {
this.resetForm();
this.currentView = ‘task-list’;
},
resetForm() {
this.taskForm = {
id: null,
title: ”,
description: ”,
priority: ‘medium’,
deadline: ”,
status: ‘pending’
};
this.editingTask = null;
},
deleteTask(taskId) {
if (confirm(‘确定要删除这个任务吗?’)) {
this.tasks = this.tasks.filter(task => task.id !== taskId);
this.saveToLocalStorage();
}
},
updateTaskStatus(taskId, status) {
const task = this.tasks.find(task => task.id === taskId);
if (task) {
task.status = status;
this.saveToLocalStorage();
}
},
formatDate(dateString) {
const options = { year: ‘numeric’, month: ‘short’, day: ‘numeric’ };
return new Date(dateString).toLocaleDateString(‘zh-CN’, options);
},
getStatusText(status) {
const statusMap = {
‘pending’: ‘待处理’,
‘in-progress’: ‘进行中’,
‘completed’: ‘已完成’
};
return statusMap[status] || status;
},
getPriorityText(priority) {
const priorityMap = {
‘low’: ‘低’,
‘medium’: ‘中’,
‘high’: ‘高’
};
return priorityMap[priority] || priority;
},
saveToLocalStorage() {
localStorage.setItem(‘taskManagerTasks’, JSON.stringify(this.tasks));
localStorage.setItem(‘taskManagerNextId’, this.nextId.toString());
},
loadFromLocalStorage() {
const savedTasks = localStorage.getItem(‘taskManagerTasks’);
const savedNextId = localStorage.getItem(‘taskManagerNextId’);

if (savedTasks) {
this.tasks = JSON.parse(savedTasks);
}

if (savedNextId) {
this.nextId = parseInt(savedNextId);
}
}
},
mounted() {
this.loadFromLocalStorage();
}
});

Vue2实战教程:构建企业级任务管理系统 | 前端开发指南
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

淘吗网 vue2 Vue2实战教程:构建企业级任务管理系统 | 前端开发指南 https://www.taomawang.com/web/vue2/942.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务