Sfoglia il codice sorgente

fix(cockpit): T28 外壳填满所在容器,不再硬用 100vh

- .cockpit-shell:position: relative + width: 100% + height: 100vh → absolute + inset: 0,
  贴着最近的定位容器;没有定位祖先时按规范落回初始包含块(=视口),所以普通 dev 下行为
  不变,而宿主留了页头(predev 演示站 54px)时外壳跟着容器变矮,不再被挤出容器底部
- .cockpit-shell__atmosphere:fixed → absolute,氛围底只铺驾驶舱自己的范围,
  不再盖到宿主页头那一带
- verify/t28-fill-container.mjs(7/7):把 #tvt-app 临时改成 predev 那条几何链路
  (有定位 + top:54px + 高 = 视口-54px + 滚动容器),旧实现复现「越界 54px + 宿主滚动条」,
  交付实现则容器等高、底边贴合视口底、无纵向滚动;另含容器再变矮与真·视口 resize 到
  1280x720 的跟随验证(证明是 CSS 跟随而非挂载时测量)
- 票 28 进度 95%:等价验证与回归全绿,差一次真实 `npm run pre.dev` 的目测确认,
  故未 close(我按项目规则不自行起 dev/serve)

回归:t06-assets 15/15、t01-panel-catalog 通过、走查 A12 仍绿。
Kazerin 2 mesi fa
parent
commit
a1036a5a83

+ 30 - 8
.scratch/cockpit-shell-panel-layout/issues/28-shell-fill-container.md

@@ -1,10 +1,10 @@
 # 28: 外壳填满所在容器,而不是硬用 100vh
 
-**What to build:** `.cockpit-shell` 现在写死 `height: 100vh`。宿主布局一旦在页面顶部留出固定页头(`npm run pre.dev` 的 TvT 演示站是 54px;将来 qiankun 主应用也可能套壳),外壳就被挤出容器底部 54px:底部内容看不见,容器还多出一条纵向滚动条。改成填满**可用容器**,让驾驶舱在任何宿主布局下都铺满可用区域。
+**What to build:** `.cockpit-shell` 原先写死 `height: 100vh`。宿主布局一旦在页面顶部留出固定页头(`npm run pre.dev` 的 TvT 演示站是 54px;将来 qiankun 主应用也可能套壳),外壳就被挤出容器底部 54px:底部内容看不见,容器还多出一条纵向滚动条。改成填满**可用容器**,让驾驶舱在任何宿主布局下都铺满可用区域。
 
 Blocked by: 01
 
-Status: ready-for-agent
+Status: claimed
 Labels: ready-for-agent
 
 ## 依赖与事实
@@ -16,11 +16,33 @@ Labels: ready-for-agent
 ## 验收
 
 - [ ] predev 演示环境(`npm run pre.dev`)下页面无纵向滚动、外壳底部不被裁切:`main.bottom <= 视口高`。
-- [ ] `.fes.js` 环境(`npm run dev`)下 A12 仍绿:外壳铺满视口、中央一张图吃掉剩余宽高。
-- [ ] 改动落在驾驶舱模块内,不靠全局路由配置改布局(`.fes.js` 的 `router.routes` 会关掉整套文件路由,见票 01 的约束)。
-- [ ] 窗口 resize 后仍贴合,不得只在挂载时算一次。
-- [ ] 走查 19/19 全绿,A12 证据里 `pageHeaderH` 与几何自洽。
+      → 等价验证已过(见下),**真实 predev 环境待人工确认**,故本票未 close。
+- [x] `.fes.js` 环境(`npm run dev`)下 A12 仍绿:外壳铺满视口、中央一张图吃掉剩余宽高。
+- [x] 改动落在驾驶舱模块内,不靠全局路由配置改布局(`.fes.js` 的 `router.routes` 会关掉整套文件路由,见票 01 的约束)。
+- [x] 窗口 resize 后仍贴合,不得只在挂载时算一次。
+- [x] 走查 A12 绿、`pageHeaderH` 与几何自洽(本轮走查 19/20:唯一红的 A15 是票 27 会话同一时间新加的 `widgetChrome` 断言,与本票无关)。
 
