1
0
mirror of https://github.com/zclzone/vue-naive-admin.git synced 2025-04-30 22:29:01 +08:00

Merge 43506681e9ce55d5655a3a7c8d12e9fd5bb17f70 into 70c2098d2ed646348812945873349e4e72080186

This commit is contained in:
leip247 2025-03-21 03:29:42 +00:00 committed by GitHub
commit 10ae8ace90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 58 additions and 27 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

@ -43,6 +43,12 @@ export function createPermissionGuard(router) {
return { ...to, replace: true }
}
router.addRoute({
name: 'catchAll',
path: '/:catchAll(.*)',
redirect: '/404',
})
const routes = router.getRoutes()
if (routes.find(route => route.name === to.name))
return true

View File

@ -16,6 +16,8 @@ export const useRouterStore = defineStore('router', () => {
accessRoutes.forEach((item) => {
router.hasRoute(item.name) && router.removeRoute(item.name)
})
router.removeRoute('catchAll')
}
return {

View File

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

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

@ -0,0 +1,9 @@
import { permission } from '@/directives'
/**
* @description: 按钮权限渲染
*/
import { withDirectives } from 'vue'
export function withPermission(vnode, code) {
return withDirectives(vnode, [[permission, code]])
}

View File

@ -163,31 +163,31 @@ const columns = [
render(row) {
return row.roles?.some(item => item.id === +route.params.roleId)
? h(
NButton,
{
size: 'small',
type: 'error',
secondary: true,
onClick: () => handleBatchRemove([row.id]),
},
{
default: () => '取消授权',
icon: () => h('i', { class: 'i-material-symbols:delete-outline text-14' }),
},
)
NButton,
{
size: 'small',
type: 'error',
secondary: true,
onClick: () => handleBatchRemove([row.id]),
},
{
default: () => '取消授权',
icon: () => h('i', { class: 'i-material-symbols:delete-outline text-14' }),
},
)
: h(
NButton,
{
size: 'small',
type: 'primary',
secondary: true,
onClick: () => handleBatchAdd([row.id]),
},
{
default: () => '授权',
icon: () => h('i', { class: 'i-line-md:confirm-circle text-14' }),
},
)
NButton,
{
size: 'small',
type: 'primary',
secondary: true,
onClick: () => handleBatchAdd([row.id]),
},
{
default: () => '授权',
icon: () => h('i', { class: 'i-line-md:confirm-circle text-14' }),
},
)
},
},
]

View File

@ -112,7 +112,7 @@
<script setup>
import { MeCrud, MeModal, MeQueryItem } from '@/components'
import { useCrud } from '@/composables'
import { formatDateTime } from '@/utils'
import { formatDateTime, withPermission } from '@/utils'
import { NAvatar, NButton, NSwitch, NTag } from 'naive-ui'
import api from './api'
@ -219,17 +219,30 @@ const columns = [
{
title: '操作',
key: 'actions',
width: 320,
width: 380,
align: 'right',
fixed: 'right',
hideInExcel: true,
render(row) {
return [
withPermission(
h(NButton, {
size: 'small',
type: 'primary',
secondary: true,
onClick: () => handleOpenRolesSet(row),
}, {
default: () => '超管专属',
icon: () => h('i', { class: 'i-carbon:user-role text-14' }),
}),
'superAdmin',
),
h(
NButton,
{
size: 'small',
type: 'primary',
class: 'ml-12px',
secondary: true,
onClick: () => handleOpenRolesSet(row),
},