navbar.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <a-layout-header class="header" :style="{backgroundColor: headerBgColor}">
  3. <a-row >
  4. <a-col :span="18" >
  5. <a-menu
  6. mode="horizontal"
  7. :style="{ lineHeight: '64px', border: 'none' }"
  8. :selectedKeys="selectedKeys"
  9. >
  10. <a-menu-item
  11. v-for="route in appRouter.$state.router.navbar.route"
  12. :key="route.path"
  13. @click="changeRouter(route)"
  14. >
  15. {{route.name}}
  16. </a-menu-item>
  17. </a-menu>
  18. </a-col>
  19. <a-col :span="4" >
  20. <a-row :gutter="[8, 8]" justify="end" >
  21. <a-col class="df-center" >
  22. <a-button type="text" @click="changeTheme" > <IconTsx :name="iconName" /></a-button>
  23. </a-col>
  24. <a-col class="df-center" >
  25. <user />
  26. </a-col>
  27. </a-row>
  28. </a-col>
  29. </a-row>
  30. </a-layout-header>
  31. </template>
  32. <script lang="ts" setup >
  33. import { computed, ref } from 'vue'
  34. import { useAppRouter } from '@/store/router'
  35. import user from './user.vue'
  36. import { useRoute, useRouter } from 'vue-router'
  37. import { IconTsx } from '@/components/MicroComponents/index'
  38. import { useDesignStore } from '@/store'
  39. const route = useRoute()
  40. const router = useRouter()
  41. const appRouter = useAppRouter()
  42. const selectedKeys = ref<string[]>([route.matched[0].path])
  43. const designStore = useDesignStore()
  44. const iconName = computed(() => designStore.theme ? 'sun' : 'moon')
  45. const headerBgColor = computed(() => designStore.theme ? '#141414' : '#fff')
  46. const changeTheme = () => {
  47. designStore.changeModeltheme()
  48. }
  49. const changeRouter = (route: ROUTER.RoutesProps) => {
  50. if (route.link) {
  51. window.open(route.path)
  52. } else {
  53. selectedKeys.value = [route.path]
  54. router.push(route.path)
  55. }
  56. }
  57. </script>
  58. <style lang="less" scoped >
  59. .df-center {
  60. display: flex;
  61. justify-content: center;
  62. align-items: center;
  63. }
  64. </style>