qrcode-login.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <script setup lang="ts">
  2. import { ref } from 'vue';
  3. import { useRouter } from 'vue-router';
  4. import { $t } from '@vben/locales';
  5. import { VbenButton } from '@vben-core/shadcn-ui';
  6. import { useQRCode } from '@vueuse/integrations/useQRCode';
  7. import Title from './auth-title.vue';
  8. interface Props {
  9. /**
  10. * @zh_CN 是否处于加载处理状态
  11. */
  12. loading?: boolean;
  13. /**
  14. * @zh_CN 登录路径
  15. */
  16. loginPath?: string;
  17. /**
  18. * @zh_CN 标题
  19. */
  20. title?: string;
  21. /**
  22. * @zh_CN 描述
  23. */
  24. subTitle?: string;
  25. /**
  26. * @zh_CN 按钮文本
  27. */
  28. submitButtonText?: string;
  29. /**
  30. * @zh_CN 描述
  31. */
  32. description?: string;
  33. /**
  34. * @zh_CN 是否显示返回按钮
  35. */
  36. showBack?: boolean;
  37. }
  38. defineOptions({
  39. name: 'AuthenticationQrCodeLogin',
  40. });
  41. const props = withDefaults(defineProps<Props>(), {
  42. description: '',
  43. loading: false,
  44. showBack: true,
  45. loginPath: '/auth/login',
  46. submitButtonText: '',
  47. subTitle: '',
  48. title: '',
  49. });
  50. const router = useRouter();
  51. const text = ref('https://vben.vvbin.cn');
  52. const qrcode = useQRCode(text, {
  53. errorCorrectionLevel: 'H',
  54. margin: 4,
  55. });
  56. function goToLogin() {
  57. router.push(props.loginPath);
  58. }
  59. </script>
  60. <template>
  61. <div>
  62. <Title>
  63. <slot name="title">
  64. {{ title || $t('authentication.welcomeBack') }} 📱
  65. </slot>
  66. <template #desc>
  67. <span class="text-muted-foreground">
  68. <slot name="subTitle">
  69. {{ subTitle || $t('authentication.qrcodeSubtitle') }}
  70. </slot>
  71. </span>
  72. </template>
  73. </Title>
  74. <div class="flex-col-center mt-6">
  75. <img :src="qrcode" alt="qrcode" class="w-1/2" />
  76. <p class="text-muted-foreground mt-4 text-sm">
  77. <slot name="description">
  78. {{ description || $t('authentication.qrcodePrompt') }}
  79. </slot>
  80. </p>
  81. </div>
  82. <VbenButton
  83. v-if="showBack"
  84. class="mt-4 w-full"
  85. variant="outline"
  86. @click="goToLogin()"
  87. >
  88. {{ $t('common.back') }}
  89. </VbenButton>
  90. </div>
  91. </template>