feat(platform): add delivery time presets

This commit is contained in:
lingniu
2026-07-05 22:02:29 +08:00
parent 7580fce07e
commit eccede509f
3 changed files with 116 additions and 0 deletions

View File

@@ -125,6 +125,25 @@ function previousDateString(value: string) {
return `${year}-${month}-${day}`;
}
function offsetDateString(value: string, offsetDays: number) {
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim());
if (!match) return value;
const date = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]) + offsetDays);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
function weekStartDateString(value: string) {
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim());
if (!match) return value;
const date = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
const day = date.getDay();
const mondayOffset = day === 0 ? -6 : 1 - day;
return offsetDateString(value, mondayOffset);
}
function dayRangeText(dateFrom?: string, dateTo?: string) {
if (!dateFrom && !dateTo) return '未限定时间';
if (!dateFrom || !dateTo) return '单边时间窗';
@@ -2002,6 +2021,29 @@ export function Dashboard({
onClick: openTimeMonitorRaw
}
];
const deliveryToday = timeMonitorScopeValue.dateTo || todayDateString();
const customerTimeRangePresets = [
{
label: '最近一天',
range: `${previousDateString(deliveryToday)}${deliveryToday}`,
filters: { ...timeMonitorScopeValue, dateFrom: previousDateString(deliveryToday), dateTo: deliveryToday }
},
{
label: '最近三天',
range: `${offsetDateString(deliveryToday, -3)}${deliveryToday}`,
filters: { ...timeMonitorScopeValue, dateFrom: offsetDateString(deliveryToday, -3), dateTo: deliveryToday }
},
{
label: '本周',
range: `${weekStartDateString(deliveryToday)}${deliveryToday}`,
filters: { ...timeMonitorScopeValue, dateFrom: weekStartDateString(deliveryToday), dateTo: deliveryToday }
},
{
label: '自定义复盘',
range: '当前范围',
filters: timeMonitorScopeValue
}
];
const deliveryScopeText = `${timeMonitorScopeValue.keyword || '全部车辆'} / ${timeMonitorScopeValue.protocol || '全部数据通道'} / ${timeMonitorScopeValue.dateFrom || '-'}${timeMonitorScopeValue.dateTo || '-'}`;
const customerDeliveryWorkbenchItems = [
{
@@ -2140,6 +2182,22 @@ export function Dashboard({
<span></span>
<strong>{deliveryScopeText}</strong>
</div>
<div className="vp-customer-time-presets">
<span></span>
<div>
{customerTimeRangePresets.map((item) => (
<button
key={item.label}
type="button"
onClick={() => setTimeMonitorFilters(item.filters)}
aria-label={`客户常用时间范围 ${item.label} ${item.range} 应用`}
>
<strong>{item.label}</strong>
<small>{item.range}</small>
</button>
))}
</div>
</div>
</div>
<div className="vp-customer-delivery-workbench-grid">
{customerDeliveryWorkbenchItems.map((item) => (