高德 SDK 改为按需加载,只在用地图的页面引入(批 30)

This commit is contained in:
2026-09-29 23:29:43 +08:00
parent 2aaabce8e3
commit 151e854b64
+14
View File
@@ -8,6 +8,18 @@ $__name = (string)($__user['name'] ?? ($_SESSION['user_name'] ?? ''));
// 就会渲染出 <img src=""> —— 一个破图占位。
$__avatar = media_avatar((string)($__user['avatar'] ?? ''));
$__initial = $__name !== '' ? mb_substr($__name, 0, 1) : '·';
/* 高德 JS SDK 按需加载(批 30):
只有「首页地图 / 活动详情路线图 / 节点表单地址联想」这三个页面真正用到 AMap 对象,
其余页面(登录、各类管理、节点详情…)一律不加载 —— 省掉 SDK 的下载与解析,
也避免它的两条控制台噪音(WEBGL_debug_renderer_info 弃用提示、
restapi.amap.com 埋点返回 octet-stream 的 MIME 警告)。
⚠️ 新增用 AMap 的模板,必须把相对路径加进下面这个白名单,否则页面会拿不到 SDK。
路径按 `/templates/<相对路径>.php` 匹配(兼容 Windows 反斜杠)。 */
$__needAmap = (bool)preg_match(
'~/templates/(?:activities/(?:index|show)|nodes/form)\.php$~',
str_replace('\\', '/', (string)($content ?? ''))
);
?>
<!DOCTYPE html>
<html lang="zh-CN">
@@ -26,6 +38,7 @@ $__initial = $__name !== '' ? mb_substr($__name, 0, 1) : '·';
<link rel="stylesheet" href="<?= e(asset('assets/style.css')) ?>">
<link rel="stylesheet" href="<?= e(asset('assets/vendor/cropper/cropper.min.css')) ?>">
<script src="<?= e(asset('assets/vendor/cropper/cropper.min.js')) ?>"></script>
<?php if ($__needAmap): ?>
<script>
window._AMapSecurityConfig = {
securityJsCode: '<?= e(app_config()['amap']['security_js'] ?? '') ?>',
@@ -37,6 +50,7 @@ $__initial = $__name !== '' ? mb_substr($__name, 0, 1) : '·';
onload="window.__AMAP_LOADED = true;"
onerror="window.__AMAP_ERROR = 'script load failed';">
</script>
<?php endif; ?>
</head>
<body>
<?php if ($__isLoggedIn): ?>