From 89d8f5ddef791cd5315e646e57f1f418f690fe06 Mon Sep 17 00:00:00 2001 From: qiqi Date: Sat, 28 Nov 2026 01:44:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(gallery):=201.8.2=20=E5=88=97=E5=AE=BD?= =?UTF-8?q?=E6=8C=89=E3=80=8C=E7=9C=9F=E6=AD=A3=E6=BB=9A=E5=8A=A8=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E3=80=8D=E7=9A=84=E5=8F=AF=E7=94=A8=E5=AE=BD=E5=BA=A6?= =?UTF-8?q?=E7=AE=97=EF=BC=8C=E6=9C=80=E5=8F=B3=E4=B8=80=E5=88=97=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E8=A2=AB=E8=A3=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现象:图库 4 列排布时最右一列被窗口裁掉(用户截图)。 原因:renderGrid 用 wrap.clientWidth(面板全宽)当可用宽度,而实际滚动容器右侧还有滚动条与内边距, 列宽按全宽均分后总宽超出可视区,最右一列被裁。 改动(plugins/gallery/main.js): - 新增 usableW():沿 scrollerOf() 找到真正滚动的容器,取其 clientWidth 减去左右 padding 与 4px 余量 - renderGrid / measure 都改用 usableW(),并且每次都采用实测值(不再因为差值 ≤1 而沿旧值) - colW 改为 floor,避免四舍五入后 n 列总宽超出容器 --- plugins/gallery/main.js | 23 +++++++++++++++++++---- plugins/gallery/manifest.json | 4 ++-- plugins/index.json | 6 +++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/plugins/gallery/main.js b/plugins/gallery/main.js index 3832eea..a482123 100644 --- a/plugins/gallery/main.js +++ b/plugins/gallery/main.js @@ -344,14 +344,14 @@ var gap = 6 // 每次重排都重新量一次宽度:面板显隐/停靠栏展开时 gridW 可能是旧值, // 只靠 ResizeObserver 会在「变成 0 再回来」期间漏掉,导致必须拖宽度才出图。 - var liveW = availableW() - if (liveW > 0 && Math.abs(liveW - gridW) > 1) gridW = liveW + var liveW = usableW() + if (liveW > 0) gridW = liveW if (!gridW) gridW = 320 var tileW = Math.max(40, Number(cfg.tile) || 110) var n = Math.max(1, Math.floor((gridW + gap) / (tileW + gap))) // v1.6.6:列宽 = 均分宽度(铺满面板),图幅只决定「列数」—— // 以前 min(图幅, 均分) 会留下右侧空白,看起来像没补齐。 - var colW = Math.max(40, (gridW - gap * (n - 1)) / n) + var colW = Math.max(40, Math.floor((gridW - gap * (n - 1)) / n)) // floor:避免四舍五入后总宽超出容器 var cols = [] var heights = [] for (var c = 0; c < n; c++) { cols.push([]); heights.push(0) } @@ -585,6 +585,21 @@ // 宽度测量:列数只由「面板宽 / 图幅」决定 // v1.6.5:面板刚挂载时 grid 宽度可能是 0,而 grid 宽度又取决于列宽 → RO 不会触发,图库一直空白。 + // v1.8.2:可用宽度按「真正滚动的容器」算,扣掉内边距和滚动条余量。 + // 原来用 wrap.clientWidth(面板全宽),右侧有滚动条/内边距时 4 列总宽会超出,最右一列被裁掉。 + function usableW () { + var sc = scrollerOf() + var w = 0 + if (sc) { + var cs = null + try { cs = global.getComputedStyle ? global.getComputedStyle(sc) : null } catch (e) { cs = null } + var padL = cs ? (parseFloat(cs.paddingLeft) || 0) : 0 + var padR = cs ? (parseFloat(cs.paddingRight) || 0) : 0 + w = sc.clientWidth - padL - padR + } + if (!w || w < 80) w = availableW() + return Math.max(80, Math.floor(w) - 4) + } function availableW () { // v1.6.6:优先量「会随面板拉伸的外层容器」,而不是 grid 自身 // (grid 现在是 flex-start + 内容宽度,面板变宽它不会变宽 → RO 不触发 → 列数永不补齐) @@ -594,7 +609,7 @@ return w || 0 } function measure () { - var w = availableW() + var w = usableW() if (w > 0 && Math.abs(w - gridW) > 1) { gridW = w; renderGrid() } } var ro = typeof ResizeObserver === 'function' ? new ResizeObserver(function () { measure() }) : null diff --git a/plugins/gallery/manifest.json b/plugins/gallery/manifest.json index f68deb4..0ed6dbd 100644 --- a/plugins/gallery/manifest.json +++ b/plugins/gallery/manifest.json @@ -1,7 +1,7 @@ { "id": "gallery", "name": "图库", - "version": "1.8.1", + "version": "1.8.2", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -13,7 +13,7 @@ "图库" ], "files": { - "main.js": "6dd3bf43dce74236d4904c4e33639772ef03bd4cd80d6e5a4532ff7ca7ed085a", + "main.js": "eb178baa9d1c8d3148e93e38513bd35754d720e8af8f02c53c041d7e1322dac3", "styles.css": "14d374b5d0e1461cb1ca2b125865e9c27df7c3bd79c11caa0afc52152c7d0aef" } } diff --git a/plugins/index.json b/plugins/index.json index 156ded9..122dee3 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -33,10 +33,10 @@ "dir": "gallery", "main": "main.js", "style": "styles.css", - "version": "1.8.1", + "version": "1.8.2", "files": { - "manifest.json": "8e1235f0f0d89d81c9aafe8e4eac4a4dc3521c1b583c845b15595ddeecc7c0c2", - "main.js": "6dd3bf43dce74236d4904c4e33639772ef03bd4cd80d6e5a4532ff7ca7ed085a", + "manifest.json": "d54679889ab43e54408f6ff5731a557a9816ad5872ea86a341f98f3dfec30eb3", + "main.js": "eb178baa9d1c8d3148e93e38513bd35754d720e8af8f02c53c041d7e1322dac3", "styles.css": "14d374b5d0e1461cb1ca2b125865e9c27df7c3bd79c11caa0afc52152c7d0aef" } },