后台格式规范化 引入casbin做鉴权

This commit is contained in:
pixel
2019-12-12 13:21:16 +08:00
parent effab2d2b0
commit 3f17e80944
46 changed files with 576 additions and 338 deletions
+35
View File
@@ -0,0 +1,35 @@
import service from '@/utils/request'
// @Tags authority
// @Summary 更改角色api权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateAuthorityPatams true "更改角色api权限"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /casbin/casbinPUpdata [post]
export const casbinPUpdata = (data) => {
return service({
url: "/casbin/casbinPUpdata",
method: 'post',
data
})
}
// @Tags casbin
// @Summary 获取权限列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateAuthorityPatams true "获取权限列表"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /casbin/getPolicyPathByAuthorityId [post]
export const getPolicyPathByAuthorityId = (data) => {
return service({
url: "/casbin/getPolicyPathByAuthorityId",
method: 'post',
data
})
}
@@ -68,7 +68,7 @@
:props="apiDefaultProps"
default-expand-all
highlight-current
node-key="ID"
node-key="path"
ref="apiTree"
show-checkbox
v-if="apiDialogFlag"
@@ -91,6 +91,7 @@ import {
} from '@/api/authority'
import { getBaseMenuTree, addMenuAuthority, getMenuAuthority } from '@/api/menu'
import { getAllApis, getAuthAndApi, setAuthAndApi } from '@/api/api'
import { casbinPUpdata,getPolicyPathByAuthorityId } from '@/api/casbin'
import infoList from '@/components/mixins/infoList'
export default {
name: 'Authority',
@@ -234,24 +235,19 @@ export default {
},
// 关联用户api关系
async addAuthApi(row) {
const res = await getAuthAndApi({ authorityId: row.authorityId })
const res = await getPolicyPathByAuthorityId({ authorityId: row.authorityId })
this.activeUserId = row.authorityId
this.apiTreeIds = res.data.apis || []
this.apiTreeIds = res.data.paths || []
this.apiDialogFlag = true
},
// 关联关系确定
async authApiEnter() {
const checkArr = this.$refs.apiTree.getCheckedKeys(true)
const res = await setAuthAndApi({
authorityId: this.activeUserId,
apiIds: checkArr
})
if (res.success) {
this.$message({
type: 'success',
message: '添加成功!'
})
const res = await casbinPUpdata({ authorityId: this.activeUserId,paths:checkArr})
if(res.success){
this.$message({type:"success",message:res.msg})
this.closeDialog()
}
this.closeDialog()
}
},
async created() {