fix: 修复bug

This commit is contained in:
tangtanglove
2023-03-08 15:07:27 +08:00
parent e48b44825d
commit ad2820800a
2 changed files with 23 additions and 37 deletions

View File

@@ -258,48 +258,34 @@ func (p *Admin) AfterSaved(ctx *builder.Context, id int, data map[string]interfa
return ctx.JSON(200, msg.Error(result.Error.Error(), ""))
}
// 导入操作,直接返回
if ctx.IsImport() {
return true
}
if data["role_ids"] == nil {
return ctx.JSON(200, msg.Success("操作成功!", strings.Replace("/index?api="+adminresource.IndexRoute, ":resource", ctx.Param("resource"), -1), ""))
}
if ctx.IsCreating() {
roleData := []map[string]interface{}{}
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{}{}
// 先清空用户对应的角色
// 编辑操作,先清空用户对应的角色
if ctx.IsEditing() {
db.Client.Model(&models.ModelHasRole{}).Where("model_id = ?", id).Where("model_type = ?", "admin").Delete("")
for _, v := range data["role_ids"].([]interface{}) {
item := map[string]interface{}{
"role_id": v,
"model_type": "admin",
"model_id": id,
}
roleData = append(roleData, item)
}
roleData := []map[string]interface{}{}
for _, v := range data["role_ids"].([]interface{}) {
item := map[string]interface{}{
"role_id": v,
"model_type": "admin",
"model_id": id,
}
if len(roleData) > 0 {
// 同步角色
err := db.Client.Model(&models.ModelHasRole{}).Create(roleData).Error
if err != nil {
return msg.Error(err.Error(), "")
}
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(), "")
}
}

View File

@@ -19,7 +19,7 @@ const (
AppName = "QuarkGo"
// Version of current package
Version = "1.1.26"
Version = "1.1.27"
// 静态文件URL
RespositoryURL = "https://github.com/quarkcms/quark-go/tree/main/website/"