From 8d2df44d99fa929ee83ea5990cd35f4831358cb1 Mon Sep 17 00:00:00 2001 From: codex Date: Sat, 31 Oct 2026 05:51:42 +0800 Subject: [PATCH] refactor(admin): replace object storage native confirms --- web/public/cloud/admin-object-storage.css | 84 +++++++++++++ web/public/cloud/admin-object-storage.js | 114 ++++++++++++++---- .../views/venix/admin/object_storage.tpl | 12 ++ .../CloudObjectStorageAdminContractTest.php | 4 + web/tests/CloudObjectStorageViewTest.php | 3 + 5 files changed, 191 insertions(+), 26 deletions(-) diff --git a/web/public/cloud/admin-object-storage.css b/web/public/cloud/admin-object-storage.css index af00ca3f..6de6b64a 100644 --- a/web/public/cloud/admin-object-storage.css +++ b/web/public/cloud/admin-object-storage.css @@ -762,6 +762,82 @@ body.os-drawer-open { overflow: hidden; } +.os-confirm-layer { + position: fixed; + z-index: 1090; + inset: 0; + display: grid; + place-items: center; + padding: 20px; +} + +.os-confirm-layer[hidden] { + display: none; +} + +.os-confirm-backdrop { + position: absolute; + inset: 0; + width: 100%; + border: 0; + background: rgba(15, 32, 49, 0.56); + backdrop-filter: blur(2px); +} + +.os-confirm-dialog { + position: relative; + display: grid; + grid-template-columns: auto minmax(0, 1fr); + gap: 15px; + width: min(470px, 100%); + padding: 24px; + border-radius: 16px; + background: #fff; + box-shadow: 0 28px 80px rgba(15, 32, 49, 0.28); +} + +.os-confirm-icon { + display: inline-flex; + align-items: center; + justify-content: center; + width: 42px; + height: 42px; + border-radius: 12px; + color: #c13d3d; + background: #fff0f0; + font-size: 23px; +} + +.os-confirm-dialog.is-primary .os-confirm-icon { + color: #0b858d; + background: #e9f8f8; +} + +.os-confirm-copy h2 { + margin: 1px 0 7px; + color: #1d344b; + font-size: 19px; +} + +.os-confirm-copy p { + margin: 0; + color: #6f8398; + font-size: 13px; + line-height: 1.65; +} + +.os-confirm-actions { + display: flex; + grid-column: 1 / -1; + justify-content: flex-end; + gap: 9px; + padding-top: 4px; +} + +body.os-dialog-open { + overflow: hidden; +} + @media (max-width: 1100px) { .os-summary, .os-connection-details { @@ -993,6 +1069,14 @@ body.os-drawer-open { flex: 1 1 0; } + .os-confirm-dialog { + padding: 20px; + } + + .os-confirm-actions .btn { + flex: 1 1 0; + } + .os-cleanup-legend { display: grid; } diff --git a/web/public/cloud/admin-object-storage.js b/web/public/cloud/admin-object-storage.js index 0ced82c5..79c6e8a1 100644 --- a/web/public/cloud/admin-object-storage.js +++ b/web/public/cloud/admin-object-storage.js @@ -33,7 +33,54 @@ node.className = 'os-notice is-show ' + (ok ? 'is-ok' : 'is-error'); } - function initializeConfiguration() { + function initializeConfirmation() { + var layer = document.getElementById('osConfirmDialog'); + if (!layer) return null; + var dialog = layer.querySelector('[role="alertdialog"]'); + var title = document.getElementById('osConfirmTitle'); + var message = document.getElementById('osConfirmMessage'); + var submit = document.getElementById('osConfirmSubmit'); + var cancelButtons = layer.querySelectorAll('[data-os-confirm-cancel]'); + var pending = null; + var previousFocus = null; + + function close(result) { + if (!pending) return; + var resolve = pending; + pending = null; + layer.hidden = true; + document.body.classList.remove('os-dialog-open'); + if (previousFocus && typeof previousFocus.focus === 'function') { + previousFocus.focus({ preventScroll: true }); + } + previousFocus = null; + resolve(result); + } + + cancelButtons.forEach(function (button) { + button.addEventListener('click', function () { close(false); }); + }); + submit.addEventListener('click', function () { close(true); }); + document.addEventListener('keydown', function (event) { + if (event.key === 'Escape' && !layer.hidden) close(false); + }); + + return function confirmAction(options) { + if (pending) return Promise.resolve(false); + title.textContent = options.title; + message.textContent = options.message; + submit.textContent = options.confirmLabel; + submit.className = options.tone === 'primary' ? 'btn btn-primary' : 'btn btn-danger'; + dialog.classList.toggle('is-primary', options.tone === 'primary'); + previousFocus = document.activeElement; + layer.hidden = false; + document.body.classList.add('os-dialog-open'); + submit.focus({ preventScroll: true }); + return new Promise(function (resolve) { pending = resolve; }); + }; + } + + function initializeConfiguration(confirmAction) { var form = document.getElementById('objectStorageForm'); if (!form) return; var notice = document.getElementById('osNotice'); @@ -101,16 +148,23 @@ }); disableButton.addEventListener('click', function () { - if (!canManage || disableButton.disabled) return; - if (!window.confirm('确认停用对象存储?已保存的加密凭据不会被删除。')) return; - setBusy(true); - showNotice(notice, '正在停用对象存储...', true); - request('/admin/object-storage/disable', { expected_revision: revision() }).then(function (result) { - showNotice(notice, result.msg, true); - window.setTimeout(function () { window.location.reload(); }, 650); - }).catch(function (error) { - showNotice(notice, error.message, false); - setBusy(false); + if (!canManage || disableButton.disabled || !confirmAction) return; + confirmAction({ + title: '停用对象存储', + message: '停用后云备份不会再使用当前连接;已加密保存的访问凭据不会被删除。', + confirmLabel: '确认停用', + tone: 'danger', + }).then(function (confirmed) { + if (!confirmed) return; + setBusy(true); + showNotice(notice, '正在停用对象存储...', true); + request('/admin/object-storage/disable', { expected_revision: revision() }).then(function (result) { + showNotice(notice, result.msg, true); + window.setTimeout(function () { window.location.reload(); }, 650); + }).catch(function (error) { + showNotice(notice, error.message, false); + setBusy(false); + }); }); }); } @@ -187,7 +241,7 @@ + ' ' + units[index]; } - function initializeCleanupDebt() { + function initializeCleanupDebt(confirmAction) { document.querySelectorAll('.os-byte-value').forEach(function (node) { node.textContent = formatBytes(node.getAttribute('data-bytes')); }); @@ -199,18 +253,25 @@ document.querySelectorAll('.os-cleanup-retry').forEach(function (button) { button.addEventListener('click', function () { var backupId = String(button.getAttribute('data-backup-id') || ''); - if (!/^\d+$/.test(backupId) || button.disabled) return; - if (!window.confirm('确认重新开启该对象的受控清理周期?系统仍会先完成稳定 HEAD 核对。')) return; - button.disabled = true; - showNotice(notice, '正在核对准确对象版本...', true); - request('/admin/object-storage/cleanup-debts/' + encodeURIComponent(backupId) + '/retry', {}) - .then(function (result) { - showNotice(notice, result.msg, true); - window.setTimeout(function () { window.location.reload(); }, 700); - }).catch(function (error) { - showNotice(notice, error.message || '请求失败', false); - button.disabled = false; - }); + if (!/^\d+$/.test(backupId) || button.disabled || !confirmAction) return; + confirmAction({ + title: '重新开启清理核对', + message: '系统会先检查准确对象身份并等待第二次稳定证据;此操作不会直接重放原删除请求。', + confirmLabel: '开始核对', + tone: 'primary', + }).then(function (confirmed) { + if (!confirmed) return; + button.disabled = true; + showNotice(notice, '正在核对准确对象版本...', true); + request('/admin/object-storage/cleanup-debts/' + encodeURIComponent(backupId) + '/retry', {}) + .then(function (result) { + showNotice(notice, result.msg, true); + window.setTimeout(function () { window.location.reload(); }, 700); + }).catch(function (error) { + showNotice(notice, error.message || '请求失败', false); + button.disabled = false; + }); + }); }); }); } @@ -249,10 +310,11 @@ } function initialize() { + var confirmAction = initializeConfirmation(); initializeTabs(); initializeConfigurationDrawer(); - initializeConfiguration(); - initializeCleanupDebt(); + initializeConfiguration(confirmAction); + initializeCleanupDebt(confirmAction); } initialize(); diff --git a/web/resources/views/venix/admin/object_storage.tpl b/web/resources/views/venix/admin/object_storage.tpl index 4ff5a9c2..d6a97b1c 100644 --- a/web/resources/views/venix/admin/object_storage.tpl +++ b/web/resources/views/venix/admin/object_storage.tpl @@ -241,5 +241,17 @@ {/if} + + {include file='admin/static_footer.tpl'} diff --git a/web/tests/CloudObjectStorageAdminContractTest.php b/web/tests/CloudObjectStorageAdminContractTest.php index c103026d..e677144d 100644 --- a/web/tests/CloudObjectStorageAdminContractTest.php +++ b/web/tests/CloudObjectStorageAdminContractTest.php @@ -79,6 +79,8 @@ $assert(str_contains($template, "admin_title value='对象存储'") && str_contains($template, '$item.next_check_at') && str_contains($template, '$item.attention_at') && !str_contains($template, '') + && str_contains($template, 'id="osConfirmDialog"') + && str_contains($template, 'role="alertdialog"') && str_contains($template, '/cloud/admin-object-storage.css?v={$venix_asset_version}') && str_contains($template, '/cloud/admin-object-storage.js?v={$venix_asset_version}') && !str_contains($template, '