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 charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>猪场管理系统</title>
|
<title>猪场管理系统</title>
|
||||||
<script type="module" crossorigin src="/assets/index.80d29e01.js"></script>
|
<script type="module" crossorigin src="/assets/index.0581bd6d.js"></script>
|
||||||
<link rel="stylesheet" href="/assets/index.398ac6b2.css">
|
<link rel="stylesheet" href="/assets/index.42c8d2d4.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
@@ -130,12 +130,13 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/v1/feed/plan/delete/${planId}`, {
|
const response = await fetch('/api/v1/feed/plan/delete', {
|
||||||
method: 'DELETE',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer ' + localStorage.getItem('authToken')
|
'Authorization': 'Bearer ' + localStorage.getItem('authToken')
|
||||||
}
|
},
|
||||||
|
body: JSON.stringify({ id: planId })
|
||||||
})
|
})
|
||||||
|
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
@@ -143,13 +144,13 @@ export default {
|
|||||||
if (response.ok && data.code === 0) {
|
if (response.ok && data.code === 0) {
|
||||||
// 删除成功,重新加载列表
|
// 删除成功,重新加载列表
|
||||||
await this.loadPlans()
|
await this.loadPlans()
|
||||||
alert('删除成功')
|
this.$message?.success('删除成功') || alert('删除成功')
|
||||||
} else {
|
} else {
|
||||||
alert('删除失败: ' + data.message)
|
this.$message?.error('删除失败: ' + data.message) || alert('删除失败: ' + data.message)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除饲喂计划失败:', 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 删除饲料计划
|
// Delete 删除饲料计划
|
||||||
func (c *Controller) Delete(ctx *gin.Context) {
|
func (c *Controller) Delete(ctx *gin.Context) {
|
||||||
// 获取路径参数中的计划ID
|
// 获取路径参数中的计划ID
|
||||||
planIDStr := ctx.Param("id")
|
var req struct {
|
||||||
planID, err := strconv.ParseUint(planIDStr, 10, 32)
|
ID uint `json:"id" binding:"required"`
|
||||||
if err != nil {
|
}
|
||||||
controller.SendErrorResponse(ctx, controller.InvalidParameterCode, "无效的计划ID")
|
|
||||||
|
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||||
|
controller.SendErrorResponse(ctx, controller.InvalidParameterCode, "请求参数错误: "+err.Error())
|
||||||
return
|
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())
|
c.logger.Error("删除计划失败: " + err.Error())
|
||||||
controller.SendErrorResponse(ctx, controller.InternalServerErrorCode, "删除计划失败")
|
controller.SendErrorResponse(ctx, controller.InternalServerErrorCode, "删除计划失败")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user