feat(platform): integrate runtime amap vehicle maps

This commit is contained in:
lingniu
2026-07-04 10:52:11 +08:00
parent bb1b2f1c46
commit adb9d146d9
12 changed files with 402 additions and 51 deletions

View 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);
});

View 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);
}