feat: 接入权限接口
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, defineAsyncComponent } from 'vue'
|
||||
import type { Component } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
import { useLoginStore } from '@/stores/login'
|
||||
import PagePlaceholder from '@/components/PagePlaceholder.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const loginStore = useLoginStore()
|
||||
|
||||
const componentRegistry: Record<string, Component> = {
|
||||
'dashboard/index': defineAsyncComponent(() => import('@/views/workbench/home/index.vue')),
|
||||
'sign/workbench/index': defineAsyncComponent(() => import('@/views/workbench/signing/index.vue')),
|
||||
'system/org/index': defineAsyncComponent(() => import('@/views/management/users/index.vue')),
|
||||
'system/role/index': defineAsyncComponent(() => import('@/views/management/roles/index.vue')),
|
||||
'doc/library/index': defineAsyncComponent(() => import('@/views/management/documents/index.vue')),
|
||||
'report/index': defineAsyncComponent(() => import('@/views/management/reports/index.vue')),
|
||||
'system/setting/index': defineAsyncComponent(
|
||||
() => import('@/views/management/settings/index.vue'),
|
||||
),
|
||||
}
|
||||
|
||||
const resource = computed(() => loginStore.menuForPath(route.path))
|
||||
const pageComponent = computed(() => {
|
||||
const path = resource.value?.componentPath
|
||||
return path ? (componentRegistry[path] ?? null) : null
|
||||
})
|
||||
const unsupportedMessage = computed(() => {
|
||||
const componentPath = resource.value?.componentPath
|
||||
return componentPath
|
||||
? `前端暂未接入组件「${componentPath}」。资源路由和权限已从菜单资源读取。`
|
||||
: '当前路由没有对应的启用菜单资源。'
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<KeepAlive v-if="pageComponent && resource?.cacheable">
|
||||
<component :is="pageComponent" :key="resource?.id" />
|
||||
</KeepAlive>
|
||||
<component :is="pageComponent" v-else-if="pageComponent" />
|
||||
<PagePlaceholder
|
||||
v-else
|
||||
group="菜单资源"
|
||||
:title="resource?.name ?? '页面未接入'"
|
||||
:icon="resource?.icon ?? '◇'"
|
||||
:description="unsupportedMessage"
|
||||
/>
|
||||
</template>
|
||||
Reference in New Issue
Block a user