authentication.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <script setup lang="ts">
  2. import type { ToolbarType } from './types';
  3. import { computed } from 'vue';
  4. import { preferences, usePreferences } from '@vben/preferences';
  5. import { Copyright } from '../basic/copyright';
  6. import AuthenticationFormView from './form.vue';
  7. import SloganIcon from './icons/slogan.vue';
  8. import Toolbar from './toolbar.vue';
  9. interface Props {
  10. appName?: string;
  11. logo?: string;
  12. logoDark?: string;
  13. pageTitle?: string;
  14. pageDescription?: string;
  15. sloganImage?: string;
  16. toolbar?: boolean;
  17. copyright?: boolean;
  18. toolbarList?: ToolbarType[];
  19. clickLogo?: () => void;
  20. }
  21. const props = withDefaults(defineProps<Props>(), {
  22. appName: '',
  23. copyright: true,
  24. logo: '',
  25. logoDark: '',
  26. pageDescription: '',
  27. pageTitle: '',
  28. sloganImage: '',
  29. toolbar: true,
  30. toolbarList: () => ['color', 'language', 'layout', 'theme'],
  31. clickLogo: () => {},
  32. });
  33. const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
  34. usePreferences();
  35. /**
  36. * @zh_CN 根据主题选择合适的 logo 图标
  37. */
  38. const logoSrc = computed(() => {
  39. // 如果是暗色主题且提供了 logoDark,则使用暗色主题的 logo
  40. if (isDark.value && props.logoDark) {
  41. return props.logoDark;
  42. }
  43. // 否则使用默认的 logo
  44. return props.logo;
  45. });
  46. </script>
  47. <template>
  48. <div
  49. :class="[isDark ? 'dark' : '']"
  50. class="flex min-h-full flex-1 overflow-x-hidden select-none"
  51. >
  52. <template v-if="toolbar">
  53. <slot name="toolbar">
  54. <Toolbar :toolbar-list="toolbarList" />
  55. </slot>
  56. </template>
  57. <!-- 左侧认证面板 -->
  58. <AuthenticationFormView
  59. v-if="authPanelLeft"
  60. class="min-h-full w-2/5 flex-1"
  61. data-side="left"
  62. >
  63. <template v-if="copyright" #copyright>
  64. <slot name="copyright">
  65. <Copyright
  66. v-if="preferences.copyright.enable"
  67. v-bind="preferences.copyright"
  68. />
  69. </slot>
  70. </template>
  71. </AuthenticationFormView>
  72. <slot name="logo">
  73. <!-- 头部 Logo 和应用名称 -->
  74. <div
  75. v-if="logoSrc || appName"
  76. class="absolute top-0 left-0 z-10 flex flex-1"
  77. @click="clickLogo"
  78. >
  79. <div
  80. class="mt-4 ml-4 flex flex-1 items-center text-foreground sm:top-6 sm:left-6 lg:text-foreground"
  81. >
  82. <img
  83. v-if="logoSrc"
  84. :key="logoSrc"
  85. :alt="appName"
  86. :src="logoSrc"
  87. class="mr-2"
  88. width="42"
  89. />
  90. <p v-if="appName" class="m-0 text-xl font-medium">
  91. {{ appName }}
  92. </p>
  93. </div>
  94. </div>
  95. </slot>
  96. <!-- 系统介绍 -->
  97. <div v-if="!authPanelCenter" class="relative hidden w-0 flex-1 lg:block">
  98. <div
  99. class="absolute inset-0 size-full bg-background-deep dark:bg-[#070709]"
  100. >
  101. <div class="login-background absolute top-0 left-0 size-full"></div>
  102. <div
  103. :key="authPanelLeft ? 'left' : authPanelRight ? 'right' : 'center'"
  104. class="mr-20 flex-col-center h-full"
  105. :class="{
  106. 'enter-x': authPanelLeft,
  107. '-enter-x': authPanelRight,
  108. }"
  109. >
  110. <template v-if="sloganImage">
  111. <img
  112. :alt="appName"
  113. :src="sloganImage"
  114. class="h-64 w-2/5 animate-float"
  115. />
  116. </template>
  117. <SloganIcon v-else :alt="appName" class="h-64 w-2/5 animate-float" />
  118. <div class="text-1xl mt-6 font-sans text-foreground lg:text-2xl">
  119. {{ pageTitle }}
  120. </div>
  121. <div class="mt-2 dark:text-muted-foreground">
  122. {{ pageDescription }}
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. <!-- 中心认证面板 -->
  128. <div v-if="authPanelCenter" class="relative flex-center w-full">
  129. <div class="login-background absolute top-0 left-0 size-full"></div>
  130. <AuthenticationFormView
  131. class="w-full rounded-3xl pb-20 shadow-float shadow-primary/5 md:w-2/3 md:bg-background lg:w-1/2 xl:w-[36%]"
  132. data-side="bottom"
  133. >
  134. <template v-if="copyright" #copyright>
  135. <slot name="copyright">
  136. <Copyright
  137. v-if="preferences.copyright.enable"
  138. v-bind="preferences.copyright"
  139. />
  140. </slot>
  141. </template>
  142. </AuthenticationFormView>
  143. </div>
  144. <!-- 右侧认证面板 -->
  145. <AuthenticationFormView
  146. v-if="authPanelRight"
  147. class="min-h-full w-2/5 flex-1"
  148. data-side="right"
  149. >
  150. <template v-if="copyright" #copyright>
  151. <slot name="copyright">
  152. <Copyright
  153. v-if="preferences.copyright.enable"
  154. v-bind="preferences.copyright"
  155. />
  156. </slot>
  157. </template>
  158. </AuthenticationFormView>
  159. </div>
  160. </template>
  161. <style scoped>
  162. .login-background {
  163. background: linear-gradient(
  164. 154deg,
  165. #07070915 30%,
  166. hsl(var(--primary) / 30%) 48%,
  167. #07070915 64%
  168. );
  169. filter: blur(100px);
  170. }
  171. .dark {
  172. .login-background {
  173. background: linear-gradient(
  174. 154deg,
  175. #07070915 30%,
  176. hsl(var(--primary) / 20%) 48%,
  177. #07070915 64%
  178. );
  179. filter: blur(100px);
  180. }
  181. }
  182. </style>