login.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. await appStore.login(loginForm)
  21. } finally {
  22. loading.value = false
  23. }
  24. }
  25. </script>
  26. <template>
  27. <div class="w-[100vw] h-[100vh] px-20 flex items-center">
  28. <Background></Background>
  29. <div class="w-[400px]">
  30. <div class="text-4xl font-bold mb-12">欢迎到<br />布兰德后台管理系统</div>
  31. <div class="flex flex-col gap-6 mb-11">
  32. <TInput size="large" placeholder="账户" v-model="loginForm.username" clearable>
  33. <template #prefix-icon>
  34. <UserIcon></UserIcon>
  35. </template>
  36. </TInput>
  37. <TInput
  38. size="large"
  39. placeholder="密码"
  40. type="password"
  41. v-model="loginForm.password"
  42. clearable
  43. @enter="handleLogin"
  44. >
  45. <template #prefix-icon>
  46. <LockOnIcon></LockOnIcon>
  47. </template>
  48. </TInput>
  49. </div>
  50. <TButton size="large" :block="true" @click="handleLogin" :loading="loading">
  51. {{ loading ? '登录中' : '登录' }}
  52. </TButton>
  53. </div>
  54. </div>
  55. </template>
  56. <style scoped></style>