basic.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <script lang="ts" setup>
  2. import type { NotificationItem } from '@vben/layouts';
  3. import { computed, ref } from 'vue';
  4. import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
  5. import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
  6. import { BookOpenText, CircleHelp, MdiGithub } from '@vben/icons';
  7. import {
  8. BasicLayout,
  9. LockScreen,
  10. Notification,
  11. UserDropdown,
  12. } from '@vben/layouts';
  13. import { preferences } from '@vben/preferences';
  14. import { storeToRefs, useAccessStore, useUserStore } from '@vben/stores';
  15. import { openWindow } from '@vben/utils';
  16. import { $t } from '#/locales';
  17. import { useAuthStore } from '#/store';
  18. const notifications = ref<NotificationItem[]>([
  19. {
  20. avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB',
  21. date: '3小时前',
  22. isRead: true,
  23. message: '描述信息描述信息描述信息',
  24. title: '收到了 14 份新周报',
  25. },
  26. {
  27. avatar: 'https://avatar.vercel.sh/1',
  28. date: '刚刚',
  29. isRead: false,
  30. message: '描述信息描述信息描述信息',
  31. title: '朱偏右 回复了你',
  32. },
  33. {
  34. avatar: 'https://avatar.vercel.sh/1',
  35. date: '2024-01-01',
  36. isRead: false,
  37. message: '描述信息描述信息描述信息',
  38. title: '曲丽丽 评论了你',
  39. },
  40. {
  41. avatar: 'https://avatar.vercel.sh/satori',
  42. date: '1天前',
  43. isRead: false,
  44. message: '描述信息描述信息描述信息',
  45. title: '代办提醒',
  46. },
  47. ]);
  48. const userStore = useUserStore();
  49. const authStore = useAuthStore();
  50. const accessStore = useAccessStore();
  51. const showDot = computed(() =>
  52. notifications.value.some((item) => !item.isRead),
  53. );
  54. const menus = computed(() => [
  55. {
  56. handler: () => {
  57. openWindow(VBEN_DOC_URL, {
  58. target: '_blank',
  59. });
  60. },
  61. icon: BookOpenText,
  62. text: $t('widgets.document'),
  63. },
  64. {
  65. handler: () => {
  66. openWindow(VBEN_GITHUB_URL, {
  67. target: '_blank',
  68. });
  69. },
  70. icon: MdiGithub,
  71. text: 'GitHub',
  72. },
  73. {
  74. handler: () => {
  75. openWindow(`${VBEN_GITHUB_URL}/issues`, {
  76. target: '_blank',
  77. });
  78. },
  79. icon: CircleHelp,
  80. text: $t('widgets.qa'),
  81. },
  82. ]);
  83. const { loginLoading } = storeToRefs(authStore);
  84. const avatar = computed(() => {
  85. return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
  86. });
  87. async function handleLogout() {
  88. await authStore.logout(false);
  89. }
  90. function handleNoticeClear() {
  91. notifications.value = [];
  92. }
  93. function handleMakeAll() {
  94. notifications.value.forEach((item) => (item.isRead = true));
  95. }
  96. </script>
  97. <template>
  98. <BasicLayout @clear-preferences-and-logout="handleLogout">
  99. <template #user-dropdown>
  100. <UserDropdown
  101. :avatar
  102. :menus
  103. :text="userStore.userInfo?.realName"
  104. description="ann.vben@gmail.com"
  105. tag-text="Pro"
  106. @logout="handleLogout"
  107. />
  108. </template>
  109. <template #notification>
  110. <Notification
  111. :dot="showDot"
  112. :notifications="notifications"
  113. @clear="handleNoticeClear"
  114. @make-all="handleMakeAll"
  115. />
  116. </template>
  117. <template #extra>
  118. <AuthenticationLoginExpiredModal
  119. v-model:open="accessStore.loginExpired"
  120. :avatar
  121. :loading="loginLoading"
  122. password-placeholder="123456"
  123. username-placeholder="vben"
  124. @submit="authStore.authLogin"
  125. />
  126. </template>
  127. <template #lock-screen>
  128. <LockScreen :avatar @to-login="handleLogout" />
  129. </template>
  130. </BasicLayout>
  131. </template>