feat(platform): integrate runtime amap vehicle maps
This commit is contained in:
27
vehicle-data-platform/apps/web/src/config/appConfig.test.ts
Normal file
27
vehicle-data-platform/apps/web/src/config/appConfig.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { afterEach, expect, test } from 'vitest';
|
||||
import { getAMapConfig, isAMapConfigured } from './appConfig';
|
||||
|
||||
afterEach(() => {
|
||||
delete window.__LINGNIU_APP_CONFIG__;
|
||||
});
|
||||
|
||||
test('reads AMap runtime config from app config script', () => {
|
||||
window.__LINGNIU_APP_CONFIG__ = {
|
||||
amapWebJsKey: 'runtime-key',
|
||||
amapSecurityJsCode: 'runtime-security',
|
||||
amapSecurityServiceHost: '/_AMapService'
|
||||
};
|
||||
|
||||
expect(getAMapConfig()).toEqual({
|
||||
webJsKey: 'runtime-key',
|
||||
securityJsCode: 'runtime-security',
|
||||
securityServiceHost: '/_AMapService'
|
||||
});
|
||||
expect(isAMapConfigured()).toBe(true);
|
||||
});
|
||||
|
||||
test('treats blank AMap key as not configured', () => {
|
||||
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: ' ' };
|
||||
|
||||
expect(isAMapConfigured()).toBe(false);
|
||||
});
|
||||
18
vehicle-data-platform/apps/web/src/config/appConfig.ts
Normal file
18
vehicle-data-platform/apps/web/src/config/appConfig.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export type AMapRuntimeConfig = {
|
||||
webJsKey: string;
|
||||
securityJsCode: string;
|
||||
securityServiceHost: string;
|
||||
};
|
||||
|
||||
export function getAMapConfig(): AMapRuntimeConfig {
|
||||
const runtime = window.__LINGNIU_APP_CONFIG__ ?? {};
|
||||
return {
|
||||
webJsKey: String(runtime.amapWebJsKey || import.meta.env.VITE_AMAP_WEB_JS_KEY || '').trim(),
|
||||
securityJsCode: String(runtime.amapSecurityJsCode || '').trim(),
|
||||
securityServiceHost: String(runtime.amapSecurityServiceHost || '').trim()
|
||||
};
|
||||
}
|
||||
|
||||
export function isAMapConfigured(config = getAMapConfig()) {
|
||||
return Boolean(config.webJsKey);
|
||||
}
|
||||
Reference in New Issue
Block a user