1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2025-05-01 06:39:01 +08:00

feat: 添加PH函数,根据按钮权限判断当前按钮是否渲染

This commit is contained in:
leipu 2025-03-19 10:35:50 +08:00
parent 84fb1198d5
commit e74856040a
4 changed files with 19 additions and 3 deletions

View File

@ -8,7 +8,7 @@
import { router } from '@/router'
const permission = {
export const permission = {
mounted(el, binding) {
const currentRoute = unref(router.currentRoute)
const btns = currentRoute.meta?.btns?.map(item => item.code) || []

View File

@ -11,4 +11,5 @@ export * from './common'
export * from './http'
export * from './is'
export * from './naiveTools'
export * from './permissionH'
export * from './storage'

14
src/utils/permissionH.js Normal file
View File

@ -0,0 +1,14 @@
import { permission } from '@/directives'
/**
* @description: 按钮权限渲染
*/
import { h, withDirectives } from 'vue'
export function PH(el, props, slots, butCode) {
return withDirectives(
h(el, props, slots),
[
[permission, butCode],
],
)
}

View File

@ -112,7 +112,7 @@
<script setup>
import { MeCrud, MeModal, MeQueryItem } from '@/components'
import { useCrud } from '@/composables'
import { formatDateTime } from '@/utils'
import { formatDateTime, PH } from '@/utils'
import { NAvatar, NButton, NSwitch, NTag } from 'naive-ui'
import api from './api'
@ -225,7 +225,7 @@ const columns = [
hideInExcel: true,
render(row) {
return [
h(
PH(
NButton,
{
size: 'small',
@ -237,6 +237,7 @@ const columns = [
default: () => '分配角色',
icon: () => h('i', { class: 'i-carbon:user-role text-14' }),
},
'setRole',
),
h(
NButton,