index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="login-container">
  3. <!-- 顶部 -->
  4. <div class="lang">
  5. <LangSelect class="cursor-pointer"></LangSelect>
  6. </div>
  7. <!-- 登录表单 -->
  8. <el-card class="card">
  9. <div class="text">
  10. <h2>{{ $t('login.title') }}</h2>
  11. </div>
  12. <el-form ref="loginFormRef" :model="loginData" :rules="loginRules" class="login-form">
  13. <!-- 用户名 -->
  14. <el-form-item prop="username">
  15. <el-input v-model="loginData.account" size="large" :placeholder="$t('login.placeholder1')">
  16. <template #prefix>
  17. <el-icon>
  18. <User />
  19. </el-icon>
  20. </template>
  21. </el-input>
  22. </el-form-item>
  23. <!-- 密码 -->
  24. <el-form-item prop="password">
  25. <el-input v-model="loginData.password" size="large" type="password" show-password :placeholder="$t('login.placeholder2')">
  26. <template #prefix>
  27. <el-icon>
  28. <Unlock />
  29. </el-icon>
  30. </template>
  31. </el-input>
  32. </el-form-item>
  33. <!-- 登录按钮 -->
  34. <el-button :loading="loading" type="primary" size="large" class="button" @click.prevent="handleLogin">{{ $t('login.login') }} </el-button>
  35. </el-form>
  36. </el-card>
  37. </div>
  38. </template>
  39. <script setup>
  40. // 接口
  41. import { LoginStore } from '@/store/api/login'
  42. const router = useRouter()
  43. const loginStore = LoginStore()
  44. const loading = ref(false) // 按钮loading
  45. const loginFormRef = ref({}) // 登录表单ref
  46. const loginData = ref({
  47. account: 'admin',
  48. password: '1qaz2wsx',
  49. type: 'Admin'
  50. })
  51. const loginRules = computed(() => {})
  52. const toLogin = async (data) => {
  53. const res = await loginStore.login(data)
  54. if (res.errcode == '0') {
  55. ElMessage({ message: `登录成功`, type: 'success' })
  56. localStorage.setItem('token', res.data)
  57. // 路由
  58. router.push({ path: '/' })
  59. } else {
  60. ElMessage({ message: `${res.errmsg}`, type: 'error' })
  61. }
  62. loading.value = false
  63. }
  64. /**
  65. * 登录
  66. */
  67. function handleLogin() {
  68. loginFormRef.value.validate((valid) => {
  69. if (valid) {
  70. loading.value = true
  71. toLogin(loginData.value)
  72. }
  73. })
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. .login-container {
  78. overflow-y: auto;
  79. width: 100%;
  80. height: 100%;
  81. display: flex;
  82. align-items: center;
  83. justify-content: center;
  84. background: url('@/assets/images/login-bg.jpg') no-repeat center right;
  85. .lang {
  86. display: flex;
  87. align-items: center;
  88. justify-content: flex-end;
  89. position: absolute;
  90. top: 0;
  91. right: 0;
  92. height: 5rem;
  93. padding: 0 1.25rem;
  94. }
  95. .login-form {
  96. padding: 30px 10px;
  97. }
  98. .card {
  99. width: 400px;
  100. height: 450px;
  101. border-radius: 15px;
  102. padding: 20px;
  103. box-shadow: var(--el-box-shadow-light);
  104. background: transparent;
  105. .text {
  106. text-align: center;
  107. }
  108. .button {
  109. width: 100%;
  110. }
  111. }
  112. }
  113. .el-form-item {
  114. background: var(--el-input-bg-color);
  115. border: 1px solid var(--el-border-color);
  116. border-radius: 5px;
  117. }
  118. :deep(.el-input) {
  119. padding: 5px;
  120. .el-input__wrapper {
  121. padding: 0;
  122. background-color: transparent;
  123. box-shadow: none;
  124. &.is-focus,
  125. &:hover {
  126. box-shadow: none !important;
  127. }
  128. input:-webkit-autofill {
  129. /* 通过延时渲染背景色变相去除背景颜色 */
  130. transition: background-color 1000s ease-in-out 0s;
  131. }
  132. }
  133. }
  134. </style>