index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div class="relative flex-center wh-full" :style="{ backgroundColor: bgColor }">
  3. <dark-mode-switch
  4. :dark="theme.darkMode"
  5. class="absolute left-48px top-24px z-3 text-20px"
  6. @update:dark="theme.setDarkMode"
  7. />
  8. <n-card :bordered="false" size="large" class="z-4 !w-auto rounded-20px shadow-sm">
  9. <div class="w-300px sm:w-360px">
  10. <header class="flex-y-center justify-between">
  11. <system-logo class="text-64px text-primary" />
  12. <n-gradient-text type="primary" :size="28">{{ title }}</n-gradient-text>
  13. </header>
  14. <main class="pt-24px">
  15. <h3 class="text-18px text-primary font-medium">{{ activeModule.label }}</h3>
  16. <div class="pt-24px">
  17. <transition name="fade-slide" mode="out-in" appear>
  18. <div>
  19. <component :is="activeModule.component" />
  20. </div>
  21. </transition>
  22. </div>
  23. </main>
  24. </div>
  25. </n-card>
  26. <login-bg :theme-color="bgThemeColor" />
  27. </div>
  28. </template>
  29. <script setup lang="ts">
  30. import { computed } from 'vue';
  31. import type { Component } from 'vue';
  32. import { loginModuleLabels } from '@/constants';
  33. import { useThemeStore } from '@/store';
  34. import { useAppInfo } from '@/composables';
  35. import { getColorPalette, mixColor } from '@/utils';
  36. import { LoginBg, PwdLogin } from './components';
  37. interface Props {
  38. /** 登录模块分类 */
  39. module: UnionKey.LoginModule;
  40. }
  41. const props = defineProps<Props>();
  42. const theme = useThemeStore();
  43. const { title } = useAppInfo();
  44. interface LoginModule {
  45. key: string;
  46. label: string;
  47. component: Component;
  48. }
  49. const modules: LoginModule[] = [{ key: 'pwd-login', label: loginModuleLabels['pwd-login'], component: PwdLogin }];
  50. const activeModule = computed(() => {
  51. const active: LoginModule = { ...modules[0] };
  52. const findItem = modules.find(item => item.key === props.module);
  53. if (findItem) {
  54. Object.assign(active, findItem);
  55. }
  56. return active;
  57. });
  58. const bgThemeColor = computed(() => (theme.darkMode ? getColorPalette(theme.themeColor, 7) : theme.themeColor));
  59. const bgColor = computed(() => {
  60. const COLOR_WHITE = '#ffffff';
  61. const ratio = theme.darkMode ? 0.5 : 0.2;
  62. return mixColor(COLOR_WHITE, theme.themeColor, ratio);
  63. });
  64. </script>
  65. <style scoped></style>