feat(platform-web): link summary kpis to vehicle filters

This commit is contained in:
lingniu
2026-07-04 03:32:51 +08:00
parent 948dc774d0
commit a2ccc4a498
7 changed files with 141 additions and 18 deletions

View File

@@ -6,7 +6,20 @@ describe('parseAppHash', () => {
expect(parseAppHash('#/detail?keyword=%E7%B2%A4AG18312&protocol=JT808')).toEqual({
page: 'detail',
keyword: '粤AG18312',
protocol: 'JT808'
protocol: 'JT808',
filters: {}
});
});
test('parses vehicle list filters from hash query', () => {
expect(parseAppHash('#/vehicles?coverage=multi&serviceStatus=degraded&online=online&bindingStatus=bound')).toEqual({
page: 'vehicles',
filters: {
coverage: 'multi',
serviceStatus: 'degraded',
online: 'online',
bindingStatus: 'bound'
}
});
});
@@ -20,6 +33,10 @@ describe('buildAppHash', () => {
expect(buildAppHash({ page: 'history', keyword: '粤AG18312', protocol: 'GB32960' })).toBe('#/history?keyword=%E7%B2%A4AG18312&protocol=GB32960');
});
test('builds shareable vehicle list hash with filters', () => {
expect(buildAppHash({ page: 'vehicles', filters: { coverage: 'multi', serviceStatus: 'degraded' } })).toBe('#/vehicles?coverage=multi&serviceStatus=degraded');
});
test('builds page-only hash when keyword is empty', () => {
expect(buildAppHash({ page: 'quality', keyword: '' })).toBe('#/quality');
});

View File

@@ -6,8 +6,11 @@ export type AppRoute = {
page?: PageKey;
keyword?: string;
protocol?: string;
filters?: Record<string, string>;
};
const filterKeys = ['coverage', 'serviceStatus', 'online', 'bindingStatus'] as const;
export function parseAppHash(hash: string): AppRoute {
const normalized = hash.trim().replace(/^#\/?/, '');
if (!normalized) {
@@ -20,7 +23,14 @@ export function parseAppHash(hash: string): AppRoute {
const params = new URLSearchParams(queryPart);
const keyword = params.get('keyword')?.trim() || undefined;
const protocol = params.get('protocol')?.trim() || undefined;
return { page: pagePart as PageKey, keyword, protocol };
const filters: Record<string, string> = {};
for (const key of filterKeys) {
const value = params.get(key)?.trim();
if (value) {
filters[key] = value;
}
}
return { page: pagePart as PageKey, keyword, protocol, filters };
}
export function buildAppHash(route: AppRoute): string {
@@ -34,6 +44,12 @@ export function buildAppHash(route: AppRoute): string {
if (protocol) {
params.set('protocol', protocol);
}
for (const key of filterKeys) {
const value = route.filters?.[key]?.trim();
if (value) {
params.set(key, value);
}
}
const query = params.toString();
return query ? `#/${page}?${query}` : `#/${page}`;
}