HeaderLayout.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <script setup lang="ts">
  2. import type { ShallowRef } from 'vue'
  3. import auth from '@/api/auth'
  4. import NginxControl from '@/components/NginxControl/NginxControl.vue'
  5. import Notification from '@/components/Notification/Notification.vue'
  6. import SetLanguage from '@/components/SetLanguage/SetLanguage.vue'
  7. import SwitchAppearance from '@/components/SwitchAppearance/SwitchAppearance.vue'
  8. import { DesktopOutlined, HomeOutlined, LogoutOutlined, MenuUnfoldOutlined } from '@ant-design/icons-vue'
  9. import { message } from 'ant-design-vue'
  10. import { useRouter } from 'vue-router'
  11. const emit = defineEmits<{
  12. clickUnFold: [void]
  13. }>()
  14. const router = useRouter()
  15. function logout() {
  16. auth.logout().then(() => {
  17. message.success($gettext('Logout successful'))
  18. }).then(() => {
  19. router.push('/login')
  20. })
  21. }
  22. const headerRef = useTemplateRef('headerRef') as Readonly<ShallowRef<HTMLDivElement>>
  23. const isWorkspace = computed(() => {
  24. return !!window.inWorkspace
  25. })
  26. </script>
  27. <template>
  28. <div ref="headerRef" class="header">
  29. <div class="tool">
  30. <MenuUnfoldOutlined @click="emit('clickUnFold')" />
  31. </div>
  32. <div v-if="!isWorkspace" class="workspace-entry">
  33. <RouterLink to="/workspace">
  34. <ATooltip :title="$gettext('Workspace')">
  35. <DesktopOutlined />
  36. </ATooltip>
  37. </RouterLink>
  38. </div>
  39. <ASpace
  40. class="user-wrapper"
  41. :size="24"
  42. >
  43. <SetLanguage v-if="!isWorkspace" class="set_lang" />
  44. <SwitchAppearance />
  45. <Notification :header-ref="headerRef" />
  46. <NginxControl />
  47. <a href="/">
  48. <HomeOutlined />
  49. </a>
  50. <a v-if="!isWorkspace" @click="logout">
  51. <LogoutOutlined />
  52. </a>
  53. </ASpace>
  54. </div>
  55. </template>
  56. <style lang="less" scoped>
  57. .header {
  58. height: 64px;
  59. padding: 0 20px 0 0;
  60. background: transparent;
  61. box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.05);
  62. width: 100%;
  63. a {
  64. color: #000000;
  65. }
  66. }
  67. .dark {
  68. .header {
  69. box-shadow: 1px 1px 0 0 #404040;
  70. a {
  71. color: #fafafa;
  72. }
  73. }
  74. }
  75. .tool {
  76. position: absolute;
  77. left: 20px;
  78. @media (min-width: 600px) {
  79. display: none;
  80. }
  81. }
  82. .workspace-entry {
  83. position: absolute;
  84. left: 20px;
  85. @media (max-width: 600px) {
  86. display: none;
  87. }
  88. }
  89. .user-wrapper {
  90. position: absolute;
  91. right: 28px;
  92. }
  93. .set_lang {
  94. display: inline;
  95. }
  96. </style>