feat(platform): add delivery time presets
This commit is contained in:
@@ -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) => (
|
||||
|
||||
Reference in New Issue
Block a user