From bb8a4ea38600879c0d5cd2a35a76ca5ab73a112b Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Wed, 18 Feb 2026 22:48:31 +0800 Subject: [PATCH] fix(frontend): replace share delete confirm with in-app modal --- frontend/app.html | 27 ++++++++++++-- frontend/app.js | 90 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 110 insertions(+), 7 deletions(-) diff --git a/frontend/app.html b/frontend/app.html index 6e8c273..9c7064f 100644 --- a/frontend/app.html +++ b/frontend/app.html @@ -2364,6 +2364,27 @@ + + + @@ -3154,7 +3175,7 @@ - diff --git a/frontend/app.js b/frontend/app.js index 974cbfc..8485056 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -94,6 +94,14 @@ createApp({ shares: [], directLinks: [], directLinksLoading: false, + showDeleteConfirmModal: false, + deleteConfirm: { + type: '', // share | direct_link + id: null, + title: '', + message: '', + loading: false + }, showShareFileModal: false, creatingShare: false, // 创建分享中状态 shareFileForm: { @@ -2965,9 +2973,29 @@ handleDragLeave(e) { } }, - async deleteDirectLink(id) { - if (!window.confirm('确定要删除这个直链吗?')) return; + requestDeleteDirectLink(id, event = null) { + if (event) { + event.preventDefault(); + event.stopPropagation(); + } + const linkId = parseInt(id, 10); + if (!Number.isFinite(linkId) || linkId <= 0) { + this.showToast('warning', '提示', '无效的直链ID'); + return; + } + + this.deleteConfirm = { + type: 'direct_link', + id: linkId, + title: '删除直链', + message: '确定要删除这个直链吗?删除后将无法继续访问。', + loading: false + }; + this.showDeleteConfirmModal = true; + }, + + async deleteDirectLink(id) { try { const response = await axios.delete(`${this.apiBase}/api/direct-link/${id}`); if (response.data?.success) { @@ -3000,9 +3028,29 @@ handleDragLeave(e) { } }, - async deleteShare(id) { - if (!window.confirm('确定要删除这个分享吗?')) return; + requestDeleteShare(id, event = null) { + if (event) { + event.preventDefault(); + event.stopPropagation(); + } + const shareId = parseInt(id, 10); + if (!Number.isFinite(shareId) || shareId <= 0) { + this.showToast('warning', '提示', '无效的分享ID'); + return; + } + + this.deleteConfirm = { + type: 'share', + id: shareId, + title: '删除分享', + message: '确定要删除这个分享吗?删除后外链将立即失效。', + loading: false + }; + this.showDeleteConfirmModal = true; + }, + + async deleteShare(id) { try { const response = await axios.delete(`${this.apiBase}/api/share/${id}`); @@ -3016,6 +3064,40 @@ handleDragLeave(e) { } }, + closeDeleteConfirmModal(force = false) { + if (this.deleteConfirm.loading && !force) return; + this.showDeleteConfirmModal = false; + this.deleteConfirm = { + type: '', + id: null, + title: '', + message: '', + loading: false + }; + }, + + async confirmDeleteAction() { + if (this.deleteConfirm.loading) return; + const { type, id } = this.deleteConfirm; + if (!type || !id) { + this.closeDeleteConfirmModal(true); + return; + } + + this.deleteConfirm.loading = true; + try { + if (type === 'share') { + await this.deleteShare(id); + } else if (type === 'direct_link') { + await this.deleteDirectLink(id); + } + this.closeDeleteConfirmModal(true); + } catch (error) { + console.error('执行删除操作失败:', error); + this.deleteConfirm.loading = false; + } + }, + // 格式化到期时间显示 formatExpireTime(expiresAt) { if (!expiresAt) return '永久有效';