1. 实现前端删除饲喂计划
2. 修复后端delete接口bug
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
frontend/dist/index.html
vendored
4
frontend/dist/index.html
vendored
@@ -4,8 +4,8 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>猪场管理系统</title>
|
||||
<script type="module" crossorigin src="/assets/index.80d29e01.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index.398ac6b2.css">
|
||||
<script type="module" crossorigin src="/assets/index.0581bd6d.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index.42c8d2d4.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -130,12 +130,13 @@ export default {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/v1/feed/plan/delete/${planId}`, {
|
||||
method: 'DELETE',
|
||||
const response = await fetch('/api/v1/feed/plan/delete', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + localStorage.getItem('authToken')
|
||||
}
|
||||
},
|
||||
body: JSON.stringify({ id: planId })
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
@@ -143,13 +144,13 @@ export default {
|
||||
if (response.ok && data.code === 0) {
|
||||
// 删除成功,重新加载列表
|
||||
await this.loadPlans()
|
||||
alert('删除成功')
|
||||
this.$message?.success('删除成功') || alert('删除成功')
|
||||
} else {
|
||||
alert('删除失败: ' + data.message)
|
||||
this.$message?.error('删除失败: ' + data.message) || alert('删除失败: ' + data.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('删除饲喂计划失败:', error)
|
||||
alert('删除饲喂计划失败: ' + error.message)
|
||||
this.$message?.error('删除饲喂计划失败: ' + error.message) || alert('删除饲喂计划失败: ' + error.message)
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -126,15 +126,17 @@ func (c *Controller) convertToCreateModel(req *CreateRequest) *model.FeedingPlan
|
||||
// Delete 删除饲料计划
|
||||
func (c *Controller) Delete(ctx *gin.Context) {
|
||||
// 获取路径参数中的计划ID
|
||||
planIDStr := ctx.Param("id")
|
||||
planID, err := strconv.ParseUint(planIDStr, 10, 32)
|
||||
if err != nil {
|
||||
controller.SendErrorResponse(ctx, controller.InvalidParameterCode, "无效的计划ID")
|
||||
var req struct {
|
||||
ID uint `json:"id" binding:"required"`
|
||||
}
|
||||
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
controller.SendErrorResponse(ctx, controller.InvalidParameterCode, "请求参数错误: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 调用仓库删除计划
|
||||
if err := c.feedPlanRepo.DeleteFeedingPlan(uint(planID)); err != nil {
|
||||
if err := c.feedPlanRepo.DeleteFeedingPlan(uint(req.ID)); err != nil {
|
||||
c.logger.Error("删除计划失败: " + err.Error())
|
||||
controller.SendErrorResponse(ctx, controller.InternalServerErrorCode, "删除计划失败")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user