From fa13eb59977265e4a75f2470e11c7f4bba7e1e26 Mon Sep 17 00:00:00 2001 From: qiqi Date: Fri, 20 Nov 2026 11:46:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(gallery):=20=E7=BC=A9=E7=95=A5=E5=9B=BE?= =?UTF-8?q?=E6=8C=89=E5=BC=82=E6=AD=A5=E5=A4=84=E7=90=86=EF=BC=88thumb=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=20Promise=EF=BC=8C=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E5=BD=93=E5=AD=97=E7=AC=A6=E4=B8=B2=20=E2=87=92=20=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=98=BE=E7=A4=BA=E5=9B=BE=E7=89=87=E5=B7=B2=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1=EF=BC=89v1.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gallery/package.json | 2 +- gallery/src/index.js | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/gallery/package.json b/gallery/package.json index a278697..58c9ed1 100644 --- a/gallery/package.json +++ b/gallery/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/gallery", "private": true, - "version": "1.0.0", + "version": "1.0.1", "description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供", "ibwPlugin": { "id": "gallery", diff --git a/gallery/src/index.js b/gallery/src/index.js index cca9c96..ef4f698 100644 --- a/gallery/src/index.js +++ b/gallery/src/index.js @@ -141,10 +141,15 @@ function itemNode (it) { var on = !!picked[it.name] var box = el('div', { class: 'iwb-history-item' + (count() ? ' iwb-history-managed' : '') + (on ? ' iwb-history-selected' : '') }) - var url = '' - try { url = ctx.gallery.thumb(it.name) } catch (e) { url = '' } - if (url && typeof url.then === 'function') url = '' - if (url) { + // 缩略图是**异步**的(ctx.gallery.thumb 返回 Promise):先占位,拿到地址再挂 img + var holder = el('div', { class: 'iwb-history-missing', text: '加载中…' }) + box.appendChild(holder) + Promise.resolve(ctx.gallery.thumb(it.name)).then(function (url) { + if (!url || typeof url !== 'string') { + holder.textContent = '图片已丢失' + return + } + if (!box.isConnected) return var img = el('img', { src: url, loading: 'lazy', title: it.name + '(单击单选 · Shift+单击多选 · 双击放大 · 拖到画布=参考图节点)', draggable: 'true' }) if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h) img.addEventListener('click', function (e) { pick(it.name, !!(e && e.shiftKey)) }) @@ -156,10 +161,8 @@ e.dataTransfer.effectAllowed = 'copy' } catch (err) { /* ignore */ } }) - box.appendChild(img) - } else { - box.appendChild(el('div', { class: 'iwb-history-missing', text: '图片已丢失' })) - } + box.replaceChild(img, holder) + }).catch(function () { holder.textContent = '图片已丢失' }) var acts = el('div', { class: 'iwb-history-actions' }) function act (label, title, fn) { var b = el('button', { class: 'iwb-btn iwb-btn-sm', text: label, title: title }) @@ -217,7 +220,7 @@ global.IWBPluginHost.register({ id: 'gallery', name: '图库', - version: '1.0.0', + version: '1.0.1', apiVersion: 1, capabilities: ['panels', 'gallery'], data: { schemaVersion: 1, maxBytes: 65536 },