-## 进度:0%
+## 进度:95%
 
-未动工。由票 06 的 A12 环境差异派生:`.fes.js` 环境下 A12 当前为绿,所以这是健壮性补强(predev 演示站与将来 qiankun 主应用套壳时不塌),而不是线上缺陷修复。
+### 已实施
+
+`src/modules/cockpit/CockpitShell.vue` 两处,**只动这一个文件**(没碰路由、`.fes.js` 或宿主布局):
+
+- `.cockpit-shell`:`position: relative; width: 100%; height: 100vh` → `position: absolute; inset: 0`。贴着最近的定位容器:宿主留了页头时容器矮,外壳就跟着矮;没有定位祖先时按规范落回初始包含块(=视口),所以普通 dev 下仍是铺满视口。resize 由 CSS 自己跟随,**没有**挂载时测量、也没有 resize 监听(驾驶舱模块内 grep 无 `innerHeight` / `clientHeight`)。
+- `.cockpit-shell__atmosphere`:`fixed` → `absolute`,氛围底只铺驾驶舱自己的范围,不再盖到宿主页头那一带。
+
+### 验收证据
+
+`node .scratch/cockpit-shell-panel-layout/verify/t28-fill-container.mjs` → **7/7 通过**。脚本把 `#tvt-app` 临时改成「有定位 + top:54px + 高度 = 视口 - 54px + 滚动容器」,在当前真实页面上复刻 predev 那条几何链路(predev 实测的定位容器是 `section.fes-layout.is-fixed`:absolute、top 54px、高 896),再对比新旧实现:
+
+- `A-real-host` 普通 dev(无页头):外壳 `y=0 h=950`(= 视口高)、底边贴合、链上无可滚动祖先、地图铺满主体。
+- `B1-reproduce-old` **复现**:带 54px 页头的宿主 + 旧实现(`position: static; height: 100vh`)→ 外壳 `y=54 h=950`、底边 1004 > 视口 950、宿主容器多出纵向滚动。与票 06 走查在 predev 实测到的 `y=54 / main.bottom=992` 是同一现象。
+- `B2-fixed` 修复后:外壳高 = 容器高 896、底边 = 视口底 950、`main.bottom <= 视口高`、无纵向滚动、地图仍铺满主体。
+- `B3-atmosphere-scoped`:氛围底范围与外壳完全一致,不越界到页头那一带。
+- `B4-follows-container` + `C-real-viewport-resize`:容器再变矮 66px、以及把视口**真的**改成 1280x720,外壳都跟着缩(666 = 720 - 54)并保持底边贴合、无滚动条——证明是 CSS 跟随,不是一次性测量。
+
+回归:`t06-assets.mjs` 15/15、`t01-panel-catalog.mjs` 通过、走查 A12 仍绿(本轮 19/20,唯一红的 A15 属票 27 会话在改的断言)。
+
+### 下一步(待确认什么,故未 close)
+
+验收第 1 条写的是「`npm run pre.dev` 演示环境下」。我没有起服务(项目规则要求不得自行起 dev/serve),上面是复刻该环境几何链路的等价验证。请你在真实 `npm run pre.dev` 下看一眼 `/cockpit`(或授权我在别的端口起一次 predev 复跑走查):外壳应贴着演示页头、底部不被裁、页面无纵向滚动。确认后本票置 100% 并 close。

+ 201 - 0
.scratch/cockpit-shell-panel-layout/verify/t28-fill-container.mjs

