feat(产品方案): 优化计划卡片展示和排序
This commit is contained in:
@@ -78,6 +78,26 @@ export interface VersionPlan {
|
||||
|
||||
export type PlanType = VersionPlan['type'];
|
||||
|
||||
function getPlanCreatedAtTime(plan: VersionPlan): number {
|
||||
const time = new Date(plan.createdAt).getTime();
|
||||
return Number.isFinite(time) ? time : 0;
|
||||
}
|
||||
|
||||
function getPlanIdTime(plan: VersionPlan): number {
|
||||
const match = /^plan-(\d+)$/.exec(plan.id);
|
||||
if (!match) return 0;
|
||||
const time = Number(match[1]);
|
||||
return Number.isFinite(time) ? time : 0;
|
||||
}
|
||||
|
||||
export function sortPlansNewestFirst(plans: VersionPlan[]): VersionPlan[] {
|
||||
return [...plans].sort((a, b) => {
|
||||
const createdDiff = getPlanCreatedAtTime(b) - getPlanCreatedAtTime(a);
|
||||
if (createdDiff !== 0) return createdDiff;
|
||||
return getPlanIdTime(b) - getPlanIdTime(a);
|
||||
});
|
||||
}
|
||||
|
||||
export function calcPlanProgress(tasks?: PlanTask[]): number {
|
||||
if (!tasks || tasks.length === 0) return 0;
|
||||
const completed = tasks.filter((t) => t.status === 'completed').length;
|
||||
|
||||
Reference in New Issue
Block a user