From cb22990844ccef72fd59dd0fe1d80e223bc63111 Mon Sep 17 00:00:00 2001 From: zpc Date: Wed, 4 Feb 2026 22:12:49 +0800 Subject: [PATCH] 21 --- .../Controllers/DanyeController.cs | 20 +++++++++++++ .../Services/DanyeService.cs | 23 +++++++++++++++ .../Services/Interfaces/IDanyeService.cs | 7 +++++ .../admin-web/src/api/business/danye.ts | 12 ++++++++ .../business/danye/components/DanyeTable.vue | 10 ++++++- .../src/views/business/danye/list.vue | 28 +++++++++++++++++++ 6 files changed, 99 insertions(+), 1 deletion(-) diff --git a/server/HoneyBox/src/HoneyBox.Admin.Business/Controllers/DanyeController.cs b/server/HoneyBox/src/HoneyBox.Admin.Business/Controllers/DanyeController.cs index a7645b61..24b5ae5e 100644 --- a/server/HoneyBox/src/HoneyBox.Admin.Business/Controllers/DanyeController.cs +++ b/server/HoneyBox/src/HoneyBox.Admin.Business/Controllers/DanyeController.cs @@ -123,4 +123,24 @@ public class DanyeController : BusinessControllerBase return Error(ex.Code, ex.Message); } } + + /// + /// 删除单页 + /// + /// 单页ID + /// 操作结果 + [HttpDelete("{id}")] + [BusinessPermission("danye:delete")] + public async Task DeleteDanye(int id) + { + try + { + var result = await _danyeService.DeleteDanyeAsync(id); + return result ? Ok("删除成功") : Error(BusinessErrorCodes.InternalError, "删除失败"); + } + catch (BusinessException ex) + { + return Error(ex.Code, ex.Message); + } + } } diff --git a/server/HoneyBox/src/HoneyBox.Admin.Business/Services/DanyeService.cs b/server/HoneyBox/src/HoneyBox.Admin.Business/Services/DanyeService.cs index 9cc7a6d0..63e94830 100644 --- a/server/HoneyBox/src/HoneyBox.Admin.Business/Services/DanyeService.cs +++ b/server/HoneyBox/src/HoneyBox.Admin.Business/Services/DanyeService.cs @@ -147,6 +147,29 @@ public class DanyeService : IDanyeService return result; } + /// + public async Task DeleteDanyeAsync(int id) + { + var danye = await _dbContext.Danyes.FirstOrDefaultAsync(d => d.Id == id); + if (danye == null) + { + throw new BusinessException(BusinessErrorCodes.NotFound, "单页不存在"); + } + + // 系统预设单页(ID 2-20)不允许删除 + if (IsTitleProtected(id)) + { + throw new BusinessException(BusinessErrorCodes.ValidationFailed, "系统预设单页不允许删除"); + } + + _dbContext.Danyes.Remove(danye); + var result = await _dbContext.SaveChangesAsync() > 0; + + _logger.LogInformation("删除单页: Id={Id}, Title={Title}", id, danye.Title); + + return result; + } + #region Private Helper Methods /// diff --git a/server/HoneyBox/src/HoneyBox.Admin.Business/Services/Interfaces/IDanyeService.cs b/server/HoneyBox/src/HoneyBox.Admin.Business/Services/Interfaces/IDanyeService.cs index a5c037b4..2c61bbdf 100644 --- a/server/HoneyBox/src/HoneyBox.Admin.Business/Services/Interfaces/IDanyeService.cs +++ b/server/HoneyBox/src/HoneyBox.Admin.Business/Services/Interfaces/IDanyeService.cs @@ -42,4 +42,11 @@ public interface IDanyeService /// 单页ID /// 是否成功 Task ClearContentAsync(int id); + + /// + /// 删除单页 + /// + /// 单页ID + /// 是否成功 + Task DeleteDanyeAsync(int id); } diff --git a/server/HoneyBox/src/HoneyBox.Admin/admin-web/src/api/business/danye.ts b/server/HoneyBox/src/HoneyBox.Admin/admin-web/src/api/business/danye.ts index 239008a5..bd2ec985 100644 --- a/server/HoneyBox/src/HoneyBox.Admin/admin-web/src/api/business/danye.ts +++ b/server/HoneyBox/src/HoneyBox.Admin/admin-web/src/api/business/danye.ts @@ -110,3 +110,15 @@ export function clearDanyeContent(id: number): Promise> { method: 'put' }) } + +/** + * 删除单页 + * @param id 单页ID + * @returns 操作结果 + */ +export function deleteDanye(id: number): Promise> { + return request({ + url: `${DANYE_BASE_URL}/${id}`, + method: 'delete' + }) +} diff --git a/server/HoneyBox/src/HoneyBox.Admin/admin-web/src/views/business/danye/components/DanyeTable.vue b/server/HoneyBox/src/HoneyBox.Admin/admin-web/src/views/business/danye/components/DanyeTable.vue index 66604ea5..22410e74 100644 --- a/server/HoneyBox/src/HoneyBox.Admin/admin-web/src/views/business/danye/components/DanyeTable.vue +++ b/server/HoneyBox/src/HoneyBox.Admin/admin-web/src/views/business/danye/components/DanyeTable.vue @@ -27,7 +27,7 @@ - + @@ -55,6 +58,7 @@ const emit = defineEmits<{ (e: 'edit', row: DanyeResponse): void (e: 'toggle-optimizer', row: DanyeResponse, value: boolean): void (e: 'clear', row: DanyeResponse): void + (e: 'delete', row: DanyeResponse): void }>() const handleEdit = (row: DanyeResponse) => { @@ -68,6 +72,10 @@ const handleToggleOptimizer = (row: DanyeResponse, value: boolean) => { const handleClear = (row: DanyeResponse) => { emit('clear', row) } + +const handleDelete = (row: DanyeResponse) => { + emit('delete', row) +}