1
0

basic.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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, MdiGithub } 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: MdiGithub,
  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. () => preferences.app.watermark,
  100. async (enable) => {
  101. if (enable) {
  102. await updateWatermark({
  103. content: `${userStore.userInfo?.username}`,
  104. });
  105. } else {
  106. destroyWatermark();
  107. }
  108. },
  109. {
  110. immediate: true,
  111. },
  112. );
  113. </script>
  114. <template>
  115. <BasicLayout @clear-preferences-and-logout="handleLogout">
  116. <template #user-dropdown>
  117. <UserDropdown
  118. :avatar
  119. :menus
  120. :text="userStore.userInfo?.realName"
  121. description="ann.vben@gmail.com"
  122. tag-text="Pro"
  123. @logout="handleLogout"
  124. />
  125. </template>
  126. <template #notification>
  127. <Notification
  128. :dot="showDot"
  129. :notifications="notifications"
  130. @clear="handleNoticeClear"
  131. @make-all="handleMakeAll"
  132. />
  133. </template>
  134. <template #extra>
  135. <AuthenticationLoginExpiredModal
  136. v-model:open="accessStore.loginExpired"
  137. :avatar
  138. >
  139. <LoginForm />
  140. </AuthenticationLoginExpiredModal>
  141. </template>
  142. <template #lock-screen>
  143. <LockScreen :avatar @to-login="handleLogout" />
  144. </template>
  145. </BasicLayout>
  146. </template>