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