From 37c63e1abd71b83868a0d8f69f870c8128236ecd Mon Sep 17 00:00:00 2001 From: pengyuthon Date: Tue, 31 Mar 2026 21:13:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=BA=A2=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/src/js/status_bar_buttons.js | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/k_ry_mobile_form/static/src/js/status_bar_buttons.js b/k_ry_mobile_form/static/src/js/status_bar_buttons.js index 5652016c0..adcccea99 100644 --- a/k_ry_mobile_form/static/src/js/status_bar_buttons.js +++ b/k_ry_mobile_form/static/src/js/status_bar_buttons.js @@ -51,6 +51,11 @@ function forceMobileBarVisible(container) { container.style.setProperty('pointer-events', 'auto', 'important'); } +function shouldUseMobileBar() { + if (typeof window === 'undefined') return false; + return window.matchMedia('(max-width: 767.98px)').matches; +} + function applyWorkflowButtonPaint(button) { for (const [cls, bg, fg] of WORKFLOW_BUTTON_STYLES) { if (button.classList.contains(cls)) { @@ -104,10 +109,18 @@ patch(StatusBarButtons, { try { const mobileContainers = document.querySelectorAll('.o_statusbar_buttons_mobile_fixed'); if (mobileContainers.length === 0) return; + const useMobileBar = shouldUseMobileBar(); mobileContainers.forEach(container => { try { - forceMobileBarVisible(container); + if (useMobileBar) { + forceMobileBarVisible(container); + } else { + container.style.setProperty('display', 'none', 'important'); + container.style.setProperty('visibility', 'hidden', 'important'); + container.style.setProperty('opacity', '0', 'important'); + return; + } // 同时修复容器内的按钮 const buttons = container.querySelectorAll('button, a.btn, .btn, a[role="button"], .o_statusbar_buttons > * > button, .o_statusbar_buttons > * > a'); @@ -178,7 +191,11 @@ patch(StatusBarButtons, { try { const desktopButtons = document.querySelectorAll('.o_form_statusbar > .o_statusbar_buttons:not(.o_statusbar_buttons_mobile_fixed .o_statusbar_buttons)'); desktopButtons.forEach(btn => { - btn.style.setProperty('display', 'none', 'important'); + if (useMobileBar) { + btn.style.setProperty('display', 'none', 'important'); + } else { + btn.style.removeProperty('display'); + } }); } catch (e) { console.warn('Error hiding desktop buttons in setup:', e); @@ -232,8 +249,14 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') { containers.forEach(container => { try { - // 无条件强制底栏可见,避免主题在特定机型上把栏绘制成透明 - forceMobileBarVisible(container); + if (shouldUseMobileBar()) { + forceMobileBarVisible(container); + } else { + container.style.setProperty('display', 'none', 'important'); + container.style.setProperty('visibility', 'hidden', 'important'); + container.style.setProperty('opacity', '0', 'important'); + return; + } // 修复按钮的交互性和可见性 const buttons = container.querySelectorAll('button, a.btn, .btn, a[role="button"], .o_statusbar_buttons > * > button, .o_statusbar_buttons > * > a'); @@ -306,7 +329,7 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') { }); // 在移动设备上,确保原始状态栏中的按钮被隐藏 - if (isMobileDevice()) { + if (shouldUseMobileBar()) { try { const desktopButtons = document.querySelectorAll('.o_form_statusbar > .o_statusbar_buttons:not(.o_statusbar_buttons_mobile_fixed .o_statusbar_buttons)'); desktopButtons.forEach(btn => { @@ -386,7 +409,7 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') { }, { passive: true }); // 定期检查按钮是否可见(防止被其他样式覆盖) - if (isMobileDevice()) { + if (shouldUseMobileBar()) { // 延迟启动定时器,避免影响页面加载 setTimeout(() => { checkInterval = setInterval(() => {