# 前端布局修复与全量渲染审查 实施计划 ## 调研结论(已用浏览器实测确认) ### 问题 1:顶部菜单重复(已证实) - 管理员端与玩家端页面 `document.querySelectorAll('header').length === 2`,两个 header 中的桌面导航均 `display:flex` 可见。 - 根因:[app.js](file:///d:/GameParlor/src/main/resources/static/app.js) 的 `initLayout()` 先异步请求 `/api/user/me`,返回后才把 header 插入 DOM、并把 body 全部子节点移动进新建的 `
`。此时 Alpine.js 已启动,DOM 重排触发其 MutationObserver 对组件重新求值,`x-init="init()"` 二次执行 → `initLayout()` 二次注入 header;旧 header 在第二次包裹时被移入 `
`,最终两个 header 都渲染在页面上。 - 连带影响:init 中的数据加载、轮询(dashboard 的 setInterval)也会执行两次。 ### 问题 2:弹窗部分超出浏览器视口(已证实) - 实测:管理员设备弹窗底部越界 48.46px、玩家选时长弹窗底部越界 93.05px;`.modal-mask` 的 `offsetParent` 是 `
` 而非视口,虽然计算样式 `position:fixed`。 - 根因:`.page-fade` 的 `fadeIn` 动画 `animation-fill-mode: both` 结束后仍保留关键帧 `transform: translateY(0)`;非 none 的 transform 使 `
` 成为 fixed 后代的包含块。`.modal-mask{inset:0}` 因此相对 main(top=56.8px 起、高度超过视口)定位并居中,而不是相对视口。 ### 问题 3:全量审查发现的其它渲染缺陷 1. [player/dashboard.html](file:///d:/GameParlor/src/main/resources/static/player/dashboard.html):`x-text="active.gameName || ..."` 在 `active=null` 时仍求值(x-show 不阻止求值),控制台报 `Cannot read properties of null (reading 'gameName')`。 2. [player/combos.html](file:///d:/GameParlor/src/main/resources/static/player/combos.html):`x-for="it in detail.items"` 初始 `detail=null` 直接报错;`detail.combo.*` 多处无空值保护。 3. [player/custom-combo.html](file:///d:/GameParlor/src/main/resources/static/player/custom-combo.html#L80) 与 [player/points.html](file:///d:/GameParlor/src/main/resources/static/player/points.html#L37):玩家越权调用 `GET /api/admin/config`,拦截器返回 403 并弹出错误 toast(目前靠 catch 兜底值工作,但每次进页面弹错)。 4. `[x-cloak]{display:none!important}` 靠 9 个页面各自内联 `` 的页面:删除内联样式(已全局化)。 ## 实施步骤 1. **app.css** - `fadeIn` 关键帧改为仅 `opacity`(0→1),彻底不产生 transform 包含块;保留 0.35s 淡入。 - 新增全局 `[x-cloak]{display:none!important}`。 - 新增 header 组件类:`.gp-header`(sticky、z-50、毛玻璃、底边线)、`.gp-nav` 链接样式与 active 态、`.gp-nav-desktop`(默认隐藏,≥768px 显示为 flex)、`.gp-nav-mobile`(横向滚动,≥768px 隐藏)、`.gp-userbar`。 - `.gp-page`:`max-width:80rem;width:100%;margin-inline:auto;padding:1rem 1rem 2rem`。 - `.modal-mask` 增加 `padding:1rem`;`.modal` 增加 `margin:auto`,保证小屏下弹窗四周留白且内部可滚动。 2. **app.js(关键重构)** - IIFE 加载时(app.js 位于 body 末尾、Alpine defer 启动之前执行,此刻不存在 MutationObserver)若 body 无 `gp-auth` 标记,则**同步**: - 创建 `
`(含 logo、空的桌面 nav 容器、空的移动 nav 容器、空的用户信息容器); - 创建 `
`,把 body 现有子节点(除 header 外;script/style 标签保留原位不动)移入; - header 插在 body 最前、main 紧随其后。 - `initLayout(active)` 改为:幂等保护(`window.__gpLayoutFilled`)→ 请求 `/api/user/me`(401 仍跳登录)→ 仅用 innerHTML 填充两个 nav 容器和用户信息容器,**不再做任何 DOM 移动/包裹**。 - nav 的显隐完全由 app.css 媒体查询控制,不依赖 Tailwind 运行时生成。 3. **index.html**:body class 增加 `gp-auth`,布局脚本对其跳过。 4. **页面空值/数据修复** - player/dashboard.html:`active && active.gameName`、续费按钮在无 active 时禁用;轮询逻辑不变。 - player/combos.html:`x-for="it in (detail && detail.items) || []"`;标题/价格文本全部加 `detail &&` 保护。 - admin/users.html:tbody 增加 colspan=7 的"暂无数据"行。 5. **后端配置接口** - 新增 `ConfigController`:`GET /api/config` 返回 `configService.getAll()`(仅 3 个业务键,无敏感信息);拦截器要求登录但不限制角色。 - custom-combo.html、points.html 两处 `/api/admin/config` 改为 `/api/config`。 6. **清理**:删除 9 个页面末尾的 ``(browse、history、combos 玩家端、admin 端 combos/games/devices/snacks/users/timeslots/recharge)。 ## 依赖与注意事项 - app.js 依赖"body 末尾经典脚本先于 defer 的 Alpine 执行"这一时序:经典脚本在解析阶段执行,defer 脚本在 DOMContentLoaded 前按序执行,时序天然成立,无需调整各页面 script 标签位置。 - 同步包裹时 app.js 之后的内联 `