(message, title = '确认操作')
| 709 | // ============================================ |
| 710 | |
| 711 | function confirm(message, title = '确认操作') { |
| 712 | return new Promise((resolve) => { |
| 713 | const modal = document.createElement('div'); |
| 714 | modal.className = 'modal active'; |
| 715 | modal.innerHTML = ` |
| 716 | <div class="modal-content" style="max-width: 400px;"> |
| 717 | <div class="modal-header"> |
| 718 | <h3>${title}</h3> |
| 719 | </div> |
| 720 | <div class="modal-body"> |
| 721 | <p style="margin-bottom: var(--spacing-lg);">${message}</p> |
| 722 | <div class="form-actions" style="margin-top: 0; padding-top: 0; border-top: none;"> |
| 723 | <button class="btn btn-secondary" id="confirm-cancel">取消</button> |
| 724 | <button class="btn btn-danger" id="confirm-ok">确认</button> |
| 725 | </div> |
| 726 | </div> |
| 727 | </div> |
| 728 | `; |
| 729 | |
| 730 | document.body.appendChild(modal); |
| 731 | |
| 732 | const cancelBtn = modal.querySelector('#confirm-cancel'); |
| 733 | const okBtn = modal.querySelector('#confirm-ok'); |
| 734 | |
| 735 | cancelBtn.onclick = () => { |
| 736 | modal.remove(); |
| 737 | resolve(false); |
| 738 | }; |
| 739 | |
| 740 | okBtn.onclick = () => { |
| 741 | modal.remove(); |
| 742 | resolve(true); |
| 743 | }; |
| 744 | |
| 745 | modal.onclick = (e) => { |
| 746 | if (e.target === modal) { |
| 747 | modal.remove(); |
| 748 | resolve(false); |
| 749 | } |
| 750 | }; |
| 751 | }); |
| 752 | } |
| 753 | |
| 754 | // ============================================ |
| 755 | // 复制到剪贴板 |
no outgoing calls
no test coverage detected