mirror of
https://gitee.com/blackfox/geekai.git
synced 2024-12-03 12:48:31 +08:00
feat: add switch for enable|disable chat role
This commit is contained in:
parent
3c6e86d04b
commit
b1b385c455
@ -98,6 +98,26 @@ func (h *ChatRoleHandler) Sort(c *gin.Context) {
|
|||||||
resp.SUCCESS(c)
|
resp.SUCCESS(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *ChatRoleHandler) Set(c *gin.Context) {
|
||||||
|
var data struct {
|
||||||
|
Id uint `json:"id"`
|
||||||
|
Filed string `json:"filed"`
|
||||||
|
Value interface{} `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.ShouldBindJSON(&data); err != nil {
|
||||||
|
resp.ERROR(c, types.InvalidArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res := h.db.Model(&model.ChatRole{}).Where("id = ?", data.Id).Update(data.Filed, data.Value)
|
||||||
|
if res.Error != nil {
|
||||||
|
resp.ERROR(c, "更新数据库失败!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.SUCCESS(c)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *ChatRoleHandler) Remove(c *gin.Context) {
|
func (h *ChatRoleHandler) Remove(c *gin.Context) {
|
||||||
id := h.GetInt(c, "id", 0)
|
id := h.GetInt(c, "id", 0)
|
||||||
if id <= 0 {
|
if id <= 0 {
|
||||||
|
@ -276,6 +276,7 @@ func main() {
|
|||||||
group.GET("list", h.List)
|
group.GET("list", h.List)
|
||||||
group.POST("save", h.Save)
|
group.POST("save", h.Save)
|
||||||
group.POST("sort", h.Sort)
|
group.POST("sort", h.Sort)
|
||||||
|
group.POST("set", h.Set)
|
||||||
group.GET("remove", h.Remove)
|
group.GET("remove", h.Remove)
|
||||||
}),
|
}),
|
||||||
fx.Invoke(func(s *core.AppServer, h *admin.RewardHandler) {
|
fx.Invoke(func(s *core.AppServer, h *admin.RewardHandler) {
|
||||||
|
@ -23,8 +23,7 @@
|
|||||||
<el-table-column label="角色标识" prop="key"/>
|
<el-table-column label="角色标识" prop="key"/>
|
||||||
<el-table-column label="启用状态">
|
<el-table-column label="启用状态">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-tag v-if="scope.row.enable" type="success">启用</el-tag>
|
<el-switch v-model="scope.row['enable']" @change="roleSet('enable',scope.row)"/>
|
||||||
<el-tag type="danger" v-else>禁用</el-tag>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="角色图标" prop="icon">
|
<el-table-column label="角色图标" prop="icon">
|
||||||
@ -201,21 +200,11 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const editSort = function (event, row) {
|
const roleSet = (filed, row) => {
|
||||||
event.stopPropagation()
|
httpPost('/api/admin/role/set', {id: row.id, filed: filed, value: row[filed]}).then(() => {
|
||||||
editRow.value.id = row.id
|
ElMessage.success("操作成功!")
|
||||||
editRow.value.sort = row.sort
|
}).catch(e => {
|
||||||
}
|
ElMessage.error("操作失败:" + e.message)
|
||||||
const updateSort = function (row) {
|
|
||||||
if (row.sort === editRow.value.sort) {
|
|
||||||
editRow.value.id = 0
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
httpPost('/api/admin/role/sort', {"id": row.id, "sort": row.sort}).then(() => {
|
|
||||||
editRow.value.id = 0
|
|
||||||
}).catch(() => {
|
|
||||||
ElMessage.error("更新失败!")
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user