header.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. localStorage.removeItem('token_a');
  54. router.push('/');
  55. message.success($t('auth.logOutOK'));
  56. },
  57. onCancel() {},
  58. });
  59. }
  60. function handleClick(path: string) {
  61. window.open(path, '_blank');
  62. }
  63. function handleHome() {
  64. router.push('/');
  65. }
  66. watch(
  67. () => isLogin.value,
  68. (newValue) => {
  69. menuList.value = newValue
  70. ? [
  71. { key: 'Logout', label: $t('auth.logout') },
  72. { key: 'ChangeInformation', label: $t('auth.changeInformation') },
  73. ]
  74. : [];
  75. },
  76. { immediate: true },
  77. );
  78. </script>
  79. <template>
  80. <div class="mb-[32px] flex items-center justify-between">
  81. <img
  82. :src="Logo"
  83. alt="logo"
  84. class="logo"
  85. height="30px"
  86. width="138px"
  87. @click="handleHome"
  88. />
  89. <ul class="menu flex gap-[60px] text-xs">
  90. <li
  91. v-for="menuItem in menus"
  92. :key="menuItem.title"
  93. class="flex items-center gap-2"
  94. @click="handleClick(menuItem.path)"
  95. >
  96. <span>{{ menuItem.title }}</span>
  97. <SvgArrowRightIcon class="arrow size-2" />
  98. </li>
  99. </ul>
  100. <div class="flex gap-2">
  101. <SelectLang />
  102. <Dropdown
  103. v-if="isLogin"
  104. :menu="{
  105. items: menuList,
  106. }"
  107. placement="bottom"
  108. @menu-click="(info: any) => handleMenuClick(info)"
  109. >
  110. <img
  111. v-if="userStore.userInfo?.avatar"
  112. :src="`/File/Download?fileId=${userStore.userInfo?.avatar}`"
  113. class="cursor-pointer"
  114. @click="openLogin"
  115. />
  116. <img
  117. v-else
  118. :avatar="useAvatar"
  119. class="cursor-pointer"
  120. @click="openLogin"
  121. />
  122. </Dropdown>
  123. </div>
  124. </div>
  125. </template>
  126. <style lang="scss" scoped>
  127. .logo {
  128. cursor: pointer;
  129. }
  130. .menu li {
  131. color: #462424;
  132. cursor: pointer;
  133. &:hover {
  134. color: #7a003d;
  135. :deep(path) {
  136. fill: #7a003d;
  137. }
  138. }
  139. }
  140. .cursor-pointer {
  141. width: 24px;
  142. height: 24px;
  143. overflow: hidden;
  144. border: none;
  145. border-color: transparent;
  146. border-radius: 50%;
  147. }
  148. </style>