index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div class="login">
  3. <div class="form-box">
  4. <div class="title">
  5. 后台管理系统
  6. </div>
  7. <a-form
  8. class="form"
  9. :model="loginState"
  10. :rules="rules"
  11. @finish="finishHandle"
  12. @finishFailed="finishFailedHandle"
  13. >
  14. <a-form-item
  15. name="username"
  16. class="form-item"
  17. >
  18. <a-input
  19. v-model:value="loginState.username"
  20. placeholder="用户名"
  21. size="large"
  22. >
  23. <template #prefix>
  24. <user-outlined style="color: rgba(0, 0, 0, 0.25)" />
  25. </template>
  26. </a-input>
  27. </a-form-item>
  28. <a-form-item
  29. name="password"
  30. class="form-item"
  31. >
  32. <a-input
  33. v-model:value="loginState.password"
  34. type="password"
  35. placeholder="密码"
  36. size="large"
  37. >
  38. <template #prefix>
  39. <lock-outlined style="color: rgba(0, 0, 0, 0.25)" />
  40. </template>
  41. </a-input>
  42. </a-form-item>
  43. <a-form-item>
  44. <a-button
  45. class="form-submit"
  46. type="primary"
  47. html-type="submit"
  48. size="large"
  49. >
  50. 登录
  51. </a-button>
  52. </a-form-item>
  53. </a-form>
  54. </div>
  55. </div>
  56. </template>
  57. <script lang="ts" setup>
  58. import { reactive, ref } from 'vue';
  59. import { EnumPage } from '@/router/base';
  60. import { useRouter } from 'vue-router';
  61. import { message } from 'ant-design-vue'
  62. import { useLocalStorage } from '@vueuse/core'
  63. import type { UnwrapRef } from 'vue';
  64. import type { FormProps } from 'ant-design-vue';
  65. import { AppStore } from '@/store/modules/app'
  66. const router = useRouter()
  67. const store = AppStore()
  68. interface loginState {
  69. username: string
  70. password: string
  71. }
  72. const loginState: UnwrapRef<loginState> = reactive({
  73. username: '',
  74. password: ''
  75. })
  76. const rules = {
  77. username: [
  78. {
  79. required: true,
  80. message: '请输入用户名',
  81. whitespace: true,
  82. trigger: 'blur'
  83. }
  84. ],
  85. password: [
  86. {
  87. required: true,
  88. message: '请输入密码',
  89. whitespace: true,
  90. trigger: 'blur'
  91. }
  92. ]
  93. }
  94. const finishHandle: FormProps['onFinish'] = (values: loginState) => {
  95. const { username, password } = values
  96. if (username === 'admin' && password === '123') {
  97. router.push(EnumPage.App).then(() => store.updateIsLogin(true))
  98. } else {
  99. message.error('用户名或密码错误')
  100. }
  101. }
  102. const finishFailedHandle: FormProps['onFinishFailed'] = (errors) => {
  103. console.log(errors);
  104. }
  105. </script>
  106. <style lang="less" scoped>
  107. .login {
  108. height: 100%;
  109. background: url('/images/login_bg.jpeg') center/cover no-repeat;
  110. display: flex;
  111. justify-content: center;
  112. align-items: center;
  113. .form-box {
  114. background-color: rgba(255, 255, 255, .8);
  115. height: 460px;
  116. width: 400px;
  117. border-radius: 12px;
  118. padding: 60px 40px;
  119. .title {
  120. text-align: center;
  121. font-size: 26px;
  122. font-weight: 500;
  123. }
  124. .form {
  125. margin-top: 40px;
  126. .form-item {
  127. margin-bottom: 40px;
  128. }
  129. .form-submit {
  130. width: 180px;
  131. }
  132. // 修复表单错误提示出现时的显示异常
  133. :deep(.ant-form-item-with-help) {
  134. margin-bottom: 16px;
  135. }
  136. // 登录按钮居中
  137. :deep(.ant-form-item-control-input-content) {
  138. text-align: center;
  139. }
  140. }
  141. }
  142. }
  143. </style>