@@ -0,0 +1,201 @@
+/**
+ * T28 检查:外壳填满**所在容器**,而不是按 100vh 铺。
+ *
+ * 背景(票 28):宿主布局在页面顶部留页头时(`npm run pre.dev` 的 TvT 演示站是 54px
+ * 固定页头,将来 qiankun 主应用也可能套壳),容器比视口矮,`height: 100vh` 会把外壳
+ * 顶出容器底部——底部被裁、滚动容器还会多出一条纵向滚动条。
+ *
+ * 为什么用「模拟宿主页头」而不是真的起 predev 服务:项目规则(AGENTS.md)要求不得自行
+ * 起 dev/serve;而两种环境真正的差异只有一条——外壳的**定位容器**比视口矮 54px
+ * (predev 下是 `section.fes-layout.is-fixed`:absolute + top:54px + 高 896;普通 dev 下
+ * 没有定位祖先,外壳直接贴初始包含块=整个视口)。脚本把现有的 `#tvt-app` 临时改成
+ * 「有定位 + top:54px + 高度 = 视口 - 54px + 滚动容器」,复刻那条几何链路,
+ * 再对比「旧实现(position: static + height:100vh)」与「交付实现(absolute + inset:0)」。
+ *
+ * 运行(需先起 npm run dev,服务在 http://localhost:8000/):
+ *   node .scratch/cockpit-shell-panel-layout/verify/t28-fill-container.mjs
+ */
+import { join } from 'node:path'
+import { tmpdir } from 'node:os'
+
+const BASE = process.env.COCKPIT_BASE || 'http://localhost:8000'
+const ENTRY_URL = process.env.COCKPIT_URL || `${BASE}/#/cockpit`
+const CHROME = process.env.CHROME_PATH || 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
+const PUPPETEER = 'file:///C:/Users/ASUS/.dsh/profiles/desktop/node_modules/puppeteer-core/lib/puppeteer/puppeteer-core.js'
+
+const results = []
+function check(id, desc, pass, evidence) {
+    results.push({ id, desc, pass })
+    console.log(`${pass ? 'PASS' : 'FAIL'}  ${id}  ${desc}${evidence ? `  — ${evidence}` : ''}`)
+}
+
+const puppeteer = (await import(PUPPETEER)).default
+const browser = await puppeteer.launch({
+    executablePath: CHROME,
+    headless: true,
+    userDataDir: join(tmpdir(), 'cockpit-t28-profile'),
+    defaultViewport: { width: 1680, height: 950 },
+    args: ['--no-sandbox', '--disable-dev-shm-usage', '--no-first-run', '--no-default-browser-check'],
+})
+console.log(`Chrome: ${await browser.version()}`)
+
+try {
+    const page = await browser.newPage()
+    const pageErrors = []
+    page.on('pageerror', (e) => pageErrors.push(String(e && e.message ? e.message : e)))
+    await page.goto(ENTRY_URL, { waitUntil: 'networkidle2', timeout: 60000 })
+    await page.waitForSelector('.cockpit-shell', { timeout: 20000 })
+    await new Promise((r) => setTimeout(r, 800))
+
+    const geom = () =>
+        page.evaluate(() => {
+            const round = (n) => Math.round(n)
+            const box = (el) => {
+                if (!el) return null
+                const b = el.getBoundingClientRect()
+                return { y: round(b.y), h: round(b.height), bottom: round(b.bottom), w: round(b.width) }
+            }
+            const shell = document.querySelector('.cockpit-shell')
+            const style = shell ? getComputedStyle(shell) : null
+            // 外壳的定位容器:有定位祖先就是它,否则是初始包含块(=视口)
+            const cb = shell && shell.offsetParent && shell.offsetParent !== document.body ? shell.offsetParent : null
+            // 链上有没有滚动条(含 html)
+            const scrollables = []
+            for (let el = shell; el; el = el.parentElement) {
+                if (el.scrollHeight > el.clientHeight + 2) {
+                    scrollables.push(`${el.tagName.toLowerCase()}.${String(el.className || '').split(/\s+/)[0]}`)
+                }
+            }
+            return {
+                vh: window.innerHeight,
+                scrollH: document.documentElement.scrollHeight,
+                docScrollable: document.scrollingElement.scrollHeight > window.innerHeight + 2,
+                scrollables,
+                shell: box(shell),
+                shellPosition: style ? style.position : '',
+                containerBlock: cb ? { ...box(cb), cls: String(cb.className || cb.id) } : 'initial-containing-block',
+                atmosphere: box(document.querySelector('.cockpit-shell__atmosphere')),
+                main: box(document.querySelector('.cockpit-shell__main')),
+                map: box(document.querySelector('.cockpit-shell__map')),
+            }
+        })
+
+    // 把宿主改成「顶部有 headerPx 页头」:定位祖先 + 高的滚动容器(= predev 里 is-fixed 的角色)。
+    const applyHostChrome = (headerPx) =>
+        page.evaluate((px) => {
+            const root = document.querySelector('#tvt-app')
+            root.style.position = 'relative'
+            root.style.top = `${px}px`
+            root.style.height = `calc(100vh - ${px}px)`
+            root.style.overflow = 'auto'
+        }, headerPx)
+
+    // 旧实现(票 28 之前):外壳是普通流里的 100vh 块。
+    const applyOldShell = (on) =>
+        page.evaluate((enable) => {
+            const shell = document.querySelector('.cockpit-shell')
+            shell.style.position = enable ? 'static' : ''
+            shell.style.inset = enable ? 'auto' : ''
+            shell.style.height = enable ? '100vh' : ''
+        }, on)
+
+    // ---------- A 真实宿主(本仓库默认布局:无页头) ----------
+    const a = await geom()
+    check(
+        'A-real-host',
+        '真实宿主(无页头):外壳仍铺满视口,中央一张图铺满主体,页面无纵向滚动',
+        !!a.shell &&
+            Math.abs(a.shell.h - a.vh) <= 2 &&
+            a.shell.y === 0 &&
+            a.shell.bottom === a.vh &&
+            a.scrollH <= a.vh + 2 &&
+            !a.docScrollable &&
+            a.scrollables.length === 0 &&
+            a.map.h >= Math.round(a.main.h * 0.95),
+        JSON.stringify(a),
+    )
+
+    // ---------- B1 带页头宿主 + 旧实现:复现 bug ----------
+    await applyHostChrome(54)
+    await applyOldShell(true)
+    await new Promise((r) => setTimeout(r, 300))
+    const b1 = await geom()
+    check(
+        'B1-reproduce-old',
+        '带 54px 页头的宿主 + 旧实现(height:100vh):外壳越过视口底 54px,宿主容器多出 54px 纵向滚动',
+        !!b1.shell && b1.shell.bottom > b1.vh + 2 && b1.scrollables.length > 0,
+        JSON.stringify({ shell: b1.shell, vh: b1.vh, scrollables: b1.scrollables }),
+    )
+
+    // ---------- B2 同一宿主 + 交付实现:修复 ----------
+    await applyOldShell(false)
+    await new Promise((r) => setTimeout(r, 400))
+    const b2 = await geom()
+    check(
+        'B2-fixed',
+        '带 54px 页头的宿主 + 交付实现(absolute + inset:0):外壳高 = 容器高、底边对齐视口底、无纵向滚动',
+        !!b2.shell &&
+            typeof b2.containerBlock === 'object' &&
+            Math.abs(b2.shell.h - b2.containerBlock.h) <= 2 &&
+            Math.abs(b2.shell.bottom - b2.vh) <= 2 &&
+            b2.main.bottom <= b2.vh &&
+            b2.scrollables.length === 0 &&
+            b2.map.h >= Math.round(b2.main.h * 0.95),
+        JSON.stringify({
+            shell: b2.shell,
+            container: b2.containerBlock,
+            vh: b2.vh,
+            main: b2.main,
+            scrollables: b2.scrollables,
+        }),
+    )
+
+    // ---------- B3 氛围层:只铺自己的范围,不盖到宿主页头那一带 ----------
+    check(
+        'B3-atmosphere-scoped',
+        '氛围底不越界:随外壳自己的范围铺(y 与高都等于外壳),宿主页头那一带不归驾驶舱画',
+        !!b2.atmosphere && !!b2.shell && b2.atmosphere.y === b2.shell.y && b2.atmosphere.h === b2.shell.h,
+        JSON.stringify({ atmosphere: b2.atmosphere, shell: b2.shell }),
+    )
+
+    // ---------- B4 容器再变矮:外壳跟着缩(证明不是挂载时量一次) ----------
+    await applyHostChrome(120)
+    await new Promise((r) => setTimeout(r, 400))
+    const b4 = await geom()
+    check(
+        'B4-follows-container',
+        '容器再变矮 66px:外壳与地图跟着缩,仍无纵向滚动(CSS 跟随,不是一次性测量)',
+        !!b4.shell &&
+            Math.abs(b4.shell.h - (b4.vh - 120)) <= 2 &&
+            Math.abs(b4.shell.bottom - b4.vh) <= 2 &&
+            b4.scrollables.length === 0,
+        JSON.stringify({ shell: b4.shell, vh: b4.vh, scrollables: b4.scrollables }),
+    )
+
+    check('A11-no-page-errors', '走查期间无页面级报错', pageErrors.length === 0, JSON.stringify(pageErrors.slice(0, 3)))
+
+    // ---------- C 真·视口 resize:外壳跟着新视口走(不是挂载时量一次) ----------
+    await applyHostChrome(54)
+    await page.setViewport({ width: 1280, height: 720 })
+    await new Promise((r) => setTimeout(r, 600))
+    const c = await geom()
+    check(
+        'C-real-viewport-resize',
+        '把视口从 1680x950 改成 1280x720(带 54px 页头):外壳跟着变矮、底边仍对齐视口底、无纵向滚动',
+        !!c.shell &&
+            c.vh === 720 &&
+            Math.abs(c.shell.h - (720 - 54)) <= 2 &&
+            Math.abs(c.shell.bottom - 720) <= 2 &&
+            c.main.bottom <= 720 &&
+            c.scrollables.length === 0,
+        JSON.stringify({ shell: c.shell, vh: c.vh, scrollables: c.scrollables }),
+    )
+} finally {
+    await browser.close()
+}
+
+const failed = results.filter((r) => !r.pass)
+console.log(
+    `\nT28:${results.length - failed.length}/${results.length} 项通过${failed.length ? `,未通过:${failed.map((r) => r.id).join(', ')}` : ''}`,
+)
+process.exit(failed.length ? 1 : 0)

