login.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <script setup lang="ts">
  2. import Background from '@/pages/common/components/Background.vue'
  3. import { LockOnIcon, UserIcon } from 'tdesign-icons-vue-next'
  4. import { reactive, ref } from 'vue'
  5. import type { CreateTokenRequest } from '@/model/token'
  6. import { MessagePlugin } from 'tdesign-vue-next'
  7. import { useAppStore } from '@/stores/app'
  8. const loginForm = reactive<CreateTokenRequest>({
  9. password: '',
  10. username: ''
  11. })
  12. const loading = ref(false)
  13. const appStore = useAppStore()
  14. const handleLogin = async () => {
  15. if (!loginForm.username || !loginForm.password) {
  16. MessagePlugin.error('用户名或密码不能为空')
  17. return
  18. }
  19. try {
  20. loading.value = true
  21. await appStore.login(loginForm)
  22. } finally {
  23. loading.value = false
  24. }
  25. }
  26. </script>
  27. <template>
  28. <div class="w-[100vw] h-[100vh] px-20 flex items-center">
  29. <Background></Background>
  30. <div class="w-[400px]">
  31. <div class="text-4xl font-bold mb-12">欢迎到<br />布兰德后台管理系统</div>
  32. <div class="flex flex-col gap-6 mb-11">
  33. <TInput size="large" placeholder="账户" v-model="loginForm.username" clearable>
  34. <template #prefix-icon>
  35. <UserIcon></UserIcon>
  36. </template>
  37. </TInput>
  38. <TInput
  39. size="large"
  40. placeholder="密码"
  41. type="password"
  42. v-model="loginForm.password"
  43. clearable
  44. @enter="handleLogin"
  45. >
  46. <template #prefix-icon>
  47. <LockOnIcon></LockOnIcon>
  48. </template>
  49. </TInput>
  50. </div>
  51. <TButton size="large" :block="true" @click="handleLogin" :loading="loading">
  52. {{ loading ? '登录中' : '登录' }}
  53. </TButton>
  54. </div>
  55. </div>
  56. </template>
  57. <style scoped></style>