feat: 添加工作任务管理功能
- 新增 Task 模型(状态、优先级、进展百分比) - 任务 API(列表、统计、进展更新、完成标记) - 前端任务板块(统计卡片 + 任务列表) - 进展可视化(进度条 + 进展记录)
This commit is contained in:
@@ -64,3 +64,59 @@ class DailyProgress(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.entry.date} - {self.category}: {self.progress_percent}%"
|
||||
|
||||
|
||||
class Task(models.Model):
|
||||
"""工作任务 - 跟踪任务和进展"""
|
||||
STATUS_CHOICES = [
|
||||
('pending', '⏳ 待开始'),
|
||||
('in_progress', '🔄 进行中'),
|
||||
('blocked', '🚧 已阻塞'),
|
||||
('completed', '✅ 已完成'),
|
||||
('cancelled', '❌ 已取消'),
|
||||
]
|
||||
|
||||
PRIORITY_CHOICES = [
|
||||
('low', '低'),
|
||||
('medium', '中'),
|
||||
('high', '高'),
|
||||
('critical', '紧急'),
|
||||
]
|
||||
|
||||
title = models.CharField('任务标题', max_length=200)
|
||||
description = models.TextField('任务描述', blank=True, default='')
|
||||
status = models.CharField('状态', max_length=20, choices=STATUS_CHOICES, default='pending')
|
||||
priority = models.CharField('优先级', max_length=20, choices=PRIORITY_CHOICES, default='medium')
|
||||
progress_percent = models.IntegerField('进展百分比', default=0)
|
||||
progress_notes = models.TextField('进展记录', blank=True, default='')
|
||||
assigned_to = models.CharField('负责人', max_length=100, blank=True, default='码神')
|
||||
due_date = models.DateField('截止日期', null=True, blank=True)
|
||||
completed_at = models.DateTimeField('完成时间', null=True, blank=True)
|
||||
created_at = models.DateTimeField('创建时间', auto_now_add=True)
|
||||
updated_at = models.DateTimeField('更新时间', auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-priority', 'created_at']
|
||||
verbose_name = '任务'
|
||||
verbose_name_plural = '任务'
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title} ({self.get_status_display()})"
|
||||
|
||||
def mark_completed(self):
|
||||
"""标记任务为已完成"""
|
||||
self.status = 'completed'
|
||||
self.progress_percent = 100
|
||||
self.completed_at = timezone.now()
|
||||
self.save()
|
||||
|
||||
def update_progress(self, percent, notes=''):
|
||||
"""更新任务进展"""
|
||||
self.progress_percent = percent
|
||||
if percent > 0 and self.status == 'pending':
|
||||
self.status = 'in_progress'
|
||||
if percent == 100:
|
||||
self.mark_completed()
|
||||
if notes:
|
||||
self.progress_notes = f"[{timezone.now().strftime('%Y-%m-%d %H:%M')}] {notes}\n" + self.progress_notes
|
||||
self.save()
|
||||
|
||||
Reference in New Issue
Block a user