2024-08-29 17:06:00 +08:00
|
|
|
|
<template>
|
|
|
|
|
<a-layout class="main-content">
|
2024-08-30 18:07:30 +08:00
|
|
|
|
<a-layout-sider :collapsed="collapsed" theme="light" :trigger="null" collapsible>
|
2024-08-29 17:06:00 +08:00
|
|
|
|
<div v-if="!collapsed" class="title flex-center">
|
|
|
|
|
<div>超级后台</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else class="logo flex-center">
|
2024-08-30 18:07:30 +08:00
|
|
|
|
<img src="@/assets/vue.svg" title="超级后台" alt="xx" />
|
2024-08-29 17:06:00 +08:00
|
|
|
|
</div>
|
2024-08-30 18:07:30 +08:00
|
|
|
|
<!-- -->
|
2024-09-02 18:08:00 +08:00
|
|
|
|
<!-- <a-menu v-model:selectedKeys="selectedKeys" theme="light" mode="inline">
|
2024-08-30 18:07:30 +08:00
|
|
|
|
<a-menu-item key="1">
|
|
|
|
|
<router-link to="/index">
|
|
|
|
|
<pie-chart-outlined />
|
|
|
|
|
<span>首页</span>
|
|
|
|
|
</router-link>
|
|
|
|
|
</a-menu-item>
|
|
|
|
|
<a-menu-item key="2">
|
|
|
|
|
<router-link to="/register/index">
|
|
|
|
|
<pie-chart-outlined />
|
|
|
|
|
<span>注册</span>
|
|
|
|
|
</router-link>
|
|
|
|
|
</a-menu-item>
|
2024-09-02 18:08:00 +08:00
|
|
|
|
</a-menu> -->
|
|
|
|
|
<!-- 动态生成菜单项 -->
|
|
|
|
|
<a-menu v-model:selectedKeys="selectedKeys" theme="light" mode="inline">
|
2024-09-04 14:02:47 +08:00
|
|
|
|
<template v-for="route in staticRouter">
|
|
|
|
|
<a-menu-item v-if="route.meta?.title === undefined && route.children">
|
2024-09-02 18:08:00 +08:00
|
|
|
|
<router-link :to="`${route.children[0].path}`">
|
2024-09-04 14:02:47 +08:00
|
|
|
|
<HomeOutlined v-if="route.name === 'dashboard'" />
|
|
|
|
|
<InsuranceOutlined v-if="route.name === 'police'" />
|
|
|
|
|
<SoundOutlined v-if="route.name === 'law'" />
|
|
|
|
|
<ApartmentOutlined v-if="route.name === 'warning'" />
|
|
|
|
|
<span>{{ route?.children[0]?.meta?.title }}</span>
|
2024-09-02 18:08:00 +08:00
|
|
|
|
</router-link>
|
|
|
|
|
</a-menu-item>
|
2024-09-04 14:02:47 +08:00
|
|
|
|
<a-sub-menu v-if="route.children && route.children.length && route?.meta?.title" :key="route.path">
|
2024-09-02 18:08:00 +08:00
|
|
|
|
<template #title>
|
2024-09-04 14:02:47 +08:00
|
|
|
|
<MailOutlined />
|
2024-09-02 18:08:00 +08:00
|
|
|
|
<span>{{ route.meta?.title }}</span>
|
|
|
|
|
</template>
|
|
|
|
|
<a-menu-item v-for="child in route.children" :key="child.path">
|
2024-09-04 14:02:47 +08:00
|
|
|
|
<router-link :to="`${route.path}/${child.path}`">{{ child.meta?.title }}</router-link>
|
2024-09-02 18:08:00 +08:00
|
|
|
|
</a-menu-item>
|
|
|
|
|
</a-sub-menu>
|
|
|
|
|
</template>
|
2024-08-30 18:07:30 +08:00
|
|
|
|
</a-menu>
|
2024-08-29 17:06:00 +08:00
|
|
|
|
</a-layout-sider>
|
|
|
|
|
<a-layout>
|
2024-08-30 18:07:30 +08:00
|
|
|
|
<a-layout-header class="layout-header">
|
|
|
|
|
<layout-header v-model:collapsed="collapsed" />
|
2024-08-29 17:06:00 +08:00
|
|
|
|
</a-layout-header>
|
2024-08-30 18:07:30 +08:00
|
|
|
|
<a-layout-content class="layout-content">
|
2024-09-04 14:02:47 +08:00
|
|
|
|
<!-- <keep-alive> 会缓存已经访问过的组件,当你再次访问同一个页面时,它会直接从缓存中加载,而不会触发重新渲染 -->
|
|
|
|
|
<!-- router-view 必须绑定一个key 否则就会出现 路由切换白屏的问题(路由切换后,页面不显示内容,刷新后正常显示),但是这样也会导致一个问题就是 会导致keep-alive失效、因为这种方式会强制刷新路由-->
|
|
|
|
|
|
|
|
|
|
<router-view v-slot="{ Component, route }" :key="route.path">
|
|
|
|
|
<!-- <router-view v-slot="{ Component, route }"> -->
|
2024-08-29 17:06:00 +08:00
|
|
|
|
<transition appear name="fade-transform" mode="out-in">
|
|
|
|
|
<keep-alive :include="keepAliveNames">
|
2024-09-04 14:02:47 +08:00
|
|
|
|
<component :is="Component" :key="route.path" />
|
2024-08-29 17:06:00 +08:00
|
|
|
|
</keep-alive>
|
|
|
|
|
</transition>
|
|
|
|
|
</router-view>
|
|
|
|
|
</a-layout-content>
|
|
|
|
|
</a-layout>
|
|
|
|
|
</a-layout>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-09-04 14:02:47 +08:00
|
|
|
|
import { InsuranceOutlined, HomeOutlined, SoundOutlined, MailOutlined, ApartmentOutlined, InboxOutlined, AppstoreOutlined } from '@ant-design/icons-vue'
|
2024-08-30 18:07:30 +08:00
|
|
|
|
import LayoutHeader from '@/components/layout/header/LayoutHeader.vue'
|
|
|
|
|
import { computed } from 'vue'
|
|
|
|
|
import { staticRouter } from '@/router/staticRouters'
|
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
const route = useRoute()
|
2024-08-29 17:06:00 +08:00
|
|
|
|
|
2024-08-30 18:07:30 +08:00
|
|
|
|
// 当前选中的菜单项
|
|
|
|
|
// const selectedKeys = computed(() => route.path)
|
2024-09-02 18:08:00 +08:00
|
|
|
|
|
2024-08-30 18:07:30 +08:00
|
|
|
|
const selectedKeys = computed(() => [route.path])
|
|
|
|
|
// 过滤出需要在菜单中显示的路由
|
2024-09-04 14:02:47 +08:00
|
|
|
|
// const menuRoutes = computed(() => staticRouter.filter((route) => route.meta && route.meta.title))
|
|
|
|
|
// staticRouter.forEach((element) => {
|
|
|
|
|
// console.log(element.meta?.title)
|
|
|
|
|
// })
|
2024-08-30 18:07:30 +08:00
|
|
|
|
|
|
|
|
|
// 示例:动态控制缓存页面的名称
|
|
|
|
|
// const keepAliveNames = ref(['index'])
|
2024-08-29 17:06:00 +08:00
|
|
|
|
|
2024-08-30 18:07:30 +08:00
|
|
|
|
import { ref } from 'vue'
|
2024-09-02 18:08:00 +08:00
|
|
|
|
// 控制菜单折叠
|
2024-08-30 18:07:30 +08:00
|
|
|
|
const collapsed = ref<boolean>(false)
|
|
|
|
|
|
2024-09-04 14:02:47 +08:00
|
|
|
|
// const keepAliveNames = ref<string[]>(['Index', 'Register'])
|
|
|
|
|
const keepAliveNames = ref<string[]>(['index', 'rindex'])
|
2024-08-29 17:06:00 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.main-content {
|
|
|
|
|
width: 100vw;
|
|
|
|
|
height: 100vh;
|
|
|
|
|
|
|
|
|
|
.layout-header {
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.layout-content {
|
|
|
|
|
margin: 10px;
|
|
|
|
|
padding: 4px;
|
|
|
|
|
background: #f5f7fd;
|
|
|
|
|
min-height: 280px;
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
overflow: auto;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.title {
|
|
|
|
|
height: 32px;
|
|
|
|
|
width: 168px;
|
|
|
|
|
transition: width 2ms linear 2ms;
|
|
|
|
|
margin: 16px;
|
|
|
|
|
color: black;
|
|
|
|
|
font-weight: bold;
|
2024-08-30 18:07:30 +08:00
|
|
|
|
font-size: 20px;
|
2024-08-29 17:06:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.logo {
|
|
|
|
|
margin: 16px;
|
|
|
|
|
|
|
|
|
|
img {
|
|
|
|
|
width: 50px;
|
2024-08-30 18:07:30 +08:00
|
|
|
|
height: 50px;
|
2024-08-29 17:06:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.site-layout .site-layout-background {
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
}
|
|
|
|
|
</style>
|