CN-1468 fix: 为一些按钮增加权限控制
This commit is contained in:
@@ -427,39 +427,6 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
generateBreadcrumb (breadcrumb, menus) {
|
||||
/*if (this.route === '/entityDetail') {
|
||||
const entityMenu = menus.find(m => m.route === '/entityExplorer')
|
||||
const entityDetailMenu = menus.find(m => m.route === '/entityDetail')
|
||||
breadcrumb.push({
|
||||
code: entityMenu.code,
|
||||
value: entityMenu.i18n ? this.$t(entityMenu.i18n) : entityMenu.name,
|
||||
route: entityMenu.route,
|
||||
type: entityMenu.type
|
||||
})
|
||||
breadcrumb.push({
|
||||
code: entityDetailMenu.code,
|
||||
value: entityDetailMenu.i18n ? this.$t(entityDetailMenu.i18n) : entityDetailMenu.name,
|
||||
route: entityDetailMenu.route,
|
||||
type: entityDetailMenu.type
|
||||
})
|
||||
return true
|
||||
} else if (this.route === '/entityGraph') {
|
||||
const entityMenu = menus.find(m => m.route === '/entityExplorer')
|
||||
const entityGraphMenu = menus.find(m => m.route === '/entityGraph')
|
||||
breadcrumb.push({
|
||||
code: entityMenu.code,
|
||||
value: entityMenu.i18n ? this.$t(entityMenu.i18n) : entityMenu.name,
|
||||
route: entityMenu.route,
|
||||
type: entityMenu.type
|
||||
})
|
||||
breadcrumb.push({
|
||||
code: entityGraphMenu.code,
|
||||
value: entityGraphMenu.i18n ? this.$t(entityGraphMenu.i18n) : entityGraphMenu.name,
|
||||
route: entityGraphMenu.route,
|
||||
type: entityGraphMenu.type
|
||||
})
|
||||
return true
|
||||
}*/
|
||||
const menu = menus.find(m => m.route === this.route)
|
||||
if (menu) {
|
||||
breadcrumb.unshift({
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<div class="card-desc" :title="data.desc">{{data.desc ? data.desc : '—'}}</div>
|
||||
</div>
|
||||
<div class="card-operate__footer">
|
||||
<button v-if="data.showUpdate"
|
||||
<button v-if="data.showUpdate && hasPermission('editBuiltInKnowledgeBase')"
|
||||
class="top-tool-btn--update"
|
||||
@click="jumpToUpdatePage(data,true)">
|
||||
<i class="cn-icon-update-knowledge-base cn-icon"></i>
|
||||
|
||||
@@ -5,7 +5,6 @@ import router from '@/router'
|
||||
import store from '@/store'
|
||||
import App from '@/App.vue'
|
||||
import '@/utils/http.js'
|
||||
import { hasPermission } from '@/permission'
|
||||
import commonMixin from '@/mixins/common'
|
||||
import { cancelWithChange, noData, myHighLight } from '@/utils/tools'
|
||||
import { ClickOutside } from 'element-plus/lib/directives'
|
||||
@@ -37,7 +36,6 @@ app.use(i18n)
|
||||
app.use(hljsVuePlugin)
|
||||
app.use(VueGridLayout)
|
||||
|
||||
app.directive('has', hasPermission) // 注册指令
|
||||
app.directive('ele-click-outside', ClickOutside)
|
||||
app.directive('cancel', cancelWithChange)
|
||||
app.directive('no-data', noData)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hasButton } from '@/permission'
|
||||
import { hasPermission } from '@/permission'
|
||||
import { dateFormatByAppearance } from '@/utils/date-util'
|
||||
import { commonErrorTip } from '@/utils/constants'
|
||||
export default {
|
||||
@@ -28,9 +28,7 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
hasButton (code) {
|
||||
return hasButton(this.$store.getters.buttonList, code)
|
||||
},
|
||||
hasPermission,
|
||||
errorMsgHandler (axiosError) {
|
||||
if (axiosError.response) {
|
||||
if (axiosError.response.data) {
|
||||
|
||||
@@ -65,14 +65,14 @@ router.beforeEach(async (to, from, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
// menuList中是否包含route权限
|
||||
export function hasMenu (menuList, route) {
|
||||
// menuList中是否包含code
|
||||
export function hasMenu (menuList, code) {
|
||||
return menuList.some(menu => {
|
||||
if (menu.route === route) {
|
||||
if (menu.code === code) {
|
||||
return true
|
||||
} else {
|
||||
if (menu.children) {
|
||||
if (hasMenu(menu.children, route)) {
|
||||
if (hasMenu(menu.children, code)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -101,36 +101,9 @@ export function hasButton (buttonList, code) {
|
||||
return buttonList.some(button => button === code)
|
||||
}
|
||||
|
||||
// 用法 v-has="code" | v-has="[code...]" 任意匹配一个 | v-has:all="[code...]" 全匹配
|
||||
export const hasPermission = {
|
||||
beforeMount (el, binding) {
|
||||
// 节点权限处理
|
||||
const buttonCode = binding.value
|
||||
const arg = binding.arg
|
||||
if (buttonCode) {
|
||||
if (buttonCode instanceof Array) {
|
||||
let has = true
|
||||
if (arg && arg === 'all') { // 全匹配
|
||||
buttonCode.forEach(button => {
|
||||
if (has) {
|
||||
has = hasButton(store.getters.buttonList, button)
|
||||
}
|
||||
})
|
||||
} else { // 任意匹配
|
||||
has = buttonCode.some(button => {
|
||||
return hasButton(store.getters.buttonList, button)
|
||||
})
|
||||
}
|
||||
if (!has) {
|
||||
el.parentNode.removeChild(el)
|
||||
}
|
||||
} else { // 单个匹配
|
||||
if (!hasButton(store.getters.buttonList, buttonCode)) {
|
||||
el.parentNode && el.parentNode.removeChild(el)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 根据code从menuList和buttonList中判断是否有权限
|
||||
export function hasPermission (code) {
|
||||
return hasButton(store.getters.buttonList, code) || hasMenu(store.getters.menuList, code)
|
||||
}
|
||||
|
||||
// 根据orderNum排序
|
||||
|
||||
@@ -48,7 +48,9 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="edit-appearance-base__footer">
|
||||
<button style="position: relative;" :class="{'footer__btn--disabled': blockOperation.save}" :disabled="blockOperation.save" class="footer__btn" @click="save">
|
||||
<button style="position: relative;" :class="{'footer__btn--disabled': blockOperation.save}" :disabled="blockOperation.save" class="footer__btn" @click="save"
|
||||
v-if="hasPermission('editAppearence')"
|
||||
>
|
||||
<loading size="small" :loading="blockOperation.save"></loading>
|
||||
<span>{{$t('overall.save')}}</span>
|
||||
</button>
|
||||
|
||||
@@ -11,16 +11,19 @@
|
||||
>
|
||||
<template v-slot:top-tool-left>
|
||||
<button id="roles-add" class="top-tool-btn margin-r-10 top-tool-btn--create"
|
||||
v-if="hasPermission('createRole')"
|
||||
@click="add">
|
||||
<i class="cn-icon-xinjian cn-icon"></i>
|
||||
<span>{{$t('overall.create')}}</span>
|
||||
</button>
|
||||
<button id="roles-edit" class="top-tool-btn margin-r-10" :disabled="disableEdit"
|
||||
v-if="hasPermission('editRole')"
|
||||
@click="edit">
|
||||
<i class="cn-icon-edit cn-icon"></i>
|
||||
<span>{{$t('overall.edit')}}</span>
|
||||
</button>
|
||||
<button id="roles-delete" class="top-tool-btn margin-r-10" :disabled="disableDelete"
|
||||
v-if="hasPermission('deleteRole')"
|
||||
@click="delBatch">
|
||||
<i class="cn-icon-delete cn-icon"></i>
|
||||
<span>{{$t('overall.delete')}}</span>
|
||||
|
||||
@@ -11,16 +11,19 @@
|
||||
>
|
||||
<template #top-tool-left>
|
||||
<button id="account-add" class="top-tool-btn margin-r-10 top-tool-btn--create"
|
||||
v-if="hasPermission('createUser')"
|
||||
@click="add">
|
||||
<i class="cn-icon-xinjian cn-icon"></i>
|
||||
<span>{{$t('overall.create')}}</span>
|
||||
</button>
|
||||
<button id="account-edit" class="top-tool-btn margin-r-10" :disabled="disableEdit"
|
||||
v-if="hasPermission('editUser')"
|
||||
@click="editSelectRecord">
|
||||
<i class="cn-icon-edit cn-icon"></i>
|
||||
<span>{{$t('overall.edit')}}</span>
|
||||
</button>
|
||||
<button id="account-delete" class="top-tool-btn margin-r-10" :disabled="disableDelete"
|
||||
v-if="hasPermission('deleteUser')"
|
||||
@click="delBatch">
|
||||
<i class="cn-icon-delete cn-icon"></i>
|
||||
<span>{{$t('overall.delete')}}</span>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="explorer-top-tools explorer-detection-top-tools">
|
||||
<div class="explorer-top-tools-title">{{$t('overall.detections')}}</div>
|
||||
<div style="display: flex">
|
||||
<div class="explorer-top-tools-block" @click="jumpNewDetetion">
|
||||
<div class="explorer-top-tools-block" @click="jumpNewDetetion" v-if="hasPermission('detectionPolicy')">
|
||||
<i class="cn-icon cn-icon-configure-policies detection-icon-setting"></i>
|
||||
<span>{{$t('config.detections.configurePolicies')}}</span>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<div class="top-tools__left">
|
||||
<button
|
||||
id="knowledge-base-add"
|
||||
v-if="hasPermission('createDetectionPolicy')"
|
||||
:title="$t('knowledgeBase.createKnowledgeBase')"
|
||||
class="top-tool-btn margin-r-10 top-tool-btn--create"
|
||||
@click="onCreate"
|
||||
@@ -13,6 +14,7 @@
|
||||
|
||||
<button
|
||||
:disabled="disableEdit"
|
||||
v-if="hasPermission('editDetectionPolicy')"
|
||||
id="knowledge-base-edit"
|
||||
:title="$t('knowledgeBase.editKnowledgeBase')"
|
||||
class="top-tool-btn margin-r-10"
|
||||
@@ -24,6 +26,7 @@
|
||||
|
||||
<button
|
||||
:disabled="disableDelete"
|
||||
v-if="hasPermission('deleteDetectionPolicy')"
|
||||
id="knowledge-base-delete"
|
||||
:title="$t('knowledgeBase.deleteKnowledgeBase')"
|
||||
class="top-tool-btn margin-r-10"
|
||||
|
||||
@@ -24,16 +24,19 @@
|
||||
>
|
||||
<template #top-tool-left>
|
||||
<button id="account-add" class="top-tool-btn margin-r-10 top-tool-btn--create"
|
||||
v-if="hasPermission('createReport')"
|
||||
@click="add">
|
||||
<i class="cn-icon-xinjian cn-icon"></i>
|
||||
<span>{{$t('overall.create')}}</span>
|
||||
</button>
|
||||
<button id="report-edit" class="top-tool-btn margin-r-10" :disabled="disableEdit"
|
||||
v-if="hasPermission('editReport')"
|
||||
@click="editReport">
|
||||
<i class="cn-icon-edit cn-icon"></i>
|
||||
<span>{{$t('overall.edit')}}</span>
|
||||
</button>
|
||||
<button id="report-delete" class="top-tool-btn margin-r-10" :disabled="disableDelete"
|
||||
v-if="hasPermission('deleteReport')"
|
||||
@click="delBatch">
|
||||
<i class="cn-icon-delete cn-icon"></i>
|
||||
<span>{{$t('overall.delete')}}</span>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
</div>
|
||||
<div class="builtIn-to-user-defined" v-if="dataType === 'builtInList'">
|
||||
<button :title="$t('knowledgeBase.userDefinedLibrary')" class="top-tool-btn--user_defined_library"
|
||||
v-if="hasPermission('userDefinedLibrary')"
|
||||
@click="changeToUserDefinedList">
|
||||
<i class="cn-icon-add-knowledge-base cn-icon" ></i>
|
||||
<span>{{$t('knowledgeBase.userDefinedLibrary')}}</span>
|
||||
@@ -39,17 +40,20 @@
|
||||
<div class="top-tools__left">
|
||||
<button id="knowledge-base-add" :title="$t('knowledgeBase.createKnowledgeBase')" class="top-tool-btn margin-r-10 top-tool-btn--create"
|
||||
style="width:72px;"
|
||||
v-if="hasPermission('createUserDefinedLibrary')"
|
||||
@click="jumpToCreatePage">
|
||||
<i class="cn-icon-xinjian cn-icon"></i>
|
||||
<span>{{$t('overall.create')}}</span>
|
||||
</button>
|
||||
<button id="knowledge-base-edit" :title="$t('knowledgeBase.editKnowledgeBase')" class="top-tool-btn margin-r-10" :disabled="disableEdit"
|
||||
style="width:72px;"
|
||||
v-if="hasPermission('editUserDefinedLibrary')"
|
||||
@click="editSelectRecord">
|
||||
<i class="cn-icon-edit cn-icon" ></i>
|
||||
<span>{{$t('overall.edit')}}</span>
|
||||
</button>
|
||||
<button id="knowledge-base-delete" :title="$t('knowledgeBase.deleteKnowledgeBase')" class="top-tool-btn margin-r-10"
|
||||
v-if="hasPermission('deleteUserDefinedLibrary')"
|
||||
style="width:72px;" :disabled="disableDelete"
|
||||
@click="toDelete">
|
||||
<i class="cn-icon-delete cn-icon"></i>
|
||||
|
||||
Reference in New Issue
Block a user