Browse Source

修复前端项目代码丢失,问题,修复角色拷贝功能

pixel 4 years ago
parent
commit
aa4fa94ce6

+ 1 - 1
server/api/v1/sys_authority.go

@@ -42,7 +42,7 @@ func CopyAuthority(c *gin.Context) {
 	_ = c.ShouldBindJSON(&copyInfo)
 	err, authBack := service.CopyAuthority(copyInfo)
 	if err != nil {
-		response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
+		response.FailWithMessage(fmt.Sprintf("拷贝失败,%v", err), c)
 	} else {
 		response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
 	}

+ 10 - 0
server/service/sys_authority.go

@@ -17,6 +17,11 @@ import (
 // @return    authority       model.SysAuthority
 
 func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) {
+	var authorityBox model.SysAuthority
+	notHas := global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).Find(&authorityBox).RecordNotFound()
+	if !notHas {
+		return errors.New("存在相同角色id"), auth
+	}
 	err = global.GVA_DB.Create(&auth).Error
 	return err, auth
 }
@@ -29,6 +34,11 @@ func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAut
 // @return    authority       model.SysAuthority
 
 func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority model.SysAuthority) {
+	var authorityBox model.SysAuthority
+	notHas := global.GVA_DB.Where("authority_id = ?", copyInfo.Authority.AuthorityId).Find(&authorityBox).RecordNotFound()
+	if !notHas {
+		return errors.New("存在相同角色id"), authority
+	}
 	copyInfo.Authority.Children = []model.SysAuthority{}
 	err, menus := GetMenuAuthority(copyInfo.OldAuthorityId)
 	var baseMenu []model.SysBaseMenu

+ 2 - 2
web/src/view/superAdmin/authority/authority.vue

@@ -130,11 +130,11 @@ export default {
       this.dialogTitle = "拷贝角色"
       this.dialogType = "copy"
       for(let k in this.form) {
-        this.form[key] = row[key]
+        this.form[k] = row[k]
       }
       this.copyForm = row
       this.dialogFormVisible = true;
-    }
+    },
     opdendrawer(row) {
       this.drawer = true
       this.activeRow = row