warningSummaryParams.js
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const STORAGE_KEY = "strategyCentre_warningSummaryParams";
const CYCLE_TYPE_MAP = { 1: 2, 2: 3, 4: 4 };
/** 与策略中心 getMonitorListData 中 params 构建逻辑一致 */
export function buildWarningSummaryParams({
filters = {},
timeRangeType = {},
dateRange = {},
currentTab = {},
currentWatchType = {},
currentIndicatorType = {},
}) {
const {
storeName,
isStrategySent,
groupId,
provinceId,
firstbrandIds,
twoBrandIds,
regionOps,
onlineOps,
supervisorOps,
} = filters;
return {
storeName,
isStrategySent: isStrategySent === "" ? undefined : isStrategySent,
groupId,
regionId: provinceId,
firstbrandIds: firstbrandIds || [],
twoBrandIds: twoBrandIds || [],
regionalOperatorId: regionOps,
onlineOperatorId: onlineOps,
flightSupervisionId: supervisorOps,
cycleType: CYCLE_TYPE_MAP[timeRangeType.value],
businessType: currentTab.value,
startDate: dateRange.startDate,
monitorType: currentWatchType.value,
metricTypeId: currentIndicatorType.value,
endDate: dateRange.endDate,
};
}
export function cleanWarningSummaryParams(params) {
return Object.fromEntries(
Object.entries(params).filter(([_, v]) => v != null && v !== "" && !(Array.isArray(v) && v.length === 0)),
);
}
export function getWarningSummaryCleanParams(state) {
return cleanWarningSummaryParams(buildWarningSummaryParams(state));
}
export function saveWarningSummaryParams(params) {
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(params));
}
export function loadWarningSummaryParams() {
try {
const raw = sessionStorage.getItem(STORAGE_KEY);
return raw ? JSON.parse(raw) : null;
} catch {
return null;
}
}
/** 门店看板路由参数兜底(无策略中心缓存时) */
export function getWarningSummaryParamsFromRoute(query = {}) {
const { businessType, startDate, endDate, timeRangeType, periodType } = query;
const period = timeRangeType ?? periodType;
return cleanWarningSummaryParams({
businessType: businessType != null ? Number(businessType) : undefined,
startDate,
endDate,
cycleType: CYCLE_TYPE_MAP[period],
});
}