LoginPage.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="login-container">
  3. <el-card class="login-card">
  4. <div class="login-header">
  5. <h2>Welcome Back</h2>
  6. <p>Sign in to manage your AI characters</p>
  7. </div>
  8. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  9. <div class="form-label">Email Address</div>
  10. <el-form-item prop="username">
  11. <el-input v-model="loginForm.username" placeholder="admin@example.com">
  12. </el-input>
  13. </el-form-item>
  14. <div class="form-label">Password</div>
  15. <el-form-item prop="password">
  16. <el-input v-model="loginForm.password" type="password" placeholder="********">
  17. </el-input>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" @click="handleLogin" class="login-button">Login</el-button>
  21. </el-form-item>
  22. <div class="register-link">
  23. Don't have an account? <a href="#">Register</a>
  24. </div>
  25. </el-form>
  26. </el-card>
  27. </div>
  28. </template>
  29. <script>
  30. import { ElMessage } from 'element-plus'
  31. import { useStore } from '../store'
  32. export default {
  33. name: 'LoginPage',
  34. data() {
  35. return {
  36. loginForm: {
  37. username: '',
  38. password: ''
  39. },
  40. loginRules: {
  41. username: [
  42. { required: true, message: 'Please enter your email', trigger: 'blur' }
  43. ],
  44. password: [
  45. { required: true, message: 'Please enter your password', trigger: 'blur' }
  46. ]
  47. }
  48. }
  49. },
  50. methods: {
  51. handleLogin() {
  52. this.$refs.loginForm.validate((valid) => {
  53. if (valid) {
  54. const store = useStore()
  55. const { username, password } = this.loginForm
  56. if (store.login(username, password)) {
  57. ElMessage.success('Login successful')
  58. this.$router.push('/')
  59. } else {
  60. ElMessage.error('Invalid email or password')
  61. }
  62. }
  63. })
  64. }
  65. }
  66. }
  67. </script>
  68. <style scoped>
  69. .login-container {
  70. display: flex;
  71. justify-content: center;
  72. align-items: center;
  73. height: 100vh;
  74. background-color: #f0f2f5;
  75. }
  76. .login-card {
  77. width: 400px;
  78. border-radius: 8px;
  79. }
  80. .login-header {
  81. text-align: center;
  82. margin-bottom: 20px;
  83. }
  84. .login-header h2 {
  85. font-size: 24px;
  86. margin-bottom: 8px;
  87. }
  88. .login-header p {
  89. color: #606266;
  90. font-size: 14px;
  91. margin: 0;
  92. }
  93. .form-label {
  94. font-size: 14px;
  95. color: #606266;
  96. margin-bottom: 8px;
  97. }
  98. .login-button {
  99. width: 100%;
  100. height: 40px;
  101. border-radius: 4px;
  102. background-color: #ff6b00;
  103. border-color: #ff6b00;
  104. margin-top: 10px;
  105. }
  106. .login-button:hover {
  107. background-color: #e66000;
  108. border-color: #e66000;
  109. }
  110. .register-link {
  111. text-align: center;
  112. margin-top: 15px;
  113. font-size: 14px;
  114. }
  115. .register-link a {
  116. color: #ff6b00;
  117. text-decoration: none;
  118. }
  119. .register-link a:hover {
  120. text-decoration: underline;
  121. }
  122. :deep(.el-input__inner) {
  123. height: 40px;
  124. }
  125. :deep(.el-form-item) {
  126. margin-bottom: 20px;
  127. }
  128. </style>