basic.vue 3.9 KB

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