From 3fe027661b6b2fbfbe0814219c68eb1796e333ea Mon Sep 17 00:00:00 2001 From: MichaelWin Date: Mon, 3 Nov 2025 10:39:36 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E5=B0=81?= =?UTF-8?q?=E8=A3=85=E6=8F=90=E7=A4=BA=E6=A8=A1=E6=80=81=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/assets/js/confirmModal.js | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/resources/static/assets/js/confirmModal.js diff --git a/src/main/resources/static/assets/js/confirmModal.js b/src/main/resources/static/assets/js/confirmModal.js new file mode 100644 index 0000000..3c75514 --- /dev/null +++ b/src/main/resources/static/assets/js/confirmModal.js @@ -0,0 +1,55 @@ +// assets/js/confirmModal.js +(function(window) { + // 全局确认弹窗函数 + window.showConfirmModal = function(options = {}) { + // 默认配置 + const { + title = '系统提示', + content = '确定执行此操作吗?', + onConfirm = () => {}, // 确认回调 + onCancel = () => {} // 取消回调(可选) + } = options; + + // 生成唯一ID(避免重复) + const modalId = `confirm-modal-${Date.now()}`; + + // 动态创建模态框DOM + const modalHtml = ` + + `; + + // 插入到页面 + document.body.insertAdjacentHTML('beforeend', modalHtml); + + // 初始化并显示弹窗 + const modal = new bootstrap.Modal(document.getElementById(modalId)); + modal.show(); + + // 绑定确认按钮事件 + document.getElementById(`${modalId}-confirm`).addEventListener('click', () => { + onConfirm(); // 执行确认逻辑 + modal.hide(); + }); + + // 弹窗关闭后清理DOM + const modalElement = document.getElementById(modalId); + modalElement.addEventListener('hidden.bs.modal', () => { + onCancel(); // 执行取消逻辑(可选) + modalElement.remove(); // 移除DOM,避免冗余 + }); + }; +})(window); \ No newline at end of file