diff --git a/controller/role.go b/controller/role.go index b161530..6e10933 100644 --- a/controller/role.go +++ b/controller/role.go @@ -13,3 +13,21 @@ func GetRoleList(c *gin.Context){ "result":roles, }) } +func PostRole(c *gin.Context){ + roleId:=c.PostForm("id") + method:=c.PostForm("method") + name:=c.PostForm("name") + path:=c.PostForm("path") + if roleId==""||method==""||name==""||path==""{ + c.JSON(200, gin.H{ + "code": 400, + "msg": "参数不能为空", + }) + return + } + models.SaveRole(roleId,name,method,path) + c.JSON(200, gin.H{ + "code": 200, + "msg": "修改成功", + }) +} diff --git a/main.go b/main.go index c2b2d3b..305a893 100644 --- a/main.go +++ b/main.go @@ -77,18 +77,19 @@ func main() { engine.POST("/message_status",controller.GetVisitorMessage) //获取客服信息 - engine.GET("/kefuinfo",middleware.JwtApiMiddleware, controller.GetKefuInfo) - engine.GET("/kefuinfo_setting",middleware.JwtApiMiddleware, controller.GetKefuInfoSetting) + engine.GET("/kefuinfo",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.GetKefuInfo) + engine.GET("/kefuinfo_setting",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.GetKefuInfoSetting) engine.POST("/kefuinfo",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.PostKefuInfo) engine.DELETE("/kefuinfo",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.DeleteKefuInfo) - engine.GET("/kefulist",middleware.JwtApiMiddleware, controller.GetKefuList) + engine.GET("/kefulist",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.GetKefuList) //设置页 engine.GET("/setting", tmpl.PageSetting) //设置mysql engine.GET("/setting_mysql", tmpl.PageSettingMysql) //角色列表 - engine.GET("/roles",middleware.JwtApiMiddleware, controller.GetRoleList) + engine.GET("/roles",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.GetRoleList) engine.GET("/roles_list", tmpl.PageRoleList) + engine.POST("/role",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.PostRole) //网页部署 engine.GET("/setting_deploy", tmpl.PageSettingDeploy) diff --git a/models/roles.go b/models/roles.go index fd86f83..64201bd 100644 --- a/models/roles.go +++ b/models/roles.go @@ -14,4 +14,12 @@ func FindRole(id interface{})Role{ var role Role DB.Where("id = ?", id).First(&role) return role +} +func SaveRole(id string,name string,method string,path string){ + role:=&Role{ + Method: method, + Name: name, + Path: path, + } + DB.Model(role).Where("id=?",id).Update(role) } \ No newline at end of file diff --git a/static/html/setting_bottom.html b/static/html/setting_bottom.html index 5d27087..00764e0 100644 --- a/static/html/setting_bottom.html +++ b/static/html/setting_bottom.html @@ -45,6 +45,12 @@ nickname: [ { required: true, message: '请输入昵称', trigger: 'blur' }, ], + method: [ + { required: true, message: '请输入允许的方法', trigger: 'blur' }, + ], + path: [ + { required: true, message: '请输入允许的路径', trigger: 'blur' }, + ], }, kefuList:[], kefuDialog:false, @@ -55,6 +61,14 @@ avator:"", nickname:"", }, + roleList:[], + roleDialog:false, + roleForm:{ + id:"", + name:"", + method:"", + path:"", + }, }, methods: { //提交表单 @@ -170,6 +184,8 @@ }); }else if(data.result!=null){ callback(data.result); + }else{ + callback(data); } _this.fullscreenLoading=false @@ -234,6 +250,34 @@ }); }); }, + //配置角色权限 + showAuthDialog(id,name,method,path){ + this.roleForm.id=id + this.roleForm.name=name + this.roleForm.method=method + this.roleForm.path=path + this.roleDialog=true; + }, + //提交角色表单 + submitRoleForm(formName){ + let _this=this; + this.$refs[formName].validate((valid) => { + if (valid) { + this.sendAjax("/role","POST",_this.roleForm,function(result){ + _this.roleDialog=false; + _this.sendAjax("/roles","get",{},function(result){ + _this.roleList=result; + }); + _this.$message({ + message: result.msg, + type: 'success' + }); + }); + } else { + return false; + } + }); + }, //生成部署js createDeployJs(){ let domain=window.location.host; diff --git a/static/html/setting_role_list.html b/static/html/setting_role_list.html index d42393b..01c519f 100644 --- a/static/html/setting_role_list.html +++ b/static/html/setting_role_list.html @@ -20,11 +20,15 @@ prop="method" label="允许方法"> + + @@ -32,31 +36,24 @@ - - - - - - + + + - - + + - - - - - - + + - 取 消 - 确 定 + 取 消 + 确 定