feat: 新增每日进销存(大货库存监控)

This commit is contained in:
youruo 2026-09-23 17:40:56 +08:00
parent 9fd0bcaf4b
commit 2bd5dce3d7

View File

@ -1,195 +1,201 @@
export const DEFAULT_SIDEBAR_CONFIG = { export const DEFAULT_SIDEBAR_CONFIG = {
collapsedByDefault: false, collapsedByDefault: false,
darkModeByDefault: false, darkModeByDefault: false,
entries: [ entries: [
{ key: 'product-monitoring', type: 'item', label: '商品监控', icon: 'appstore', routeKey: 'product-monitoring', visible: true, order: 12 }, { key: 'product-monitoring', type: 'item', label: '商品监控', icon: 'appstore', routeKey: 'product-monitoring', visible: true, order: 12 },
{ key: 'ops-b-incentive', type: 'item', label: '激励看板', icon: 'line-chart', routeKey: 'ops-b-incentive', visible: true, order: 15 }, { key: 'ops-b-incentive', type: 'item', label: '激励看板', icon: 'line-chart', routeKey: 'ops-b-incentive', visible: true, order: 15 },
{ key: 'dashboard-preview', type: 'item', label: '仪表盘', icon: 'dashboard', routeKey: 'dashboard-preview', visible: true, order: 50 }, { key: 'dashboard-preview', type: 'item', label: '仪表盘', icon: 'dashboard', routeKey: 'dashboard-preview', visible: true, order: 50 },
{ {
key: 'marketing-management', type: 'group', label: '营销管理', icon: 'shopping', visible: true, order: 60, defaultExpanded: true, key: 'marketing-management', type: 'group', label: '营销管理', icon: 'shopping', visible: true, order: 60, defaultExpanded: true,
children: [ children: [
{ key: 'marketing-events', label: '营销活动', icon: 'projection', routeKey: 'marketing-events', visible: true, order: 30 }, { key: 'marketing-events', label: '营销活动', icon: 'projection', routeKey: 'marketing-events', visible: true, order: 30 },
{ key: 'promotion-module', label: '推广模块', icon: 'line-chart', routeKey: 'promotion-module', visible: true, order: 50 }, { key: 'promotion-module', label: '推广模块', icon: 'line-chart', routeKey: 'promotion-module', visible: true, order: 50 },
], ],
}, },
{ {
key: 'product-management', type: 'group', label: '商品管理', icon: 'appstore', visible: true, order: 70, defaultExpanded: true, key: 'product-management', type: 'group', label: '商品管理', icon: 'appstore', visible: true, order: 70, defaultExpanded: true,
children: [ children: [
{ key: 'product-analysis', label: '商品分析', icon: 'table', routeKey: 'product-analysis', visible: true, order: 20 }, { key: 'product-analysis', label: '商品分析', icon: 'table', routeKey: 'product-analysis', visible: true, order: 20 },
], ],
}, },
{ key: 'work-orders', type: 'item', label: '工单待办', icon: 'message', routeKey: 'work-orders', visible: true, order: 100 }, { key: 'work-orders', type: 'item', label: '工单待办', icon: 'message', routeKey: 'work-orders', visible: true, order: 100 },
{ {
key: 'modular-stock-monitor', type: 'group', label: '模块化库存监控', icon: 'appstore', visible: true, order: 105, defaultExpanded: true, key: 'modular-stock-monitor', type: 'group', label: '模块化库存监控', icon: 'appstore', visible: true, order: 105, defaultExpanded: true,
children: [ children: [
{ key: 'modular-stock-monitor-accessory', label: '配件库存监控', icon: 'table', routeKey: 'modular-stock-monitor-accessory', visible: true, order: 10 }, { key: 'modular-stock-monitor-accessory', label: '配件库存监控', icon: 'table', routeKey: 'modular-stock-monitor-accessory', visible: true, order: 10 },
{ key: 'mkh-bom-data', label: 'MKH-BOM资料', icon: 'table', routeKey: 'mkh-bom-data', visible: true, order: 20 }, { key: 'mkh-bom-data', label: 'MKH-BOM资料', icon: 'table', routeKey: 'mkh-bom-data', visible: true, order: 20 },
], ],
}, },
{ {
key: 'manage', type: 'group', label: '系统管理', icon: 'setting', visible: true, order: 900, defaultExpanded: false, requiresAdmin: true, key: 'large-stock-monitor', type: 'group', label: '大货库存监控', icon: 'appstore', visible: true, order: 200, defaultExpanded: true,
children: [ children: [
{ key: 'settings', label: '系统设置', icon: 'setting', routeKey: 'settings', visible: true, order: 10, requiresAdmin: true }, { key: 'daily-inventory', label: '每日进销存', icon: 'table', routeKey: 'daily-inventory', visible: true, order: 10 },
{ key: 'online-desktop-users', label: '在线客户端', icon: 'team', routeKey: 'online-desktop-users', visible: true, order: 30, requiresAdmin: true }, ],
{ key: 'desktop-execution-tasks', label: '执行任务', icon: 'projection', routeKey: 'desktop-execution-tasks', visible: true, order: 40, requiresAdmin: true }, },
], {
}, key: 'manage', type: 'group', label: '系统管理', icon: 'setting', visible: true, order: 900, defaultExpanded: false, requiresAdmin: true,
], children: [
}; { key: 'settings', label: '系统设置', icon: 'setting', routeKey: 'settings', visible: true, order: 10, requiresAdmin: true },
{ key: 'online-desktop-users', label: '在线客户端', icon: 'team', routeKey: 'online-desktop-users', visible: true, order: 30, requiresAdmin: true },
const cloneDefaultConfig = () => JSON.parse(JSON.stringify(DEFAULT_SIDEBAR_CONFIG)); { key: 'desktop-execution-tasks', label: '执行任务', icon: 'projection', routeKey: 'desktop-execution-tasks', visible: true, order: 40, requiresAdmin: true },
],
const flattenEntryKeys = (entries = []) => entries.flatMap((entry) => [ },
entry.key, ],
...flattenEntryKeys(entry.children || []), };
]).filter(Boolean);
const cloneDefaultConfig = () => JSON.parse(JSON.stringify(DEFAULT_SIDEBAR_CONFIG));
const flattenRouteKeys = (entries = []) => entries.flatMap((entry) => [
entry.routeKey, const flattenEntryKeys = (entries = []) => entries.flatMap((entry) => [
...flattenRouteKeys(entry.children || []), entry.key,
]).filter(Boolean); ...flattenEntryKeys(entry.children || []),
]).filter(Boolean);
const ALLOWED_ENTRY_KEYS = new Set(flattenEntryKeys(DEFAULT_SIDEBAR_CONFIG.entries));
const ALLOWED_ROUTE_KEYS = new Set(flattenRouteKeys(DEFAULT_SIDEBAR_CONFIG.entries)); const flattenRouteKeys = (entries = []) => entries.flatMap((entry) => [
entry.routeKey,
// 激励看板原为「运营工具 → 运营中心B激励看板」,现升级为顶层入口;用于迁移存量侧边栏配置 ...flattenRouteKeys(entry.children || []),
const OPS_B_INCENTIVE_LEGACY_LABEL = '运营中心B激励看板'; ]).filter(Boolean);
const OPS_B_INCENTIVE_LEGACY_ORDER = 6;
const PROMOTED_TOP_LEVEL_ENTRY_KEYS = new Set(['ops-b-incentive']); const ALLOWED_ENTRY_KEYS = new Set(flattenEntryKeys(DEFAULT_SIDEBAR_CONFIG.entries));
// 把存量配置里仍嵌在分组下的已升级条目摘出来,提升为顶层配置参与合并 const ALLOWED_ROUTE_KEYS = new Set(flattenRouteKeys(DEFAULT_SIDEBAR_CONFIG.entries));
const extractPromotedTopLevelEntries = (entries = []) => {
const promoted = []; // 激励看板原为「运营工具 → 运营中心B激励看板」,现升级为顶层入口;用于迁移存量侧边栏配置
const nextEntries = entries.map((entry) => { const OPS_B_INCENTIVE_LEGACY_LABEL = '运营中心B激励看板';
if (!Array.isArray(entry?.children)) return entry; const OPS_B_INCENTIVE_LEGACY_ORDER = 6;
const children = []; const PROMOTED_TOP_LEVEL_ENTRY_KEYS = new Set(['ops-b-incentive']);
entry.children.forEach((child) => { // 把存量配置里仍嵌在分组下的已升级条目摘出来,提升为顶层配置参与合并
if (child?.key && PROMOTED_TOP_LEVEL_ENTRY_KEYS.has(child.key)) { const extractPromotedTopLevelEntries = (entries = []) => {
promoted.push(child); const promoted = [];
} else { const nextEntries = entries.map((entry) => {
children.push(child); if (!Array.isArray(entry?.children)) return entry;
} const children = [];
}); entry.children.forEach((child) => {
return children.length === entry.children.length ? entry : { ...entry, children }; if (child?.key && PROMOTED_TOP_LEVEL_ENTRY_KEYS.has(child.key)) {
}); promoted.push(child);
return { nextEntries, promoted }; } else {
}; children.push(child);
}
const mergeSidebarEntries = (defaultEntries = [], configuredEntries = []) => { });
const defaultByKey = new Map(defaultEntries.map((entry) => [entry?.key, entry]).filter(([key]) => key)); return children.length === entry.children.length ? entry : { ...entry, children };
const configuredKeys = new Set(); });
return { nextEntries, promoted };
const mergeEntry = (defaultEntry = {}, configuredEntry = {}) => { };
const merged = { ...defaultEntry, ...configuredEntry };
if (defaultEntry.type) { const mergeSidebarEntries = (defaultEntries = [], configuredEntries = []) => {
merged.type = defaultEntry.type; const defaultByKey = new Map(defaultEntries.map((entry) => [entry?.key, entry]).filter(([key]) => key));
} const configuredKeys = new Set();
if (defaultEntry.routeKey) {
merged.routeKey = defaultEntry.routeKey; const mergeEntry = (defaultEntry = {}, configuredEntry = {}) => {
} const merged = { ...defaultEntry, ...configuredEntry };
if (typeof defaultEntry.requiresAdmin !== 'undefined') { if (defaultEntry.type) {
merged.requiresAdmin = defaultEntry.requiresAdmin; merged.type = defaultEntry.type;
} }
if ( if (defaultEntry.routeKey) {
defaultEntry.key === 'ops-b-incentive' merged.routeKey = defaultEntry.routeKey;
&& (!configuredEntry.label || configuredEntry.label === OPS_B_INCENTIVE_LEGACY_LABEL) }
) { if (typeof defaultEntry.requiresAdmin !== 'undefined') {
merged.label = defaultEntry.label; merged.requiresAdmin = defaultEntry.requiresAdmin;
} }
if ( if (
defaultEntry.key === 'ops-b-incentive' defaultEntry.key === 'ops-b-incentive'
&& (configuredEntry.order == null || configuredEntry.order === OPS_B_INCENTIVE_LEGACY_ORDER) && (!configuredEntry.label || configuredEntry.label === OPS_B_INCENTIVE_LEGACY_LABEL)
) { ) {
merged.order = defaultEntry.order; merged.label = defaultEntry.label;
} }
const hasDefaultChildren = Array.isArray(defaultEntry.children); if (
const hasConfiguredChildren = Array.isArray(configuredEntry.children); defaultEntry.key === 'ops-b-incentive'
&& (configuredEntry.order == null || configuredEntry.order === OPS_B_INCENTIVE_LEGACY_ORDER)
if (hasDefaultChildren || hasConfiguredChildren) { ) {
if (hasDefaultChildren) { merged.order = defaultEntry.order;
merged.type = defaultEntry.type; }
} else if (defaultEntry.routeKey) { const hasDefaultChildren = Array.isArray(defaultEntry.children);
merged.type = defaultEntry.type || 'item'; const hasConfiguredChildren = Array.isArray(configuredEntry.children);
delete merged.children;
delete merged.defaultExpanded; if (hasDefaultChildren || hasConfiguredChildren) {
return merged; if (hasDefaultChildren) {
} merged.type = defaultEntry.type;
merged.children = mergeSidebarEntries(defaultEntry.children || [], configuredEntry.children || []); } else if (defaultEntry.routeKey) {
} merged.type = defaultEntry.type || 'item';
delete merged.children;
return merged; delete merged.defaultExpanded;
}; return merged;
}
const configuredMerged = configuredEntries.map((entry) => { merged.children = mergeSidebarEntries(defaultEntry.children || [], configuredEntry.children || []);
if (entry?.key) { }
configuredKeys.add(entry.key);
} return merged;
};
const defaultEntry = defaultByKey.get(entry?.key);
return defaultEntry ? mergeEntry(defaultEntry, entry) : entry; const configuredMerged = configuredEntries.map((entry) => {
}); if (entry?.key) {
configuredKeys.add(entry.key);
const missingDefaults = defaultEntries }
.filter((entry) => entry?.key && !configuredKeys.has(entry.key))
.map((entry) => mergeEntry(entry, {})); const defaultEntry = defaultByKey.get(entry?.key);
return defaultEntry ? mergeEntry(defaultEntry, entry) : entry;
return [...configuredMerged, ...missingDefaults]; });
};
const missingDefaults = defaultEntries
const mergeSidebarConfigWithDefaults = (config) => { .filter((entry) => entry?.key && !configuredKeys.has(entry.key))
const defaults = cloneDefaultConfig(); .map((entry) => mergeEntry(entry, {}));
const nestedEntries = (config?.entries || []);
const { nextEntries, promoted } = extractPromotedTopLevelEntries(nestedEntries); return [...configuredMerged, ...missingDefaults];
const topLevelKeys = new Set(nextEntries.map((entry) => entry?.key).filter(Boolean)); };
const promotedNotDuplicated = promoted.some((entry) => topLevelKeys.has(entry.key)) ? [] : promoted;
const mergeSidebarConfigWithDefaults = (config) => {
return { const defaults = cloneDefaultConfig();
...defaults, const nestedEntries = (config?.entries || []);
...config, const { nextEntries, promoted } = extractPromotedTopLevelEntries(nestedEntries);
entries: mergeSidebarEntries(defaults.entries, [...nextEntries, ...promotedNotDuplicated]), const topLevelKeys = new Set(nextEntries.map((entry) => entry?.key).filter(Boolean));
}; const promotedNotDuplicated = promoted.some((entry) => topLevelKeys.has(entry.key)) ? [] : promoted;
};
return {
const pruneSidebarEntry = (entry) => { ...defaults,
if (!entry || !ALLOWED_ENTRY_KEYS.has(entry.key)) { ...config,
return null; entries: mergeSidebarEntries(defaults.entries, [...nextEntries, ...promotedNotDuplicated]),
} };
};
const children = Array.isArray(entry.children)
? entry.children.map(pruneSidebarEntry).filter(Boolean) const pruneSidebarEntry = (entry) => {
: undefined; if (!entry || !ALLOWED_ENTRY_KEYS.has(entry.key)) {
const hasAllowedRoute = entry.routeKey ? ALLOWED_ROUTE_KEYS.has(entry.routeKey) : false; return null;
const hasAllowedChildren = Array.isArray(children) && children.length > 0; }
const keepEntry = hasAllowedRoute || hasAllowedChildren;
const children = Array.isArray(entry.children)
if (!keepEntry) { ? entry.children.map(pruneSidebarEntry).filter(Boolean)
return null; : undefined;
} const hasAllowedRoute = entry.routeKey ? ALLOWED_ROUTE_KEYS.has(entry.routeKey) : false;
const hasAllowedChildren = Array.isArray(children) && children.length > 0;
return { const keepEntry = hasAllowedRoute || hasAllowedChildren;
...entry,
...(Array.isArray(entry.children) ? { children } : {}), if (!keepEntry) {
}; return null;
}; }
const removeRetiredEntries = (config) => ({ return {
...config, ...entry,
entries: (config.entries || []).map(pruneSidebarEntry).filter(Boolean), ...(Array.isArray(entry.children) ? { children } : {}),
}); };
};
export const parseSidebarConfig = (value) => {
if (!value) return cloneDefaultConfig(); const removeRetiredEntries = (config) => ({
...config,
try { entries: (config.entries || []).map(pruneSidebarEntry).filter(Boolean),
const parsed = typeof value === 'string' ? JSON.parse(value) : value; });
if (!parsed || !Array.isArray(parsed.entries)) return cloneDefaultConfig();
return removeRetiredEntries(mergeSidebarConfigWithDefaults(parsed)); export const parseSidebarConfig = (value) => {
} catch { if (!value) return cloneDefaultConfig();
return cloneDefaultConfig();
} try {
}; const parsed = typeof value === 'string' ? JSON.parse(value) : value;
if (!parsed || !Array.isArray(parsed.entries)) return cloneDefaultConfig();
export const sortSidebarEntries = (entries = []) => ( return removeRetiredEntries(mergeSidebarConfigWithDefaults(parsed));
[...entries] } catch {
.filter((entry) => entry?.visible !== false) return cloneDefaultConfig();
.sort((a, b) => Number(a.order || 0) - Number(b.order || 0)) }
); };
export const sortSidebarEntries = (entries = []) => (
[...entries]
.filter((entry) => entry?.visible !== false)
.sort((a, b) => Number(a.order || 0) - Number(b.order || 0))
);