✨ 新增回收站审计与八位取件码
This commit is contained in:
1 parent
c25c495657
commit
4ee06e2d29
15 files changed
+534
-132
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
import gzip
|
||||
import re
|
||||
|
||||
ASSETS_ROOT = Path('/app')
|
||||
|
||||
@@ -39,28 +40,27 @@ def patch_file_manage(path: Path) -> bool:
|
||||
def patch_clipboard(path: Path) -> bool:
|
||||
text = path.read_text(encoding='utf-8')
|
||||
old = text
|
||||
marker = 'const y=async(a,e={})=>{'
|
||||
if marker not in text or 'fcbx-copy-fallback' in text:
|
||||
pattern = re.compile(
|
||||
r'const (?P<name>[A-Za-z_$][\w$]*)=async\(a,e=\{\}\)=>\{.*?\},'
|
||||
r'(?=[A-Za-z_$][\w$]*=async\(a,e=\{\}\)=>\{)',
|
||||
re.S,
|
||||
)
|
||||
match = pattern.search(text)
|
||||
if not match:
|
||||
return False
|
||||
start = text.index(marker)
|
||||
end_marker = '},T=async(a,e={})=>{'
|
||||
end = text.index(end_marker, start) + 1
|
||||
replacement = '''const y=async(a,e={})=>{const{successMsg:t="复制成功",errorMsg:n="复制失败,请手动复制",showMsg:s=!0,notify:c}=e,l=(r,d)=>{s&&c?.(r,d)},q=()=>{try{window.prompt("复制下面内容",a)}catch{}};try{if(navigator.clipboard&&window.isSecureContext)try{await navigator.clipboard.writeText(a);return l(t,"success"),!0}catch{}const r=document.createElement("textarea");r.value=a,r.setAttribute("readonly","");r.className="fcbx-copy-fallback";r.style.cssText="position:fixed;left:0;top:0;width:1px;height:1px;opacity:0;z-index:-1";document.body.appendChild(r);r.focus();r.select();r.setSelectionRange(0,r.value.length);let d=!1;try{d=document.execCommand("copy")}finally{document.body.removeChild(r)}if(d)return l(t,"success"),!0;q();l("已打开手动复制窗口","warning");return!1}catch(r){return console.error("复制失败:",r),q(),l(n,"error"),!1}}'''
|
||||
text = text[:start] + replacement + text[end:]
|
||||
name = match.group('name')
|
||||
replacement = f'''const {name}=async(a,e={{}})=>{{const{{successMsg:t="复制成功",errorMsg:n="复制失败,请手动复制",showMsg:s=!0,notify:c}}=e,l=(r,d)=>{{s&&c?.(r,d)}},q=()=>{{try{{window.prompt("复制下面内容",a)}}catch{{}}}};try{{if(navigator.clipboard&&window.isSecureContext)try{{await navigator.clipboard.writeText(a);return l(t,"success"),!0}}catch{{}}const r=document.createElement("textarea");r.value=a,r.setAttribute("readonly","");r.className="fcbx-copy-fallback";r.style.cssText="position:fixed;left:0;top:0;width:1px;height:1px;opacity:0;z-index:-1";document.body.appendChild(r);r.focus();r.select();r.setSelectionRange(0,r.value.length);let d=!1;try{{d=document.execCommand("copy")}}finally{{document.body.removeChild(r)}}if(d)return l(t,"success"),!0;q();l("已打开手动复制窗口","warning");return!1}}catch(r){{return console.error("复制失败:",r),q(),l(n,"error"),!1}}}}'''
|
||||
text = text[:match.start()] + replacement + text[match.end():]
|
||||
if text != old:
|
||||
rewrite(path, text)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def write_detail_collapse_script(theme_dir: Path) -> bool:
|
||||
assets = theme_dir / 'assets'
|
||||
index = theme_dir / 'index.html'
|
||||
if not assets.exists() or not index.exists():
|
||||
return False
|
||||
js_path = assets / 'fcb-lifecycle-collapse-v3.js'
|
||||
js = r'''(() => {
|
||||
def build_lifecycle_script() -> str:
|
||||
return r'''(() => {
|
||||
const LIFE_RE = /(生命周期|Lifecycle)/i;
|
||||
const RETRIEVAL_RE = /^(第\s*\d+\s*次取件|retrieval\s*#?\d+)/i;
|
||||
const STATE = new WeakMap();
|
||||
const getSection = section => {
|
||||
const title = section.querySelector('h1,h2,h3,h4,h5');
|
||||
@@ -72,70 +72,74 @@ def write_detail_collapse_script(theme_dir: Path) -> bool:
|
||||
const getRows = section => {
|
||||
const ctx = getSection(section);
|
||||
if (!ctx) return [];
|
||||
return [...ctx.box.children].filter(el => el instanceof HTMLElement);
|
||||
return [...ctx.box.querySelectorAll(':scope > .fcb-expand-content')];
|
||||
};
|
||||
const apply = section => {
|
||||
const ctx = getSection(section);
|
||||
if (!ctx) return;
|
||||
const rows = [...ctx.box.children].filter(el => el instanceof HTMLElement);
|
||||
if (rows.length <= 3) return;
|
||||
const rows = getRows(section);
|
||||
const events = rows.filter(row => RETRIEVAL_RE.test((row.querySelector('p')?.textContent || '').trim()));
|
||||
if (events.length <= 3) return;
|
||||
const expanded = STATE.get(section) === true;
|
||||
section.classList.toggle('fcbx-life-expanded', expanded);
|
||||
rows.forEach((row, idx) => {
|
||||
const shouldHide = idx >= 3 && !expanded;
|
||||
row.classList.toggle('fcbx-life-row-extra', idx >= 3);
|
||||
if (shouldHide) {
|
||||
if (row.style.display !== 'none') row.style.setProperty('display', 'none', 'important');
|
||||
} else if (row.style.display) {
|
||||
row.style.removeProperty('display');
|
||||
}
|
||||
events.forEach((row, idx) => {
|
||||
row.classList.add('fcbx-retrieval-event');
|
||||
row.style.display = expanded || idx < 3 ? '' : 'none';
|
||||
});
|
||||
const btn = section.querySelector(':scope > .fcbx-life-toggle') || section.querySelector('.fcbx-life-toggle');
|
||||
if (btn) {
|
||||
btn.textContent = expanded ? '收起生命周期记录' : `展开全部生命周期记录(共 ${rows.length} 条)`;
|
||||
btn.setAttribute('aria-expanded', expanded ? 'true' : 'false');
|
||||
}
|
||||
};
|
||||
const ensureSection = section => {
|
||||
const ctx = getSection(section);
|
||||
if (!ctx) return;
|
||||
const rows = [...ctx.box.children].filter(el => el instanceof HTMLElement);
|
||||
if (rows.length <= 3) return;
|
||||
if (!STATE.has(section)) STATE.set(section, false);
|
||||
let btn = section.querySelector(':scope > .fcbx-life-toggle');
|
||||
if (!btn) {
|
||||
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;cursor:pointer;';
|
||||
btn.onclick = event => {
|
||||
let button = section.querySelector(':scope > .fcbx-retrieval-toggle');
|
||||
if (!button) {
|
||||
button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'fcbx-retrieval-toggle';
|
||||
button.style.cssText = 'display:inline-flex;align-items:center;margin:0 0 12px 44px;padding:8px 12px;border:1px solid rgba(148,163,184,.55);border-radius:10px;background:transparent;cursor:pointer;touch-action:manipulation;';
|
||||
button.onclick = event => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
STATE.set(section, STATE.get(section) !== true);
|
||||
apply(section);
|
||||
};
|
||||
section.appendChild(btn);
|
||||
ctx.box.parentNode.insertBefore(button, ctx.box);
|
||||
}
|
||||
apply(section);
|
||||
button.textContent = expanded ? '收起取件记录' : `展开全部取件记录(共 ${events.length} 次)`;
|
||||
button.setAttribute('aria-expanded', expanded ? 'true' : 'false');
|
||||
};
|
||||
const markRows = root => {
|
||||
const scope = root?.querySelectorAll ? root : document;
|
||||
scope.querySelectorAll('section').forEach(ensureSection);
|
||||
scope.querySelectorAll('section').forEach(section => {
|
||||
const ctx = getSection(section);
|
||||
if (!ctx) return;
|
||||
ctx.box.style.overflow = 'visible';
|
||||
if (ctx.box.parentElement) ctx.box.parentElement.style.overflow = 'visible';
|
||||
getRows(section).forEach(row => {
|
||||
row.style.overflow = 'visible';
|
||||
row.style.position = 'relative';
|
||||
row.style.zIndex = '0';
|
||||
const card = row.lastElementChild;
|
||||
if (card) {
|
||||
card.style.overflow = 'visible';
|
||||
card.style.position = 'relative';
|
||||
}
|
||||
row.onmouseenter = () => { row.style.zIndex = '2'; };
|
||||
row.onmouseleave = () => { row.style.zIndex = '0'; };
|
||||
});
|
||||
apply(section);
|
||||
});
|
||||
};
|
||||
let raf = 0;
|
||||
const schedule = root => { cancelAnimationFrame(raf); raf = requestAnimationFrame(() => markRows(root)); };
|
||||
window.addEventListener('hashchange', () => schedule(document));
|
||||
document.addEventListener('DOMContentLoaded', () => schedule(document));
|
||||
new MutationObserver(records => {
|
||||
for (const rec of records) {
|
||||
if ([...rec.addedNodes].some(n => n.nodeType === 1 && ((n.matches?.('section')) || n.querySelector?.('section')))) {
|
||||
schedule(document);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}).observe(document.body || document.documentElement, { childList: true, subtree: true });
|
||||
new MutationObserver(() => schedule(document)).observe(document.body || document.documentElement, { childList: true, subtree: true });
|
||||
schedule(document);
|
||||
})();'''
|
||||
|
||||
|
||||
def write_detail_collapse_script(theme_dir: Path) -> bool:
|
||||
assets = theme_dir / 'assets'
|
||||
index = theme_dir / 'index.html'
|
||||
if not assets.exists() or not index.exists():
|
||||
return False
|
||||
js_path = assets / 'fcb-lifecycle-collapse-v3.js'
|
||||
js = build_lifecycle_script()
|
||||
rewrite(js_path, js)
|
||||
html = index.read_text(encoding='utf-8')
|
||||
# Remove old detail-collapse injection so browsers cannot keep loading the stale “取件记录” script.
|
||||
@@ -156,16 +160,14 @@ def write_detail_collapse_script(theme_dir: Path) -> bool:
|
||||
|
||||
def main() -> None:
|
||||
changed = []
|
||||
theme = ASSETS_ROOT / 'themes/2026'
|
||||
assets = theme / 'assets'
|
||||
if assets.exists():
|
||||
# 只用独立 DOM 脚本处理生命周期收起,避免再改编译后的 FileManageView,
|
||||
# 否则 Vue 内部状态和外部补丁会互相抢状态,导致展开/收起需要点多次。
|
||||
for path in assets.glob('clipboard-*.js'):
|
||||
if patch_clipboard(path):
|
||||
changed.append(str(path.relative_to(ASSETS_ROOT)))
|
||||
if write_detail_collapse_script(theme):
|
||||
changed.append(str((assets / 'fcb-lifecycle-collapse-v3.js').relative_to(ASSETS_ROOT)))
|
||||
for theme in (ASSETS_ROOT / 'themes/2024', ASSETS_ROOT / 'themes/2026'):
|
||||
assets = theme / 'assets'
|
||||
if assets.exists():
|
||||
for path in assets.glob('clipboard-*.js'):
|
||||
if patch_clipboard(path):
|
||||
changed.append(str(path.relative_to(ASSETS_ROOT)))
|
||||
if write_detail_collapse_script(theme):
|
||||
changed.append(str((assets / 'fcb-lifecycle-collapse-v3.js').relative_to(ASSETS_ROOT)))
|
||||
if not changed:
|
||||
raise SystemExit('admin timeline/clipboard patch markers not found or already patched')
|
||||
print('patched admin assets:', ', '.join(changed))
|
||||
|
||||
Reference in new issue
Block a user