R63 A1-A6:通知中心体验增强
这个提交包含在:
@@ -0,0 +1,75 @@
|
||||
type NotificationTarget = {
|
||||
targetType: string | null;
|
||||
targetId: string | null;
|
||||
};
|
||||
|
||||
export function resolveNotificationTargetLink(item: NotificationTarget) {
|
||||
if (!item.targetType || !item.targetId) return null;
|
||||
|
||||
if (item.targetType === "workflow_task") {
|
||||
return `/workflow/tasks/${item.targetId}`;
|
||||
}
|
||||
|
||||
if (item.targetType === "reimbursement_form") {
|
||||
return `/reimbursements/${item.targetId}`;
|
||||
}
|
||||
|
||||
if (item.targetType === "leave_request") {
|
||||
return `/leave-requests?highlight=${item.targetId}`;
|
||||
}
|
||||
|
||||
if (item.targetType === "purchase_request") {
|
||||
return `/purchase-requests?highlight=${item.targetId}`;
|
||||
}
|
||||
|
||||
if (item.targetType === "travel_request") {
|
||||
return `/travel-requests?highlight=${item.targetId}`;
|
||||
}
|
||||
|
||||
if (item.targetType === "asset" || item.targetType === "asset_card") {
|
||||
return `/assets?highlight=${item.targetId}`;
|
||||
}
|
||||
|
||||
if (item.targetType === "inventory_check") {
|
||||
return `/inventory-checks?highlight=${item.targetId}`;
|
||||
}
|
||||
|
||||
if (item.targetType === "employee") {
|
||||
return "/settings/profile";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function formatNotificationRelativeTime(value: string | null) {
|
||||
if (!value) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
const timestamp = new Date(value).getTime();
|
||||
if (Number.isNaN(timestamp)) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
const diffMs = Date.now() - timestamp;
|
||||
if (diffMs < 60 * 1000) {
|
||||
return "刚刚";
|
||||
}
|
||||
|
||||
const diffMinutes = Math.floor(diffMs / (60 * 1000));
|
||||
if (diffMinutes < 60) {
|
||||
return `${diffMinutes} 分钟前`;
|
||||
}
|
||||
|
||||
const diffHours = Math.floor(diffMinutes / 60);
|
||||
if (diffHours < 24) {
|
||||
return `${diffHours} 小时前`;
|
||||
}
|
||||
|
||||
const diffDays = Math.floor(diffHours / 24);
|
||||
if (diffDays < 7) {
|
||||
return `${diffDays} 天前`;
|
||||
}
|
||||
|
||||
return new Date(value).toLocaleDateString("zh-CN");
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户