basic.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 { useAccessStore, useUserStore } from '@vben/stores';
  15. import { openWindow } from '@vben/utils';
  16. import { $t } from '#/locales';
  17. import { useAuthStore } from '#/store';
  18. import LoginForm from '#/views/_core/authentication/login.vue';
  19. const notifications = ref<NotificationItem[]>([
  20. {
  21. avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB',
  22. date: '3小时前',
  23. isRead: true,
  24. message: '描述信息描述信息描述信息',
  25. title: '收到了 14 份新周报',
  26. },
  27. {
  28. avatar: 'https://avatar.vercel.sh/1',
  29. date: '刚刚',
  30. isRead: false,
  31. message: '描述信息描述信息描述信息',
  32. title: '朱偏右 回复了你',
  33. },
  34. {
  35. avatar: 'https://avatar.vercel.sh/1',
  36. date: '2024-01-01',
  37. isRead: false,
  38. message: '描述信息描述信息描述信息',
  39. title: '曲丽丽 评论了你',
  40. },
  41. {
  42. avatar: 'https://avatar.vercel.sh/satori',
  43. date: '1天前',
  44. isRead: false,
  45. message: '描述信息描述信息描述信息',
  46. title: '代办提醒',
  47. },
  48. ]);
  49. const userStore = useUserStore();
  50. const authStore = useAuthStore();
  51. const accessStore = useAccessStore();
  52. const showDot = computed(() =>
  53. notifications.value.some((item) => !item.isRead),
  54. );
  55. const menus = computed(() => [
  56. {
  57. handler: () => {
  58. openWindow(VBEN_DOC_URL, {
  59. target: '_blank',
  60. });
  61. },
  62. icon: BookOpenText,
  63. text: $t('widgets.document'),
  64. },
  65. {
  66. handler: () => {
  67. openWindow(VBEN_GITHUB_URL, {
  68. target: '_blank',
  69. });
  70. },
  71. icon: MdiGithub,
  72. text: 'GitHub',
  73. },
  74. {
  75. handler: () => {
  76. openWindow(`${VBEN_GITHUB_URL}/issues`, {
  77. target: '_blank',
  78. });
  79. },
  80. icon: CircleHelp,
  81. text: $t('widgets.qa'),
  82. },
  83. ]);
  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. >
  122. <LoginForm />
  123. </AuthenticationLoginExpiredModal>
  124. </template>
  125. <template #lock-screen>
  126. <LockScreen :avatar @to-login="handleLogout" />
  127. </template>
  128. </BasicLayout>
  129. </template>