| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <template>
- <a-layout-header class="header" :style="{backgroundColor: headerBgColor}">
- <a-row >
- <a-col :span="18" >
- <a-menu
- mode="horizontal"
- :style="{ lineHeight: '64px', border: 'none' }"
- :selectedKeys="selectedKeys"
- >
- <a-menu-item
- v-for="route in appRouter.$state.router.navbar.route"
- :key="route.path"
- @click="changeRouter(route)"
- >
- {{route.name}}
- </a-menu-item>
- </a-menu>
- </a-col>
- <a-col :span="4" >
- <a-row :gutter="[8, 8]" justify="end" >
- <a-col class="df-center" >
- <a-button type="text" @click="changeTheme" > <IconTsx :name="iconName" /></a-button>
- </a-col>
- <a-col class="df-center" >
- <user />
- </a-col>
- </a-row>
- </a-col>
- </a-row>
- </a-layout-header>
- </template>
- <script lang="ts" setup >
- import { computed, onMounted, ref } from 'vue'
- import { useAppRouter } from '@/store/router'
- import user from './user.vue'
- import { useRouter, useRoute } from 'vue-router'
- import { routes } from '@/router/index'
- import { IconTsx } from '@/components/MicroComponents/index'
- import { useDesignStore } from '@/store'
- const logoPng = require('@/assets/logo.png')
- const router = useRouter()
- const route = useRoute()
- const appRouter = useAppRouter()
- const selectedKeys = ref<string[]>()
- const designStore = useDesignStore()
- console.log('designStore:', !!designStore.theme, designStore.theme)
- const iconName = computed(() => designStore.theme ? 'sun' : 'moon')
- const headerBgColor = computed(() => designStore.theme ? '#141414' : '#fff')
- const changeTheme = () => {
- designStore.changeModeltheme()
- }
- const changeRouter = (route: ROUTER.RoutesProps) => {
- if (route.link) {
- window.open(route.path)
- } else {
- selectedKeys.value = [route.path]
- appRouter.changeNavbar(route.path, '')
- }
- }
- const hasCurrentRourte = (children: ROUTER.RoutesProps[]): boolean => {
- let r = false
- children.forEach(item => {
- if (item.path === route.path) {
- r = true
- }
- if (item.children && item.children.length) {
- item.children.forEach(_ => {
- if (_.path === route.path) {
- r = true
- }
- })
- }
- })
- return r
- }
- onMounted(() => {
- routes.forEach(item => {
- if (item.children && hasCurrentRourte(item.children)) {
- selectedKeys.value = [item.path]
- appRouter.changeNavbar(item.path, 'init')
- appRouter.changeSiderRoute()
- }
- })
- })
- </script>
- <style lang="less" scoped >
- .header {
- // width: 100%;
- // position: absolute;
- // z-index: 2;
- // background-color: #fff;
- }
- .df-center {
- display: flex;
- justify-content: center;
- align-items: center;
- }
- </style>
|