From 82acc3470ffd7a3b1e6ac3351f5d252a7e4bcce3 Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Wed, 31 Dec 2025 21:28:28 +0800 Subject: [PATCH] Ensure menu expanded in screenshots --- docker-compose.yml | 2 +- services/screenshots.py | 51 +++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e2a6e28..0b7653e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -46,7 +46,7 @@ services: - API_DIAGNOSTIC_LOG=0 - API_DIAGNOSTIC_SLOW_MS=0 # wkhtmltoimage 截图配置 - - WKHTMLTOIMAGE_FULL_PAGE=1 + - WKHTMLTOIMAGE_FULL_PAGE=0 # 知识管理平台配置 - ZSGL_LOGIN_URL=https://postoa.aidunsoft.com/admin/login.aspx - ZSGL_INDEX_URL_PATTERN=index.aspx diff --git a/services/screenshots.py b/services/screenshots.py index e9ecf42..8801d98 100644 --- a/services/screenshots.py +++ b/services/screenshots.py @@ -273,37 +273,32 @@ def take_screenshot_for_account( index_url = config.ZSGL_INDEX_URL or f"{base}/admin/index.aspx" run_script = ( "(function(){" - "var f=document.getElementById('mainframe');" "function done(){window.status='ready';}" - "function fit(){" + "function ensureNav(){try{if(typeof loadMenuTree==='function'){loadMenuTree(true);}}catch(e){}}" + "function expandMenu(){" + "try{var body=document.body;if(body&&body.classList.contains('lay-mini')){body.classList.remove('lay-mini');}}catch(e){}" + "try{if(typeof mainPageResize==='function'){mainPageResize();}}catch(e){}" + "try{if(typeof toggleMainMenu==='function' && document.body && document.body.classList.contains('lay-mini')){toggleMainMenu();}}catch(e){}" + "try{var navRight=document.querySelector('.nav-right');if(navRight){navRight.style.display='block';}}catch(e){}" + "try{var mainNav=document.getElementById('main-nav');if(mainNav){mainNav.style.display='block';}}catch(e){}" + "}" + "function navReady(){" + "try{var nav=document.getElementById('sidebar-nav');return nav && nav.querySelectorAll('a').length>0;}catch(e){return false;}" + "}" + "function frameReady(){" + "try{var f=document.getElementById('mainframe');return f && f.contentDocument && f.contentDocument.readyState==='complete';}catch(e){return false;}" + "}" + "function check(){" + "if(navReady() && frameReady()){done();return;}" + "setTimeout(check,300);" + "}" + "var f=document.getElementById('mainframe');" + "ensureNav();" + "expandMenu();" "if(!f){done();return;}" - "try{" - "var doc=f.contentDocument||f.contentWindow.document;" - "if(doc&&doc.body&&doc.documentElement){" - "doc.body.style.height='auto';" - "doc.documentElement.style.height='auto';" - "doc.body.style.overflow='visible';" - "doc.documentElement.style.overflow='visible';" - "var h=Math.max(doc.body.scrollHeight,doc.documentElement.scrollHeight);" - "if(h&&h>0){" - "f.style.height=h+'px';" - "var extra=0;" - "var topBar=document.querySelector('.main-top');" - "if(topBar){extra+=topBar.offsetHeight||0;}" - "var container=document.querySelector('.main-container');" - "if(container){extra+=container.offsetTop||0;}" - "var total=h+extra+20;" - "document.body.style.height=total+'px';" - "document.documentElement.style.height=total+'px';" - "}" - "}" - "}catch(e){}" - "done();" - "}" - "if(!f){fit();return;}" f"f.src='{target_url}';" - "f.onload=function(){setTimeout(fit,500);};" - "setTimeout(fit,4000);" + "f.onload=function(){ensureNav();expandMenu();setTimeout(check,300);};" + "setTimeout(check,5000);" "})();" )