@wendongfly/myhi 1.3.224 → 1.3.227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/studio.html CHANGED
@@ -120,6 +120,18 @@
120
120
  #hist .h .x { min-width: 0; flex: 1; }
121
121
  #hist .h .x div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
122
122
  #hist .h .x small { color: var(--muted); }
123
+ /* 历史:每条右侧 🗑(悬停显示,触屏常显);「管理」模式多选删除 / 清空 */
124
+ #hist .hsel { display: none; flex-shrink: 0; margin: 0; }
125
+ #hist.man .hsel { display: inline-block; }
126
+ #hist .hdel { flex-shrink: 0; opacity: 0; cursor: pointer; padding: 0.15rem 0.3rem; border-radius: 5px; color: var(--muted); font-size: 0.85rem; }
127
+ #hist .h:hover .hdel { opacity: 1; }
128
+ #hist .hdel:hover { background: var(--bg); color: var(--red); }
129
+ @media (hover: none) { #hist .hdel { opacity: 0.7; } }
130
+ #hist.man .hdel { display: none; }
131
+ #hist-bar { display: none; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin: 0.2rem 0 0.4rem; font-size: 0.75rem; }
132
+ #hist-bar button { background: none; border: 1px solid var(--border); color: var(--text2); border-radius: 6px; padding: 0.2rem 0.55rem; cursor: pointer; font: inherit; }
133
+ #hist-bar button.danger { color: var(--red); border-color: var(--red); }
134
+ #hist-bar button:disabled { opacity: 0.45; cursor: default; }
123
135
  #zoom { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 50; align-items: center; justify-content: center; cursor: zoom-out; }
124
136
  #zoom.on { display: flex; }
125
137
  #zoom img { max-width: 94vw; max-height: 94vh; }
@@ -177,7 +189,7 @@
177
189
  <div class="hint" id="qc-hint"></div>
178
190
  </div>
179
191
  <div class="card">
180
- <div style="display:flex;align-items:center;margin-bottom:0.3rem"><b>历史</b><a style="margin-left:auto;font-size:0.75rem;cursor:pointer" onclick="loadHistory()">刷新</a></div>
192
+ <div style="display:flex;align-items:center;margin-bottom:0.3rem"><b>历史</b><a id="hist-man" style="margin-left:auto;font-size:0.75rem;cursor:pointer" onclick="histManage(!$('hist').classList.contains('man'))">管理</a><a style="margin-left:0.8rem;font-size:0.75rem;cursor:pointer" onclick="loadHistory()">刷新</a></div><div id="hist-bar"><button onclick="histSelAll()">全选</button><button id="hist-delsel" class="danger" onclick="histDelSel()" disabled>删除所选</button><button class="danger" style="margin-left:auto" onclick="histClear()">清空全部</button></div>
181
193
  <div id="hist"><div class="empty" style="padding:1rem">还没有出过图</div></div>
182
194
  </div>
183
195
  </div>
@@ -414,13 +426,78 @@
414
426
  async function loadHistory() {
415
427
  const d = await api('/api/studio/jobs').catch(() => null);
416
428
  const jobs = d?.jobs || [];
417
- $('hist').innerHTML = jobs.length ? jobs.map((j) => `<div class="h" data-id="${esc(j.id)}">${j.thumbs[0] ? `<img src="${imgUrl(j, j.thumbs[0])}" alt="">` : '<img alt="">'}<div class="x"><div>${esc(j.need)}</div><small>${new Date(j.createdAt).toLocaleString()} · ${j.status === 'running' ? '出图中' : j.status === 'cancelled' ? '已取消' : j.thumbs.length + ' 张'}</small></div></div>`).join('')
429
+ $('hist').innerHTML = jobs.length ? jobs.map((j) => `<div class="h" data-id="${esc(j.id)}" data-st="${esc(j.status)}">${j.thumbs[0] ? `<img src="${imgUrl(j, j.thumbs[0])}" alt="">` : '<img alt="">'}<div class="x"><div>${esc(j.need)}</div><small>${new Date(j.createdAt).toLocaleString()} · ${j.status === 'running' ? '出图中' : j.status === 'cancelled' ? '已取消' : j.thumbs.length + ' 张'}</small></div></div>`).join('')
418
430
  : '<div class="empty" style="padding:1rem">还没有出过图</div>';
419
431
  $('hist').querySelectorAll('.h').forEach((h) => h.onclick = async () => {
420
432
  const r = await api('/api/studio/jobs/' + encodeURIComponent(h.dataset.id)).catch(() => null);
421
433
  if (r?.ok) { showJob(r.job); if (innerWidth <= 860) $('result').scrollIntoView({ behavior: 'smooth' }); }
422
434
  });
423
435
  if (CUR) document.querySelectorAll('#hist .h').forEach((h) => h.classList.toggle('on', h.dataset.id === CUR.id));
436
+ histDecorate();
437
+ }
438
+ // ── 删除历史:单条 🗑 / 管理模式多选 / 清空(成员只删自己的,管理员能删全部;进行中的不删)──
439
+ const RESULT0 = $('result').innerHTML; // 删掉当前打开的那条后,右侧回到初始说明
440
+ let HMAN = false;
441
+ const HBUSY = ["running"];
442
+ const histSelIds = () => [...$('hist').querySelectorAll('.hsel:checked')].map((c) => c.closest('.h').dataset.id);
443
+ function histUpdSel() {
444
+ const n = histSelIds().length, b = $('hist-delsel');
445
+ b.textContent = n ? '删除所选(' + n + ')' : '删除所选'; b.disabled = !n;
446
+ }
447
+ function histAfterDelete(ids) {
448
+ if (CUR && ids.includes(CUR.id)) { clearTimeout(POLL); CUR = null; $('result').innerHTML = RESULT0; }
449
+ loadHistory();
450
+ }
451
+ async function histPost(body) {
452
+ const d = await api('/api/studio/jobs/delete', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }).catch((e) => ({ ok: false, error: e.message }));
453
+ if (!d.ok) { alert('删除失败:' + (d.error || '未知错误')); return null; }
454
+ if (d.busy) alert('已删除 ' + d.deleted + ' 条;还有 ' + d.busy + ' 条正在进行,没有删除(先取消再删)');
455
+ return d;
456
+ }
457
+ window.histDelOne = async (ev, id) => {
458
+ ev.stopPropagation();
459
+ if (!confirm('删除这条出图?图片文件会一起删掉(已保存到项目里的不受影响),不可恢复。')) return;
460
+ const d = await api('/api/studio/jobs/' + encodeURIComponent(id), { method: 'DELETE' }).catch((e) => ({ ok: false, error: e.message }));
461
+ if (!d.ok) return alert('删除失败:' + (d.error || '未知错误'));
462
+ histAfterDelete([id]);
463
+ };
464
+ window.histManage = (on) => {
465
+ HMAN = on;
466
+ $('hist').classList.toggle('man', on);
467
+ $('hist-bar').style.display = on ? 'flex' : 'none';
468
+ $('hist-man').textContent = on ? '完成' : '管理';
469
+ if (!on) $('hist').querySelectorAll('.hsel').forEach((c) => { c.checked = false; });
470
+ histUpdSel();
471
+ };
472
+ window.histSelAll = () => {
473
+ const cs = [...$('hist').querySelectorAll('.hsel:not(:disabled)')];
474
+ const all = cs.length && cs.every((c) => c.checked);
475
+ cs.forEach((c) => { c.checked = !all; });
476
+ histUpdSel();
477
+ };
478
+ window.histDelSel = async () => {
479
+ const ids = histSelIds();
480
+ if (!ids.length || !confirm('删除选中的 ' + ids.length + ' 条出图?图片文件会一起删掉(已保存到项目里的不受影响),不可恢复。')) return;
481
+ if (await histPost({ ids })) histAfterDelete(ids);
482
+ };
483
+ window.histClear = async () => {
484
+ if (!confirm('清空全部出图历史?图片文件会一起删掉(已保存到项目里的不受影响),不可恢复。\n(管理员会清掉所有成员的;正在进行的不删)')) return;
485
+ const d = await histPost({ all: true });
486
+ if (d) { histManage(false); histAfterDelete(CUR && !HBUSY.includes(CUR.status) ? [CUR.id] : []); }
487
+ };
488
+ // 每次重画列表后:给每行补上勾选框和 🗑,管理模式下点整行 = 勾选
489
+ function histDecorate() {
490
+ $('hist').querySelectorAll('.h').forEach((h) => {
491
+ const busy = HBUSY.includes(h.dataset.st);
492
+ const c = document.createElement('input'); c.type = 'checkbox'; c.className = 'hsel'; c.disabled = busy;
493
+ c.title = busy ? '正在进行,不能删除' : '选择';
494
+ c.onclick = (e) => e.stopPropagation(); c.onchange = histUpdSel;
495
+ h.prepend(c);
496
+ if (!busy) { const d = document.createElement('span'); d.className = 'hdel'; d.textContent = '🗑'; d.title = '删除'; d.onclick = (e) => histDelOne(e, h.dataset.id); h.append(d); }
497
+ const open = h.onclick;
498
+ h.onclick = (e) => { if (HMAN) { if (!c.disabled) { c.checked = !c.checked; histUpdSel(); } return; } open?.(e); };
499
+ });
500
+ histUpdSel();
424
501
  }
425
502
  loadConfig(); loadHistory();
426
503
  const q = new URLSearchParams(location.search).get('job');
Binary file