fix: 完成: 诊所设置中心,消息中心

This commit is contained in:
2025-04-10 17:08:23 +08:00
parent 22f91e294b
commit ed6b1bb36d
12 changed files with 1429 additions and 86 deletions

View File

@@ -348,3 +348,28 @@ export function getRegisterStatus(status: number) {
}
}
}
// 把格式化时间转换成相对时间(刚刚,几分钟前,几小时前,几天前,几周前)
export function formatTimeToRelative(time: string) {
const now = new Date();
const date = new Date(time);
const diff = now.getTime() - date.getTime();
const seconds = Math.floor(diff / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const weeks = Math.floor(days / 7);
if(seconds < 60) {
return '刚刚';
} else if(minutes < 60) {
return `${minutes} 分钟前`;
} else if(hours < 24) {
return `${hours} 小时前`;
} else if(days < 7) {
return `${days} 天前`;
} else if (weeks < 4) {
return `${weeks} 周前`;
}
return time;
}