header.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <script setup lang="ts">
  2. import { computed, ref, watch } from 'vue';
  3. import { SvgArrowRightIcon } from '@vben/icons';
  4. import { useAccessStore, useUserStore } from '@vben/stores';
  5. import useAvatar from '@/assets/image/user.png';
  6. import { $t } from '@/locales';
  7. import { Dropdown, message, Modal } from 'antdv-next';
  8. import Logo from '#/assets/image/logo.png';
  9. import { router } from '#/router';
  10. import SelectLang from '../select-lang.vue';
  11. const userStore = useUserStore();
  12. const accessStore = useAccessStore();
  13. const token = accessStore.accessToken;
  14. const isLogin = computed(() => !!userStore.userInfo);
  15. const menus = computed(() => [
  16. { title: $t('homeMenu.toolDownloads'), path: '/Views/Tools/Index.html' },
  17. {
  18. title: $t('homeMenu.aIGeneratedApps'),
  19. path: '/Views/Designer/AIGenerateApp.html',
  20. },
  21. {
  22. title: $t('homeMenu.aIAssistants'),
  23. path: '/Views/Designer/AIAssistant.html',
  24. },
  25. {
  26. title: $t('homeMenu.shaluAcademy'),
  27. path: `/Views/Account/SSOIndex.html?system=design&token=${token}`,
  28. },
  29. {
  30. title: $t('homeMenu.applicationMarket'),
  31. path: '/Views/Designer/systemAppStore.html?tab=application',
  32. },
  33. ]);
  34. const menuList = ref();
  35. function openLogin() {}
  36. function handleMenuClick({ key }: { key: string }) {
  37. if (key === 'Logout') {
  38. handleLogout();
  39. } else if (key === 'ChangeInformation') {
  40. window.open('/Views/Home/userSet.html', '_blank');
  41. }
  42. }
  43. function handleLogout() {
  44. Modal.confirm({
  45. title: $t('auth.logOut.title'),
  46. content: $t('auth.logOut.value'),
  47. okText: $t('btn.yes'),
  48. okType: 'danger',
  49. cancelText: $t('btn.no'),
  50. onOk() {
  51. userStore.setUserInfo(null);
  52. accessStore.setAccessToken(null);
  53. router.push('/');
  54. message.success($t('auth.logOutOK'));
  55. },
  56. onCancel() {},
  57. });
  58. }
  59. function handleClick(path: string) {
  60. window.open(path, '_blank');
  61. }
  62. watch(
  63. () => isLogin.value,
  64. (newValue) => {
  65. menuList.value = newValue
  66. ? [
  67. { key: 'Logout', label: $t('auth.logout') },
  68. { key: 'ChangeInformation', label: $t('auth.changeInformation') },
  69. ]
  70. : [];
  71. },
  72. { immediate: true },
  73. );
  74. </script>
  75. <template>
  76. <div class="mb-[32px] flex items-center justify-between">
  77. <img :src="Logo" alt="logo" class="logo" height="30px" width="138px" />
  78. <ul class="menu flex gap-[60px] text-xs">
  79. <li
  80. v-for="menuItem in menus"
  81. :key="menuItem.title"
  82. class="flex items-center gap-2"
  83. @click="handleClick(menuItem.path)"
  84. >
  85. <span>{{ menuItem.title }}</span>
  86. <SvgArrowRightIcon class="arrow size-2" />
  87. </li>
  88. </ul>
  89. <div class="flex gap-2">
  90. <SelectLang />
  91. <Dropdown
  92. :menu="{
  93. items: menuList,
  94. }"
  95. placement="bottom"
  96. @menu-click="(info: any) => handleMenuClick(info)"
  97. >
  98. <img
  99. v-if="userStore.userInfo?.avatar"
  100. :src="`/File/Download?fileId=${userStore.userInfo?.avatar}`"
  101. class="cursor-pointer"
  102. @click="openLogin"
  103. />
  104. <img
  105. v-else
  106. :avatar="useAvatar"
  107. class="cursor-pointer"
  108. @click="openLogin"
  109. />
  110. </Dropdown>
  111. </div>
  112. </div>
  113. </template>
  114. <style lang="scss" scoped>
  115. .logo {
  116. cursor: pointer;
  117. }
  118. .menu li {
  119. color: #462424;
  120. cursor: pointer;
  121. &:hover {
  122. color: #7a003d;
  123. :deep(path) {
  124. fill: #7a003d;
  125. }
  126. }
  127. }
  128. .cursor-pointer {
  129. width: 24px;
  130. height: 24px;
  131. overflow: hidden;
  132. border: none;
  133. border-color: transparent;
  134. border-radius: 50%;
  135. }
  136. </style>