fix(queue): 选中态/缩略图复用/提示词标题/画布归属/状态与下载语义

This commit is contained in:
qiqi committed 2026-12-03 10:20:05 +08:00
1 parent 7b2bb0d58e
commit 48232bec5c
9 files changed
+58 -23

No files matched your search

+24 -10
View File
@@ -33,6 +33,12 @@
node.appendChild(typeof v === 'string' ? document.createTextNode(v) : v)
}
function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) }
var SVG_NS = 'http://www.w3.org/2000/svg'
function svgEl (tag, attrs) {
var node = document.createElementNS(SVG_NS, tag)
if (attrs) for (var k in attrs) if (Object.prototype.hasOwnProperty.call(attrs, k)) node.setAttribute(k, attrs[k])
return node
}
function fmtTime (ms) {
var d = new Date(Number(ms) || 0)
if (!isFinite(d.getTime())) return ''
@@ -40,6 +46,13 @@
return p(d.getMonth() + 1) + '-' + p(d.getDate()) + ' ' + p(d.getHours()) + ':' + p(d.getMinutes())
}
function fmtSize (w, h) { return (w > 0 && h > 0) ? (w + '×' + h) : '' }
function titleOf (it) {
var m = it.meta || {}
var base = String(m.promptText || m.prompt || '').trim()
if (!base) return '历史记录 · ' + fmtTime(it.createdAt) + ' · #' + String(it.id || '').slice(-4)
if (m.variant) base += ' · 第 ' + m.variant + ' 张'
return base.length > 28 ? (base.slice(0, 28) + '…') : base
}
function mount (host, ctx) {
clear(host)
@@ -96,17 +109,19 @@
function thumbOf (it) {
if (it.thumbUrl) return el('img', { class: 'iwb-tq-img', src: it.thumbUrl, alt: '', draggable: 'false' })
return el('div', { class: 'iwb-tq-ph' },
el('svg', { viewBox: '0 0 24 24', width: '20', height: '20', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.6', 'aria-hidden': 'true' },
el('path', { d: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4' }),
el('polyline', { points: '7 10 12 15 17 10' }),
el('line', { x1: '12', x2: '12', y1: '15', y2: '3' })),
(function () { var s = svgEl('svg', { viewBox: '0 0 24 24', width: '20', height: '20', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.6', 'aria-hidden': 'true' }); s.appendChild(svgEl('path', { d: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4' })); s.appendChild(svgEl('polyline', { points: '7 10 12 15 17 10' })); s.appendChild(svgEl('line', { x1: '12', x2: '12', y1: '15', y2: '3' })); return s })(),
el('span', { text: it.kind === 'only' ? '仅记录' : '' }))
}
function badgeOf (it) {
var label = STATUS[it.kind] || '记录'
if (it.kind === 'down' && it.progress > 0) label = '下载中 ' + Math.round(it.progress * 100) + '%'
return el('span', { class: 'iwb-tq-badge ' + (it.kind || ''), text: label })
if (it.kind === 'ok') return el('span', { class: 'iwb-tq-badge ' + (it.inGallery ? 'ok' : 'warn'), text: it.inGallery ? '已入图库' : '待入库' })
if (it.kind === 'down') {
var label = it.status === 'queued' ? '排队中' : '下载中'
if (it.status === 'downloading' && it.progress > 0) label += ' ' + Math.round(it.progress * 100) + '%'
return el('span', { class: 'iwb-tq-badge', text: label })
}
if (it.kind === 'fail') return el('span', { class: 'iwb-tq-badge fail', text: '下载失败' })
return el('span', { class: 'iwb-tq-badge warn', text: '未下载' })
}
function btn (label, cls, onClick) {
@@ -119,9 +134,9 @@
var meta = it.meta || {}
var thumb = el('div', { class: 'iwb-tq-thumb', title: '点击预览' }, thumbOf(it))
thumb.addEventListener('click', function () { try { Promise.resolve(ctx.queue.preview(it.id)).catch(function () { setMsg('预览失败') }) } catch (e) { setMsg('预览失败') } })
var line1 = el('div', { class: 'iwb-tq-line1' }, el('span', { class: 'iwb-tq-name', text: String(meta.prompt || '生成结果') }), badgeOf(it))
var line1 = el('div', { class: 'iwb-tq-line1' }, el('span', { class: 'iwb-tq-name', text: titleOf(it), title: String(meta.promptText || meta.prompt || '') }), badgeOf(it))
var bits = []
if (meta.boardName) bits.push(meta.boardName)
bits.push(meta.boardName || '未知画布')
if (it.createdAt) bits.push(fmtTime(it.createdAt))
var sz = fmtSize(it.w, it.h); if (sz) bits.push(sz)
if (meta.model) bits.push(meta.model)
@@ -131,7 +146,6 @@
var acts = el('div', { class: 'iwb-tq-actions' })
if (it.kind === 'ok' && it.inGallery) acts.appendChild(el('button', { class: 'iwb-btn iwb-btn-sm iwb-tq-btn', text: '已在图库', disabled: 'disabled' }))
else if (it.kind === 'down') acts.appendChild(el('button', { class: 'iwb-btn iwb-btn-sm iwb-tq-btn', text: '下载中…', disabled: 'disabled' }))
else if (it.kind === 'fail') acts.appendChild(btn('重试', 'iwb-tq-primary', function () { Promise.resolve(ctx.queue.retry(it.id)).then(function () { setMsg('已重新排队'); schedule() }).catch(function () { setMsg('重试失败') }) }))
else acts.appendChild(btn('下载', 'iwb-tq-primary', function (b) { b.disabled = true; ctx.queue.land(it.id).then(function (r) { b.disabled = false; setMsg(r && r.already ? '已在图库' : (r && r.ok ? '已加入落地队列,图库会自动刷新' : '下载失败')) ; schedule() }).catch(function () { b.disabled = false; setMsg('下载失败') }) }))
acts.appendChild(btn('复制原始链接', '', function () { ctx.queue.copyLink(it.id).then(function (r) { setMsg(r && r.ok ? '链接已复制' : '复制失败') }).catch(function () { setMsg('复制失败') }) }))
var loc = btn('定位', '', function (b) { b.disabled = true; ctx.queue.locate(it.id).then(function (r) { b.disabled = false; setMsg(r && r.ok ? '已定位到节点' : ({ 'board-missing': '画布已删除', 'node-missing': '节点已删除', 'missing-meta': '没有定位信息' }[r && r.error] || '定位失败')) }).catch(function () { b.disabled = false; setMsg('定位失败') }) })