修复终版页签切换后导入/编辑按钮无反应
供应商应付工作区用局部替换方式切换页签,被替换进来的页面自己追加在 body_end 的行内脚本不会执行,导入/编辑弹窗因此没有绑定事件(原「供应商应付」下同样使用 行内弹窗的板材扣款页也受影响)。 现在导航完成后补执行一次新出现的行内脚本,并按源码内容去重,避免重复绑定。
This commit is contained in:
parent
0c994d2465
commit
f3ebfb942e
@ -6,6 +6,23 @@
|
||||
if (!initial) return;
|
||||
const cache = new Map();
|
||||
const loaded = new Set([...document.scripts].map(script => script.src));
|
||||
// 局部替换导航只会换掉工作区节点,页面在 body_end 追加的行内脚本不会执行,
|
||||
// 导入/编辑弹窗这类按钮就会“点了没反应”。这里按源码内容去重后补执行一次。
|
||||
const executedInline = new Set(
|
||||
[...document.querySelectorAll('body script:not([src])')].map(script => script.textContent.trim())
|
||||
);
|
||||
const collectInlineScripts = doc => [...doc.querySelectorAll('body script:not([src])')]
|
||||
.map(script => script.textContent.trim())
|
||||
.filter(code => code !== '' && !executedInline.has(code));
|
||||
const runInlineScripts = codes => {
|
||||
for (const code of codes || []) {
|
||||
if (executedInline.has(code)) continue;
|
||||
executedInline.add(code);
|
||||
const script = document.createElement('script');
|
||||
script.textContent = code;
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
};
|
||||
let current = location.href;
|
||||
let pending = false;
|
||||
const heading = document.querySelector('#main-body h1');
|
||||
@ -34,7 +51,12 @@
|
||||
if (!node) throw new Error('页面不可用或登录已过期');
|
||||
scripts = [...doc.querySelectorAll('script[src]')].map(s => s.src)
|
||||
.filter(src => new URL(src).origin === location.origin && new URL(src).pathname.startsWith('/public/js/ecommerce-finance/') && !loaded.has(src));
|
||||
next = {node: document.importNode(node, true), title: doc.title, heading: doc.querySelector('#main-body h1')?.innerHTML || ''};
|
||||
next = {
|
||||
node: document.importNode(node, true),
|
||||
title: doc.title,
|
||||
heading: doc.querySelector('#main-body h1')?.innerHTML || '',
|
||||
inline: collectInlineScripts(doc),
|
||||
};
|
||||
}
|
||||
remember();
|
||||
previous.replaceWith(next.node);
|
||||
@ -48,6 +70,7 @@
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
}
|
||||
runInlineScripts(next.inline);
|
||||
cache.set(href, next);
|
||||
current = href;
|
||||
document.title = next.title;
|
||||
|
||||
@ -38,6 +38,11 @@ class SupplierPayableFinalPagesTest extends FeatureTestCase
|
||||
->assertSeeText('暂无数据,请点击“导入”上传本表数据。')
|
||||
->assertSee('workspace/supplier-payables-final/actions/board-deductions/import', false)
|
||||
->assertSee('workspace/supplier-payables-final/actions/board-deductions/template', false)
|
||||
// 导入/编辑弹窗的行内脚本必须随页面输出,局部替换导航才不会出现“点了没反应”。
|
||||
->assertSee('data-supplier-import-modal', false)
|
||||
->assertSee('data-supplier-import-choose', false)
|
||||
->assertSee('modal.dataset.ready', false)
|
||||
->assertSee('data-supplier-maintenance-modal', false)
|
||||
->assertDontSee('workspace/supplier-payables/actions/board-deductions/import', false);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user