mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 02:29:19 +08:00
feat: 经营概览改成默认显示全部
This commit is contained in:
+24
-2
@@ -6,6 +6,7 @@ import {
|
|||||||
clampFinanceKpiColsPerRow,
|
clampFinanceKpiColsPerRow,
|
||||||
FINANCE_KPI_DEFAULT_COLS_PER_ROW,
|
FINANCE_KPI_DEFAULT_COLS_PER_ROW,
|
||||||
FINANCE_KPI_DEFAULT_VISIBLE_CARDS,
|
FINANCE_KPI_DEFAULT_VISIBLE_CARDS,
|
||||||
|
FINANCE_KPI_LEGACY_DEFAULT_VISIBLE_CARDS,
|
||||||
FINANCE_KPI_PREFS_KEY,
|
FINANCE_KPI_PREFS_KEY,
|
||||||
FINANCE_KPI_PREFS_KEY_V1,
|
FINANCE_KPI_PREFS_KEY_V1,
|
||||||
migrateV1LabelsToCardIds,
|
migrateV1LabelsToCardIds,
|
||||||
@@ -15,6 +16,23 @@ import {
|
|||||||
type FinanceKpiCardId,
|
type FinanceKpiCardId,
|
||||||
} from '../constants/kpi-catalog';
|
} from '../constants/kpi-catalog';
|
||||||
|
|
||||||
|
/** 判断两套卡片 id 是否集合相等(忽略顺序) */
|
||||||
|
function sameCardSet(a: string[], b: string[]): boolean {
|
||||||
|
if (a.length !== b.length) return false;
|
||||||
|
const set = new Set(a);
|
||||||
|
return b.every((id) => set.has(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 仍为旧产品默认时,升到「全显」;用户自行勾选过的保留 */
|
||||||
|
function upgradeLegacyDefaultVisible(
|
||||||
|
ids: FinanceKpiCardId[],
|
||||||
|
): FinanceKpiCardId[] {
|
||||||
|
if (sameCardSet(ids, FINANCE_KPI_LEGACY_DEFAULT_VISIBLE_CARDS)) {
|
||||||
|
return [...FINANCE_KPI_DEFAULT_VISIBLE_CARDS];
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
type PrefsV2 = {
|
type PrefsV2 = {
|
||||||
version: 2;
|
version: 2;
|
||||||
visibleCardIds: string[];
|
visibleCardIds: string[];
|
||||||
@@ -63,7 +81,9 @@ function loadFromStorage(): {
|
|||||||
const parsed = JSON.parse(rawV2) as PrefsV2;
|
const parsed = JSON.parse(rawV2) as PrefsV2;
|
||||||
if (Array.isArray(parsed.visibleCardIds)) {
|
if (Array.isArray(parsed.visibleCardIds)) {
|
||||||
return {
|
return {
|
||||||
visibleCardIds: normalizeVisibleCards(parsed.visibleCardIds),
|
visibleCardIds: upgradeLegacyDefaultVisible(
|
||||||
|
normalizeVisibleCards(parsed.visibleCardIds),
|
||||||
|
),
|
||||||
primaryByCardId: normalizePrimaries(parsed.primaryByCardId),
|
primaryByCardId: normalizePrimaries(parsed.primaryByCardId),
|
||||||
colsPerRow: clampFinanceKpiColsPerRow(
|
colsPerRow: clampFinanceKpiColsPerRow(
|
||||||
parsed.colsPerRow ?? FINANCE_KPI_DEFAULT_COLS_PER_ROW,
|
parsed.colsPerRow ?? FINANCE_KPI_DEFAULT_COLS_PER_ROW,
|
||||||
@@ -80,7 +100,9 @@ function loadFromStorage(): {
|
|||||||
if (rawV1) {
|
if (rawV1) {
|
||||||
const parsed = JSON.parse(rawV1) as PrefsV1;
|
const parsed = JSON.parse(rawV1) as PrefsV1;
|
||||||
if (Array.isArray(parsed.visibleLabels)) {
|
if (Array.isArray(parsed.visibleLabels)) {
|
||||||
const visibleCardIds = migrateV1LabelsToCardIds(parsed.visibleLabels);
|
const visibleCardIds = upgradeLegacyDefaultVisible(
|
||||||
|
migrateV1LabelsToCardIds(parsed.visibleLabels),
|
||||||
|
);
|
||||||
const migratedPrimary = migrateV1PrimaryByCard(parsed.visibleLabels);
|
const migratedPrimary = migrateV1PrimaryByCard(parsed.visibleLabels);
|
||||||
return {
|
return {
|
||||||
visibleCardIds,
|
visibleCardIds,
|
||||||
|
|||||||
+6
-2
@@ -160,8 +160,8 @@ export const FINANCE_KPI_CARDS: FinanceKpiCardDef[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
/** 默认展示的卡片(不含成本,减少噪音) */
|
/** 曾默认隐藏「销量」「成本」;用于把仍停在旧默认的本地偏好升到「全显」 */
|
||||||
export const FINANCE_KPI_DEFAULT_VISIBLE_CARDS: FinanceKpiCardId[] = [
|
export const FINANCE_KPI_LEGACY_DEFAULT_VISIBLE_CARDS: FinanceKpiCardId[] = [
|
||||||
'revenue',
|
'revenue',
|
||||||
'orders',
|
'orders',
|
||||||
'aov',
|
'aov',
|
||||||
@@ -170,6 +170,10 @@ export const FINANCE_KPI_DEFAULT_VISIBLE_CARDS: FinanceKpiCardId[] = [
|
|||||||
'ads',
|
'ads',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** 默认展示全部 KPI 卡片 */
|
||||||
|
export const FINANCE_KPI_DEFAULT_VISIBLE_CARDS: FinanceKpiCardId[] =
|
||||||
|
FINANCE_KPI_CARDS.map((c) => c.id);
|
||||||
|
|
||||||
export function cardById(id: string): FinanceKpiCardDef | undefined {
|
export function cardById(id: string): FinanceKpiCardDef | undefined {
|
||||||
return FINANCE_KPI_CARDS.find((c) => c.id === id);
|
return FINANCE_KPI_CARDS.find((c) => c.id === id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user