feat: 版本详情完整功能 + 数据串联 + 登录模块
- 版本详情:关联需求Tab(从需求池添加已采纳需求/移除释放) - 版本详情:调研/产品方案/UI设计Tab(计划CRUD、完成提交成果、耗时统计) - 版本详情:超期校验(结束日期超版本截止需填写原因) - 版本详情:概览统计卡片(加班时长/排名/原因占比) - 数据串联:产品→项目→版本→需求→加班全链路贯通 - 版本管理:规划中版本可删除,删除释放关联需求 - 数据清理:仅保留翻台宝/值班,需求池10条值班待评审需求 - 修复:列表页overflow裁剪菜单问题(4个页面统一修复) - 新增:登录模块、AuthGuard、VersionPlan store Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
65
apps/web/lib/version-plan.ts
Normal file
65
apps/web/lib/version-plan.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
export interface VersionPlan {
|
||||
id: string;
|
||||
versionId: string;
|
||||
type: 'research' | 'product' | 'ui';
|
||||
title: string;
|
||||
owner: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
status: 'pending' | 'in_progress' | 'completed';
|
||||
linkedRequirementIds?: string[];
|
||||
resultType?: 'link' | 'file';
|
||||
resultUrl?: string;
|
||||
resultFileName?: string;
|
||||
resultFileData?: string;
|
||||
remark?: string;
|
||||
overdueReason?: string;
|
||||
createdAt: string;
|
||||
completedAt?: string;
|
||||
addedBy: string;
|
||||
}
|
||||
|
||||
export type PlanType = VersionPlan['type'];
|
||||
|
||||
export function calcPlanDuration(start: string, end: string): { days: number; hours: number } {
|
||||
const s = new Date(start).getTime();
|
||||
const e = new Date(end).getTime();
|
||||
if (isNaN(s) || isNaN(e) || e <= s) return { days: 0, hours: 0 };
|
||||
const totalDays = Math.ceil((e - s) / (1000 * 60 * 60 * 24));
|
||||
return { days: totalDays, hours: totalDays * 8 };
|
||||
}
|
||||
|
||||
export function formatDuration(days: number, _hours: number): string {
|
||||
if (days === 0) return '0天';
|
||||
return `${days}天`;
|
||||
}
|
||||
|
||||
export function calcTotalDuration(plans: VersionPlan[]): string {
|
||||
const completedOrActive = plans.filter((p) => p.status !== 'pending');
|
||||
if (completedOrActive.length === 0) return '0天';
|
||||
|
||||
const intervals = completedOrActive.map((p) => ({
|
||||
start: new Date(p.startTime).getTime(),
|
||||
end: p.completedAt ? new Date(p.completedAt).getTime() : new Date(p.endTime).getTime(),
|
||||
})).filter((i) => i.end > i.start).sort((a, b) => a.start - b.start);
|
||||
|
||||
if (intervals.length === 0) return '0天';
|
||||
|
||||
let totalMs = 0;
|
||||
let currentStart = intervals[0].start;
|
||||
let currentEnd = intervals[0].end;
|
||||
|
||||
for (let i = 1; i < intervals.length; i++) {
|
||||
if (intervals[i].start <= currentEnd) {
|
||||
currentEnd = Math.max(currentEnd, intervals[i].end);
|
||||
} else {
|
||||
totalMs += currentEnd - currentStart;
|
||||
currentStart = intervals[i].start;
|
||||
currentEnd = intervals[i].end;
|
||||
}
|
||||
}
|
||||
totalMs += currentEnd - currentStart;
|
||||
|
||||
const totalDays = Math.ceil(totalMs / (1000 * 60 * 60 * 24));
|
||||
return `${totalDays}天`;
|
||||
}
|
||||
Reference in New Issue
Block a user