角色配置权限

pull/30/head
taoshihan1991 4 years ago
parent 3a8b5ba152
commit d5c9abe763

@ -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": "修改成功",
})
}

@ -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)

@ -15,3 +15,11 @@ func FindRole(id interface{})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)
}

@ -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;

@ -20,11 +20,15 @@
prop="method"
label="允许方法">
</el-table-column>
<el-table-column
prop="path"
label="路径">
</el-table-column>
<el-table-column
prop="id"
label="操作">
<template slot-scope="scope">
<el-button @click="" type="primary" size="small" plain>配置权限</el-button>
<el-button @click="showAuthDialog(scope.row.role_id,scope.row.role_name,scope.row.method,scope.row.path)" type="primary" size="small" plain>配置权限</el-button>
</template>
</el-table-column>
</el-table>
@ -32,31 +36,24 @@
</el-container>
<el-dialog
title="客服"
:visible.sync="kefuDialog"
title="配置权限"
:visible.sync="roleDialog"
width="30%"
>
<el-form ref="kefuForm" :model="kefuForm" :rules="rules" label-width="70px">
<el-form-item label="用户名" prop="name">
<el-input v-model="kefuForm.name"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input v-model="kefuForm.password"></el-input>
<el-form ref="roleForm" :model="roleForm" :rules="rules" label-width="70px">
<el-form-item label="角色名" prop="name">
<el-input v-model="roleForm.name"></el-input>
</el-form-item>
<el-form-item label="昵称" prop="nickname">
<el-input v-model="kefuForm.nickname"></el-input>
<el-form-item label="方法" prop="method">
<el-input v-model="roleForm.method"></el-input>
</el-form-item>
<el-form-item label="头像" prop="avator">
<el-select v-model="kefuForm.avator" placeholder="请选择头像">
<el-option :label="'头像'+item" :value="'/static/images/'+item+'.jpg'" v-for="item in [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]" v-bind:key="item">
<el-avatar :size="30" :src="'/static/images/'+item+'.jpg'"></el-avatar>
</el-option>
</el-select>
<el-form-item label="路径" prop="path">
<el-input type="textarea" v-model="roleForm.path"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="kefuDialog = false">取 消</el-button>
<el-button type="primary" @click="submitKefuForm('kefuForm')">确 定</el-button>
<el-button @click="roleDialog = false">取 消</el-button>
<el-button type="primary" @click="submitRoleForm('roleForm')">确 定</el-button>
</span>
</el-dialog>
</template>

Loading…
Cancel
Save