feat: about页面添加公司地址跳转功能
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m21s

- 外部链接跳转:点击公司地址时,跳转带外部地图服务商链接
- 智能跳转: 根据用户的连接情况,自动选择google地图或者高德地图
This commit is contained in:
2025-11-18 14:11:43 +08:00
parent fe8a0e7656
commit 67629ed518
5 changed files with 151 additions and 30 deletions

43
app/utils/autoMap.ts Normal file
View File

@ -0,0 +1,43 @@
async function testSpeed(url: string, timeout = 1500) {
const start = performance.now();
try {
await Promise.race([
fetch(url, { method: 'HEAD', mode: 'no-cors' }),
new Promise((_, reject) => setTimeout(() => reject('timeout'), timeout)),
]);
return performance.now() - start;
} catch {
return Infinity; // unreachable or timed out
}
}
async function selectBestMap() {
const testTargets = {
amap: 'https://www.amap.com/favicon.ico',
google: 'https://maps.google.com/favicon.ico',
};
const results: Record<string, number> = {};
for (const key in testTargets) {
results[key] = await testSpeed(testTargets[key]);
}
logger.debug(results);
// 根据延迟排序,选择最稳最快的平台
return Object.entries(results).sort((a, b) => a[1] - b[1])[0][0];
}
export async function getAutoMappedService(): Promise<string> {
const target = {
amap: 'https://surl.amap.com/2dYNorIJ1dgoN',
google: 'https://maps.app.goo.gl/9LqvMwEq7VaRkqnM6',
};
const fastestMap = await selectBestMap();
return target[fastestMap];
}