basic.vue 3.9 KB

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