From 930ca2b02a931ea9d0f4fa53a66037812513038a Mon Sep 17 00:00:00 2001 From: qiqi Date: Sat, 21 Nov 2026 23:50:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(gallery):=201.6.9=20=E7=BC=A9=E7=95=A5?= =?UTF-8?q?=E5=9B=BE=20Promise=20=E5=85=B1=E4=BA=AB=20+=20=E5=9D=8F?= =?UTF-8?q?=E5=9B=BE=E5=BF=AB=E9=80=9F=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gallery/src/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gallery/src/index.js b/gallery/src/index.js index a169768..2c22dcc 100644 --- a/gallery/src/index.js +++ b/gallery/src/index.js @@ -340,6 +340,7 @@ box.appendChild(holder) var tries = 0 function fail (text) { + tries = 999 holder.textContent = text || '缩略图加载失败(点击重试)' holder.style.cursor = 'pointer' holder.onclick = function () { failed[it.name] = 1; tries = 0; boot() } @@ -347,6 +348,7 @@ updateFail() } function boot () { + if (tries >= 999) return holder.style.cursor = '' holder.onclick = null holder.textContent = '加载中…' @@ -397,6 +399,15 @@ }) img.style.display = 'none' box.appendChild(img) + // v1.6.9:坏图/超时兜底 —— 某些坏字节既不触发 load 也不触发 error,700ms 后直接判定失败(可点击重试) + setTimeout(function () { + try { + if (!img.parentNode) return + if (img.naturalWidth > 0) return + if (img.parentNode === box) box.replaceChild(holder, img) + fail('缩略图加载失败(点击重试)') + } catch (e) { /* ignore */ } + }, 700) // 加载成功后再替换占位(避免破图标 + 长 title 占满格子) if (img.complete && img.naturalWidth > 0) { img.style.display = ''; if (holder.parentNode === box) box.replaceChild(img, holder) } else if (img.complete && !img.naturalWidth) { /* 立即失败(坏图)*/ tries++; if (tries <= 2) setTimeout(boot, 400 * tries); else { if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)') } }