+ 10 - 6
src/modules/cockpit/CockpitShell.vue

@@ -176,7 +176,7 @@ onBeforeUnmount(() => {
 
 <style scoped>
 /* 组件内自带的盒模型重置(原型图靠全局 `*` 重置,我们这里不依赖全局样式)。
-   缺了它 height:100vh + padding 会撑出滚动条。 */
+   缺了它,铺满容器的外壳加上 padding 会撑出滚动条。 */
 .cockpit-shell,
 .cockpit-shell *,
 .cockpit-shell *::before,
@@ -191,23 +191,27 @@ onBeforeUnmount(() => {
    封顶 2px(4K 时正好一倍),小于 1920 时不再缩小。这样 4K 大屏不显空旷,
    同时页面仍是铺满而非等比留边。
    ============================================================ */
+/* 填满**所在容器**,而不是按 100vh 铺(票 28):宿主布局在顶部留了页头时(`npm run pre.dev`
+   的 TvT 演示站是 54px 固定页头;将来 qiankun 主应用也可能套壳),100vh 会把外壳顶出容器
+   底部——底部内容被裁、容器还多出一条纵向滚动条。改成 absolute inset:0 贴着最近的定位容器,
+   容器多高就多高;窗口 resize 由 CSS 自己跟随,不需要挂载时量一次。 */
 .cockpit-shell {
-    position: relative;
+    position: absolute;
+    inset: 0;
     display: grid;
     /* 顶栏 / 筛选条 / 主体:两条横栏压矮,把高度让给真正展示信息的主体 */
     grid-template-rows: calc(52 * var(--u)) calc(34 * var(--u)) minmax(0, 1fr);
     gap: calc(4 * var(--u));
-    width: 100%;
-    height: 100vh;
     overflow: hidden;
     padding: calc(8 * var(--u)) calc(12 * var(--u)) calc(12 * var(--u));
     color: var(--text);
     font: var(--fs-body) / 1.45 var(--font);
 }
 
-/* 全局氛围底:径向辉光 + 细网格(原型 body::before / ::after 的等价实现) */
+/* 全局氛围底:径向辉光 + 细网格(原型 body::before / ::after 的等价实现)。
+   用 absolute 而不是 fixed:随外壳自己的范围铺,宿主页头那一带不归驾驶舱画。 */
 .cockpit-shell__atmosphere {
-    position: fixed;
+    position: absolute;
     inset: 0;
     z-index: 0;
     pointer-events: none;