From dc4c1f7877cf27e17f1fd59927e8636ff4aad27f Mon Sep 17 00:00:00 2001 From: RockYang Date: Fri, 10 May 2024 17:38:55 +0800 Subject: [PATCH] fix bug: remove chat role failed --- api/handler/admin/chat_role_handler.go | 13 ++++--------- api/main.go | 2 +- web/src/views/admin/ChatModel.vue | 4 ++-- web/src/views/admin/Menu.vue | 3 ++- web/src/views/admin/Product.vue | 3 ++- web/src/views/admin/Roles.vue | 3 ++- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/api/handler/admin/chat_role_handler.go b/api/handler/admin/chat_role_handler.go index 9ca2d3df..791104a7 100644 --- a/api/handler/admin/chat_role_handler.go +++ b/api/handler/admin/chat_role_handler.go @@ -144,18 +144,13 @@ func (h *ChatRoleHandler) Set(c *gin.Context) { } func (h *ChatRoleHandler) Remove(c *gin.Context) { - var data struct { - Id uint - } - if err := c.ShouldBindJSON(&data); err != nil { + id := h.GetInt(c, "id", 0) + + if id <= 0 { resp.ERROR(c, types.InvalidArgs) return } - if data.Id <= 0 { - resp.ERROR(c, types.InvalidArgs) - return - } - res := h.DB.Where("id = ?", data.Id).Delete(&model.ChatRole{}) + res := h.DB.Where("id", id).Delete(&model.ChatRole{}) if res.Error != nil { resp.ERROR(c, "删除失败!") return diff --git a/api/main.go b/api/main.go index 12a3192c..ef46926f 100644 --- a/api/main.go +++ b/api/main.go @@ -335,7 +335,7 @@ func main() { group.POST("save", h.Save) group.POST("sort", h.Sort) group.POST("set", h.Set) - group.POST("remove", h.Remove) + group.GET("remove", h.Remove) }), fx.Invoke(func(s *core.AppServer, h *admin.RewardHandler) { group := s.Engine.Group("/api/admin/reward/") diff --git a/web/src/views/admin/ChatModel.vue b/web/src/views/admin/ChatModel.vue index a82b6534..182dd2f7 100644 --- a/web/src/views/admin/ChatModel.vue +++ b/web/src/views/admin/ChatModel.vue @@ -268,8 +268,8 @@ onMounted(() => { const sorts = [] sortedData.forEach((id, index) => { ids.push(parseInt(id)) - sorts.push(index) - items.value[index].sort_num = index + sorts.push(index + 1) + items.value[index].sort_num = index + 1 }) httpPost("/api/admin/model/sort", {ids: ids, sorts: sorts}).then(() => { diff --git a/web/src/views/admin/Menu.vue b/web/src/views/admin/Menu.vue index 66123e1d..a1878097 100644 --- a/web/src/views/admin/Menu.vue +++ b/web/src/views/admin/Menu.vue @@ -138,7 +138,8 @@ onMounted(() => { const sorts = [] sortedData.forEach((id, index) => { ids.push(parseInt(id)) - sorts.push(index) + sorts.push(index + 1) + items.value[index].sort_num = index + 1 }) httpPost("/api/admin/menu/sort", {ids: ids, sorts: sorts}).catch(e => { diff --git a/web/src/views/admin/Product.vue b/web/src/views/admin/Product.vue index c05adaf2..966b6b1c 100644 --- a/web/src/views/admin/Product.vue +++ b/web/src/views/admin/Product.vue @@ -142,7 +142,8 @@ onMounted(() => { const sorts = [] sortedData.forEach((id, index) => { ids.push(parseInt(id)) - sorts.push(index) + sorts.push(index + 1) + items.value[index].sort_num = index + 1 }) httpPost("/api/admin/product/sort", {ids: ids, sorts: sorts}).catch(e => { diff --git a/web/src/views/admin/Roles.vue b/web/src/views/admin/Roles.vue index b8b6cc3a..b32de7c7 100644 --- a/web/src/views/admin/Roles.vue +++ b/web/src/views/admin/Roles.vue @@ -228,7 +228,8 @@ const fetchData = () => { const sorts = [] sortedData.forEach((id, index) => { ids.push(parseInt(id)) - sorts.push(index) + sorts.push(index+1) + items.value[index].sort_num = index + 1 }) httpPost("/api/admin/role/sort", {ids: ids, sorts: sorts}).catch(e => {