fix(gallery): 缩略图按异步处理(thumb 返回 Promise,之前当字符串 ⇒ 全部显示图片已丢失)v1.0.1

This commit is contained in:
qiqi committed 2026-11-20 11:46:42 +08:00
1 parent 21b1c70acb
commit fa13eb5997
2 files changed
+13 -10

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/gallery",
"private": true,
"version": "1.0.0",
"version": "1.0.1",
"description": "图库:右栏图片墙(筛选/多选/预览/插入画布/下载/删除),数据由宿主 gallery 能力提供",
"ibwPlugin": {
"id": "gallery",
+12 -9
View File
@@ -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 },