Test/custom admin ui #6

Merged
orion merged 2 commits from test/custom-admin-ui into master 2026-07-10 09:18:51 +08:00
Showing only changes of commit ed98cbe826 - Show all commits
+13 -21
View File
@@ -60,10 +60,13 @@ def write_detail_collapse_script(theme_dir: Path) -> bool:
return False
js_path = assets / 'fcb-detail-collapse.js'
js = r'''(() => {
const EVENT_RE = /(第\s*\d+\s*次取件|取件\s*[#]\s*\d+|Retrieval\s*#\s*\d+)/i;
const LIFE_RE = /(生命周期|Lifecycle)/i;
const STATE = new WeakMap();
const getRows = section => [...section.querySelectorAll('div.grid')].filter(row => EVENT_RE.test(row.textContent || ''));
const getRows = section => [...section.querySelectorAll('div.grid')].filter(row => {
if (row.classList.contains('fcbx-life-row-skip')) return false;
const text = row.textContent || '';
return !!row.querySelector('span.rounded-full') && !LIFE_RE.test(text);
});
const apply = section => {
const rows = getRows(section);
if (rows.length <= 3) return;
@@ -71,7 +74,7 @@ def write_detail_collapse_script(theme_dir: Path) -> bool:
rows.forEach((row, idx) => { row.hidden = !expanded && idx >= 3; });
const btn = section.querySelector(':scope > .fcbx-life-toggle') || section.querySelector('.fcbx-life-toggle');
if (btn) {
btn.textContent = expanded ? '收起取件记录' : `展开全部取件记录(共 ${rows.length} `;
btn.textContent = expanded ? '收起生命周期记录' : `展开全部生命周期记录(共 ${rows.length} `;
btn.setAttribute('aria-expanded', expanded ? 'true' : 'false');
}
};
@@ -86,29 +89,18 @@ def write_detail_collapse_script(theme_dir: Path) -> bool:
btn = document.createElement('button');
btn.type = 'button';
btn.className = 'fcbx-life-toggle mt-3 rounded-lg border px-3 py-2 text-sm font-medium transition';
btn.style.cssText = 'border-color:rgba(148,163,184,.55);display:inline-flex;align-items:center;gap:.35rem;touch-action:manipulation;user-select:none;';
btn.style.cssText = 'border-color:rgba(148,163,184,.55);display:inline-flex;align-items:center;gap:.35rem;touch-action:manipulation;user-select:none;cursor:pointer;';
btn.onclick = event => {
event.preventDefault();
event.stopPropagation();
STATE.set(section, STATE.get(section) !== true);
apply(section);
};
section.appendChild(btn);
}
apply(section);
};
const markRows = () => document.querySelectorAll('section').forEach(ensureSection);
const toggle = target => {
const btn = target.closest?.('.fcbx-life-toggle');
if (!btn) return false;
const section = btn.closest('section');
if (!section) return false;
STATE.set(section, STATE.get(section) !== true);
apply(section);
return true;
};
const onToggle = event => {
if (!toggle(event.target)) return;
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation?.();
};
document.addEventListener('pointerdown', onToggle, true);
document.addEventListener('click', onToggle, true);
let raf = 0;
const schedule = () => { cancelAnimationFrame(raf); raf = requestAnimationFrame(markRows); };
window.addEventListener('hashchange', schedule);