basic.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <script lang="ts" setup>
  2. import { computed, ref, toRefs } from 'vue';
  3. import { useRouter } from 'vue-router';
  4. import { LOGIN_PATH } from '@vben/constants';
  5. import { IcRoundCreditScore, MdiDriveDocument, MdiGithub } from '@vben/icons';
  6. import {
  7. BasicLayout,
  8. Notification,
  9. NotificationItem,
  10. UserDropdown,
  11. } from '@vben/layouts';
  12. import { AuthenticationLoginExpiredModal } from '@vben/universal-ui';
  13. import { openWindow } from '@vben/utils';
  14. import { preferences } from '@vben-core/preferences';
  15. import { $t } from '#/locales';
  16. import { resetRoutes } from '#/router';
  17. import { useAccessStore, useAppStore } 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 showDot = computed(() =>
  49. notifications.value.some((item) => !item.isRead),
  50. );
  51. const menus = computed(() => [
  52. {
  53. handler: () => {
  54. openWindow('https://github.com/vbenjs/vue-vben-admin', {
  55. target: '_blank',
  56. });
  57. },
  58. icon: MdiDriveDocument,
  59. text: $t('widgets.document'),
  60. },
  61. {
  62. handler: () => {
  63. openWindow('https://github.com/vbenjs/vue-vben-admin', {
  64. target: '_blank',
  65. });
  66. },
  67. icon: MdiGithub,
  68. text: 'GitHub',
  69. },
  70. {
  71. handler: () => {
  72. openWindow('https://github.com/vbenjs/vue-vben-admin/issues', {
  73. target: '_blank',
  74. });
  75. },
  76. icon: IcRoundCreditScore,
  77. text: $t('widgets.qa'),
  78. },
  79. ]);
  80. const appStore = useAppStore();
  81. const accessStore = useAccessStore();
  82. const {
  83. loading: loginLoading,
  84. openLoginExpiredModal,
  85. userInfo,
  86. } = toRefs(accessStore);
  87. const router = useRouter();
  88. async function handleLogout() {
  89. await appStore.resetAppState();
  90. resetRoutes();
  91. router.replace(LOGIN_PATH);
  92. }
  93. function handleNoticeClear() {
  94. notifications.value = [];
  95. }
  96. function handleMakeAll() {
  97. notifications.value.forEach((item) => (item.isRead = true));
  98. }
  99. </script>
  100. <template>
  101. <BasicLayout @clear-preferences-and-logout="handleLogout">
  102. <template #user-dropdown>
  103. <UserDropdown
  104. :avatar="userInfo?.avatar ?? preferences.app.defaultAvatar"
  105. :menus="menus"
  106. :text="userInfo?.realName"
  107. description="ann.vben@gmail.com"
  108. tag-text="Pro"
  109. @logout="handleLogout"
  110. />
  111. </template>
  112. <template #notification>
  113. <Notification
  114. :dot="showDot"
  115. :notifications="notifications"
  116. @clear="handleNoticeClear"
  117. @make-all="handleMakeAll"
  118. />
  119. </template>
  120. <template #dialog>
  121. <AuthenticationLoginExpiredModal
  122. v-model:open="openLoginExpiredModal"
  123. :loading="loginLoading"
  124. password-placeholder="123456"
  125. username-placeholder="vben"
  126. @submit="accessStore.authLogin"
  127. />
  128. </template>
  129. </BasicLayout>
  130. </template>