mirror of
https://github.com/quarkcloudio/quark-go.git
synced 2025-10-21 23:19:28 +08:00
fix: 修复bug
This commit is contained in:
@@ -258,34 +258,21 @@ func (p *Admin) AfterSaved(ctx *builder.Context, id int, data map[string]interfa
|
|||||||
return ctx.JSON(200, msg.Error(result.Error.Error(), ""))
|
return ctx.JSON(200, msg.Error(result.Error.Error(), ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 导入操作,直接返回
|
||||||
|
if ctx.IsImport() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if data["role_ids"] == nil {
|
if data["role_ids"] == nil {
|
||||||
return ctx.JSON(200, msg.Success("操作成功!", strings.Replace("/index?api="+adminresource.IndexRoute, ":resource", ctx.Param("resource"), -1), ""))
|
return ctx.JSON(200, msg.Success("操作成功!", strings.Replace("/index?api="+adminresource.IndexRoute, ":resource", ctx.Param("resource"), -1), ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsCreating() {
|
// 编辑操作,先清空用户对应的角色
|
||||||
roleData := []map[string]interface{}{}
|
if ctx.IsEditing() {
|
||||||
for _, v := range data["role_ids"].([]interface{}) {
|
|
||||||
item := map[string]interface{}{
|
|
||||||
"role_id": v,
|
|
||||||
"model_type": "admin",
|
|
||||||
"model_id": id,
|
|
||||||
}
|
|
||||||
roleData = append(roleData, item)
|
|
||||||
}
|
|
||||||
if len(roleData) > 0 {
|
|
||||||
// 同步角色
|
|
||||||
err := db.Client.Model(&models.ModelHasRole{}).Create(roleData).Error
|
|
||||||
if err != nil {
|
|
||||||
return msg.Error(err.Error(), "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// 同步角色
|
|
||||||
roleData := []map[string]interface{}{}
|
|
||||||
|
|
||||||
// 先清空用户对应的角色
|
|
||||||
db.Client.Model(&models.ModelHasRole{}).Where("model_id = ?", id).Where("model_type = ?", "admin").Delete("")
|
db.Client.Model(&models.ModelHasRole{}).Where("model_id = ?", id).Where("model_type = ?", "admin").Delete("")
|
||||||
|
}
|
||||||
|
|
||||||
|
roleData := []map[string]interface{}{}
|
||||||
for _, v := range data["role_ids"].([]interface{}) {
|
for _, v := range data["role_ids"].([]interface{}) {
|
||||||
item := map[string]interface{}{
|
item := map[string]interface{}{
|
||||||
"role_id": v,
|
"role_id": v,
|
||||||
@@ -301,7 +288,6 @@ func (p *Admin) AfterSaved(ctx *builder.Context, id int, data map[string]interfa
|
|||||||
return msg.Error(err.Error(), "")
|
return msg.Error(err.Error(), "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.JSON(200, msg.Success("操作成功!", strings.Replace("/index?api="+adminresource.IndexRoute, ":resource", ctx.Param("resource"), -1), ""))
|
return ctx.JSON(200, msg.Success("操作成功!", strings.Replace("/index?api="+adminresource.IndexRoute, ":resource", ctx.Param("resource"), -1), ""))
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ const (
|
|||||||
AppName = "QuarkGo"
|
AppName = "QuarkGo"
|
||||||
|
|
||||||
// Version of current package
|
// Version of current package
|
||||||
Version = "1.1.26"
|
Version = "1.1.27"
|
||||||
|
|
||||||
// 静态文件URL
|
// 静态文件URL
|
||||||
RespositoryURL = "https://github.com/quarkcms/quark-go/tree/main/website/"
|
RespositoryURL = "https://github.com/quarkcms/quark-go/tree/main/website/"
|
||||||
|
Reference in New Issue
Block a user