feat(dev-task): 开发任务模块 V1 完整实现
- 核心库:dev-task.ts(类型+状态机+进度计算)、task-worklog.ts(工时)、task-category.ts(字典)、work-item.ts(聚合契约) - Store:useDevTaskStore(CRUD+状态流转)、useTaskWorklogStore(工时记录)、useTaskCategoryStore(字典管理) - UI组件:DevTaskTab、DevTaskCreateModal、DevTaskDetailDrawer、DevTaskRow、WorklogPanel、StatusBadge、CategoryChip - 集成:版本详情页"开发任务"Tab、"与我相关"工作台开发任务分组、任务类型管理页 - 设计文档:spec + 实施计划 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
57
apps/web/stores/useTaskWorklogStore.ts
Normal file
57
apps/web/stores/useTaskWorklogStore.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
'use client';
|
||||
import { create } from 'zustand';
|
||||
import type { TaskWorklog } from '@/lib/task-worklog';
|
||||
|
||||
const STORAGE_KEY = 'ftb_task_worklogs_v1';
|
||||
|
||||
function saveLocal(items: TaskWorklog[]) {
|
||||
try { localStorage.setItem(STORAGE_KEY, JSON.stringify(items)); } catch {}
|
||||
}
|
||||
|
||||
function loadLocal(): TaskWorklog[] | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (raw) return JSON.parse(raw);
|
||||
} catch {}
|
||||
return null;
|
||||
}
|
||||
|
||||
interface TaskWorklogState {
|
||||
worklogs: TaskWorklog[];
|
||||
fetchWorklogs: () => void;
|
||||
addWorklog: (data: Omit<TaskWorklog, 'id' | 'createdAt'>) => void;
|
||||
deleteWorklog: (id: string) => void;
|
||||
getActualHours: (taskId: string) => number;
|
||||
}
|
||||
|
||||
export const useTaskWorklogStore = create<TaskWorklogState>((set, get) => ({
|
||||
worklogs: [],
|
||||
|
||||
fetchWorklogs: () => {
|
||||
const cached = loadLocal();
|
||||
if (cached) set({ worklogs: cached });
|
||||
},
|
||||
|
||||
addWorklog: (data) => {
|
||||
const item: TaskWorklog = {
|
||||
...data,
|
||||
id: `wl-${Date.now()}`,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
const updated = [...get().worklogs, item];
|
||||
set({ worklogs: updated });
|
||||
saveLocal(updated);
|
||||
},
|
||||
|
||||
deleteWorklog: (id) => {
|
||||
const updated = get().worklogs.filter((w) => w.id !== id);
|
||||
set({ worklogs: updated });
|
||||
saveLocal(updated);
|
||||
},
|
||||
|
||||
getActualHours: (taskId) => {
|
||||
return get().worklogs
|
||||
.filter((w) => w.taskId === taskId)
|
||||
.reduce((sum, w) => sum + w.hours, 0);
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user