29 lines
608 B
Vue
29 lines
608 B
Vue
<template>
|
||
<view v-if="showButton">
|
||
<slot></slot>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, inject } from 'vue'
|
||
import { hasPermission } from '@/utils/permission'
|
||
|
||
const props = defineProps({
|
||
// 功能类型,与permission.js中的permissionMap对应
|
||
type: {
|
||
type: String,
|
||
required: true
|
||
}
|
||
})
|
||
|
||
// 尝试从父级组件注入权限数组,如果没有则使用空数组
|
||
const userPermissions = inject('userPermissions', [])
|
||
|
||
// 计算是否显示按钮
|
||
const showButton = computed(() => {
|
||
return hasPermission(props.type, userPermissions)
|
||
})
|
||
</script>
|
||
|
||
<style>
|
||
</style> |