28 lines
785 B
JavaScript
28 lines
785 B
JavaScript
|
|
// 运维工具后台事件代理,替代 Blade 内联确认提交逻辑。
|
||
|
|
|
||
|
|
let adminOpsControlsBound = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 绑定运维工具确认提交事件。
|
||
|
|
*
|
||
|
|
* @returns {void}
|
||
|
|
*/
|
||
|
|
export function bindAdminOpsControls() {
|
||
|
|
if (adminOpsControlsBound || typeof document === "undefined") {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
adminOpsControlsBound = true;
|
||
|
|
document.addEventListener("submit", (event) => {
|
||
|
|
if (!(event.target instanceof HTMLFormElement)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 运维动作不可撤销,提交前统一读取 Blade 声明的确认文案。
|
||
|
|
const confirmMessage = event.target.getAttribute("data-ops-confirm");
|
||
|
|
if (confirmMessage && !window.confirm(confirmMessage)) {
|
||
|
|
event.preventDefault();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|