Files
image-workbench-desktop/src/ui-components.js
T
qiqi a8c2cd9d97
Verify (Gitea) / gate (build · unit · facts) (push) Canceled after 29s
feat(ingest): 出图结果接落地队列(节点先显示远程,就绪后换本地)
- src/image-ingest-store.js:localStorage 索引(500 条上限、pinned 不淘汰)+ url→状态视图(供组件订阅)
- app.js:装配 ingest(fetchBytes = wBlobFromSrc → dataURL → wImgRefWrite;persist 走 store)
  启动时 restore,出图后立即 enqueue(不等下载完)
- ui-components ResultImg:读视图状态,排队/下载中显示角标并压暗,失败显示「未落地」,
  就绪后 src 换成本地 objectURL(不再直连 CDN)
- style.css:角标样式全部走 token(z-anchor / radius-full / font-xs / err 语义色)
- 棘轮:app.js 8,860→8,891、Workbench 2,454→2,483、global 122→123(均按 B3 记账)

验证:image-ingest 24 条 + writeback 23 条单测、e2e 冒烟 33/33、lint/typecheck/facts/ratchet/token-lint 全绿。
图库侧仍走原缩略图链路,下一步接同一份本地引用。
2026-12-02 12:27:47 +08:00

67 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
;(function (global) {
'use strict'
const React = global.React
if (!React || !React.createElement) return
const el = React.createElement
function ResultImg(props) {
const useState = React.useState
const useEffect = React.useEffect
const [hover, setHover] = useState(false)
const item = props.item || {}
// 落地状态(2026-12-02):出图后队列在后台把远程图下到本地;这里只负责把「下载中 / 失败」
// 画出来,并在就绪后换成本地 objectURL(不再让 <img> 直连 CDN,避免慢慢刷/卡半张)。
const view = global.IWBImageIngestView || null
const [, bump] = useState(0)
useEffect(function () { return view ? view.subscribe(function () { bump(function (n) { return n + 1 }) }) : undefined }, [!!view])
const st = view ? view.get(item.url) : null
const src = (st && st.localUrl) ? st.localUrl : item.url
const pending = !!(st && (st.status === 'queued' || st.status === 'downloading'))
const failed = !!(st && st.status === 'failed')
const doCopyRef = () => { props.onCopyRef && props.onCopyRef(item.url) }
const doCopyLink = () => {
// 统一走 IWBClipboardCopy(2026-11-24)
try { if (global.IWBClipboardCopy) global.IWBClipboardCopy.copyText(item.url) } catch (e) { /* ignore */ }
}
return el('div', {
className: 'iwb-rimg' + (pending ? ' iwb-rimg-pending' : '') + (failed ? ' iwb-rimg-failed' : ''),
onMouseEnter: () => setHover(true),
onMouseLeave: () => setHover(false),
},
// 单击只让节点选中(不弹预览),双击才开大图:与输出节点结果图同一手势。
el('img', { className: props.cls || 'iwb-result-thumb', src: src, alt: 'img', loading: 'lazy', title: '双击放大', onClick: (e) => { try { e.stopPropagation() } catch (err) { /* ignore */ } }, onDoubleClick: (e) => { try { e.stopPropagation() } catch (err) { /* ignore */ } if (props.onPreview) props.onPreview(item.url) } }),
pending ? el('div', { className: 'iwb-rimg-flag' }, st.status === 'queued' ? '排队中' : '下载中') : null,
failed ? el('div', { className: 'iwb-rimg-flag iwb-rimg-flag-err' }, '未落地') : null,
hover ? el('div', { className: 'iwb-rimg-actions' },
el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制为参考图节点', onClick: doCopyRef }, props.copyIcon || '⧉', ' 复制到画布'),
el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制图片链接', onClick: doCopyLink }, '🔗 链接'),
) : null,
)
}
// 共享「下载浮层」:底部渐变 + 下载(可选复制),hover/focus 才出现。
// 图库插件是原生 DOM,用同一组 token 在插件 CSS 里复刻;宿主这里只需一个 React 组件。
// pointer-events:浮层条本身不吃事件(否则会挡住图片点击/双击),只有悬停后按钮才可点。
function ResultDownloadOverlay (props) {
const p = props || {}
const stopDown = (e) => { try { e.stopPropagation() } catch (err) { /* ignore */ } }
return el('div', { className: 'iwb-dl-ov' },
p.children,
el('div', { className: 'iwb-dl-bar' },
p.onCopyRef ? el('button', {
className: 'iwb-dl-btn iwb-dl-btn-ghost',
title: p.copyTitle || '插入为参考图节点',
onPointerDown: stopDown,
onClick: (e) => { e.stopPropagation(); p.onCopyRef() },
}, p.copyIcon || null, el('span', { className: 'iwb-dl-txt' }, p.copyLabel || '复制')) : null,
el('button', {
className: 'iwb-dl-btn',
title: p.downloadTitle || '下载原图',
onPointerDown: stopDown,
onClick: (e) => { e.stopPropagation(); if (p.onDownload) p.onDownload() },
}, p.icon || null, el('span', { className: 'iwb-dl-txt' }, p.label || '下载')),
),
)
}
global.IWBResultImg = ResultImg
global.IWBResultDownloadOverlay = ResultDownloadOverlay
})(typeof window !== 'undefined' ? window : globalThis)