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:
commit
10ae8ace90
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import { router } from '@/router'
|
import { router } from '@/router'
|
||||||
|
|
||||||
const permission = {
|
export const permission = {
|
||||||
mounted(el, binding) {
|
mounted(el, binding) {
|
||||||
const currentRoute = unref(router.currentRoute)
|
const currentRoute = unref(router.currentRoute)
|
||||||
const btns = currentRoute.meta?.btns?.map(item => item.code) || []
|
const btns = currentRoute.meta?.btns?.map(item => item.code) || []
|
||||||
|
@ -43,6 +43,12 @@ export function createPermissionGuard(router) {
|
|||||||
return { ...to, replace: true }
|
return { ...to, replace: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
router.addRoute({
|
||||||
|
name: 'catchAll',
|
||||||
|
path: '/:catchAll(.*)',
|
||||||
|
redirect: '/404',
|
||||||
|
})
|
||||||
|
|
||||||
const routes = router.getRoutes()
|
const routes = router.getRoutes()
|
||||||
if (routes.find(route => route.name === to.name))
|
if (routes.find(route => route.name === to.name))
|
||||||
return true
|
return true
|
||||||
|
@ -16,6 +16,8 @@ export const useRouterStore = defineStore('router', () => {
|
|||||||
accessRoutes.forEach((item) => {
|
accessRoutes.forEach((item) => {
|
||||||
router.hasRoute(item.name) && router.removeRoute(item.name)
|
router.hasRoute(item.name) && router.removeRoute(item.name)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.removeRoute('catchAll')
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -11,4 +11,5 @@ export * from './common'
|
|||||||
export * from './http'
|
export * from './http'
|
||||||
export * from './is'
|
export * from './is'
|
||||||
export * from './naiveTools'
|
export * from './naiveTools'
|
||||||
|
export * from './permissionH'
|
||||||
export * from './storage'
|
export * from './storage'
|
||||||
|
9
src/utils/permissionH.js
Normal file
9
src/utils/permissionH.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { permission } from '@/directives'
|
||||||
|
/**
|
||||||
|
* @description: 按钮权限渲染
|
||||||
|
*/
|
||||||
|
import { withDirectives } from 'vue'
|
||||||
|
|
||||||
|
export function withPermission(vnode, code) {
|
||||||
|
return withDirectives(vnode, [[permission, code]])
|
||||||
|
}
|
@ -163,31 +163,31 @@ const columns = [
|
|||||||
render(row) {
|
render(row) {
|
||||||
return row.roles?.some(item => item.id === +route.params.roleId)
|
return row.roles?.some(item => item.id === +route.params.roleId)
|
||||||
? h(
|
? h(
|
||||||
NButton,
|
NButton,
|
||||||
{
|
{
|
||||||
size: 'small',
|
size: 'small',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
secondary: true,
|
secondary: true,
|
||||||
onClick: () => handleBatchRemove([row.id]),
|
onClick: () => handleBatchRemove([row.id]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
default: () => '取消授权',
|
default: () => '取消授权',
|
||||||
icon: () => h('i', { class: 'i-material-symbols:delete-outline text-14' }),
|
icon: () => h('i', { class: 'i-material-symbols:delete-outline text-14' }),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
: h(
|
: h(
|
||||||
NButton,
|
NButton,
|
||||||
{
|
{
|
||||||
size: 'small',
|
size: 'small',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
secondary: true,
|
secondary: true,
|
||||||
onClick: () => handleBatchAdd([row.id]),
|
onClick: () => handleBatchAdd([row.id]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
default: () => '授权',
|
default: () => '授权',
|
||||||
icon: () => h('i', { class: 'i-line-md:confirm-circle text-14' }),
|
icon: () => h('i', { class: 'i-line-md:confirm-circle text-14' }),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -112,7 +112,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { MeCrud, MeModal, MeQueryItem } from '@/components'
|
import { MeCrud, MeModal, MeQueryItem } from '@/components'
|
||||||
import { useCrud } from '@/composables'
|
import { useCrud } from '@/composables'
|
||||||
import { formatDateTime } from '@/utils'
|
import { formatDateTime, withPermission } from '@/utils'
|
||||||
import { NAvatar, NButton, NSwitch, NTag } from 'naive-ui'
|
import { NAvatar, NButton, NSwitch, NTag } from 'naive-ui'
|
||||||
import api from './api'
|
import api from './api'
|
||||||
|
|
||||||
@ -219,17 +219,30 @@ const columns = [
|
|||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'actions',
|
key: 'actions',
|
||||||
width: 320,
|
width: 380,
|
||||||
align: 'right',
|
align: 'right',
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
hideInExcel: true,
|
hideInExcel: true,
|
||||||
render(row) {
|
render(row) {
|
||||||
return [
|
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(
|
h(
|
||||||
NButton,
|
NButton,
|
||||||
{
|
{
|
||||||
size: 'small',
|
size: 'small',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
|
class: 'ml-12px',
|
||||||
secondary: true,
|
secondary: true,
|
||||||
onClick: () => handleOpenRolesSet(row),
|
onClick: () => handleOpenRolesSet(row),
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user