qrcode-login.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <script setup lang="ts">
  2. import { ref } from 'vue';
  3. import { useRouter } from 'vue-router';
  4. import { LOGIN_PATH } from '@vben/constants';
  5. import { $t } from '@vben-core/locales';
  6. import { VbenButton } from '@vben-core/shadcn-ui';
  7. import { useQRCode } from '@vueuse/integrations/useQRCode';
  8. import Title from './auth-title.vue';
  9. interface Props {
  10. /**
  11. * @zh_CN 是否处于加载处理状态
  12. */
  13. loading?: boolean;
  14. /**
  15. * @zh_CN 登陆路径
  16. */
  17. loginPath?: string;
  18. }
  19. defineOptions({
  20. name: 'AuthenticationQrCodeLogin',
  21. });
  22. const props = withDefaults(defineProps<Props>(), {
  23. loading: false,
  24. loginPath: LOGIN_PATH,
  25. });
  26. const router = useRouter();
  27. const text = ref('https://vben.vvbin.cn');
  28. const qrcode = useQRCode(text, {
  29. errorCorrectionLevel: 'H',
  30. margin: 4,
  31. });
  32. function goLogin() {
  33. router.push(props.loginPath);
  34. }
  35. </script>
  36. <template>
  37. <div>
  38. <Title>
  39. {{ $t('authentication.welcomeBack') }} 📱
  40. <template #desc>
  41. <span class="text-muted-foreground">
  42. {{ $t('authentication.qrcodeSubtitle') }}
  43. </span>
  44. </template>
  45. </Title>
  46. <div class="flex-col-center mt-6">
  47. <img :src="qrcode" alt="qrcode" class="w-1/2" />
  48. <p class="text-muted-foreground mt-4 text-sm">
  49. {{ $t('authentication.qrcodePrompt') }}
  50. </p>
  51. </div>
  52. <VbenButton class="mt-4 w-full" variant="outline" @click="goLogin()">
  53. {{ $t('common.back') }}
  54. </VbenButton>
  55. </div>
  56. </template>