Login.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <script setup lang="ts">
  2. const thisYear = new Date().getFullYear()
  3. import app from '@/main'
  4. import {UserOutlined, LockOutlined} from '@ant-design/icons-vue'
  5. import {reactive, ref} from 'vue'
  6. import {useRouter, useRoute} from "vue-router"
  7. import gettext from "@/gettext"
  8. import {Form, message} from "ant-design-vue"
  9. import auth from '@/api/auth'
  10. const route = useRoute()
  11. const router = useRouter()
  12. const {$gettext} = gettext
  13. const loading = ref(false)
  14. const modelRef = reactive({
  15. username: '',
  16. password: ''
  17. })
  18. const rulesRef = reactive({
  19. username: [
  20. {
  21. required: true,
  22. message: $gettext('Please input your username!'),
  23. }
  24. ],
  25. password: [
  26. {
  27. required: true,
  28. message: $gettext('Please input your password!'),
  29. }
  30. ]
  31. })
  32. const {validate, validateInfos} = Form.useForm(modelRef, rulesRef)
  33. const onSubmit = () => {
  34. validate().then(() => {
  35. // modelRef
  36. auth.login(modelRef.username, modelRef.password).then(async ()=>{
  37. message.success($gettext('Login successful'), 1)
  38. const next = (route.query?.next||'').toString() || '/'
  39. await router.push(next)
  40. }).
  41. catch(e=>{
  42. message.error(e.message)
  43. })
  44. })
  45. }
  46. </script>
  47. <template>
  48. <div class="container">
  49. <div class="login-form">
  50. <div class="project-title">
  51. <h1>Nginx UI</h1>
  52. </div>
  53. <a-form id="components-form-demo-normal-login">
  54. <a-form-item v-bind="validateInfos.username">
  55. <a-input
  56. v-model:value="modelRef.username"
  57. :placeholder="$gettext('Username')"
  58. >
  59. <template #prefix>
  60. <UserOutlined style="color: rgba(0, 0, 0, 0.25)"/>
  61. </template>
  62. </a-input>
  63. </a-form-item>
  64. <a-form-item v-bind="validateInfos.password">
  65. <a-input-password
  66. v-model:value="modelRef.password"
  67. :placeholder="$gettext('Password')"
  68. >
  69. <template #prefix>
  70. <LockOutlined style="color: rgba(0, 0, 0, 0.25)"/>
  71. </template>
  72. </a-input-password>
  73. </a-form-item>
  74. <a-form-item>
  75. <a-button @click="onSubmit" type="primary" :block="true" html-type="submit" :loading="loading">
  76. <translate>Login</translate>
  77. </a-button>
  78. </a-form-item>
  79. </a-form>
  80. <div class="footer">
  81. <p>Copyright © 2020 - {{ thisYear }} Nginx UI</p>
  82. Language <set-language class="set_lang" style="display: inline"/>
  83. </div>
  84. </div>
  85. </div>
  86. </template>
  87. <style lang="less">
  88. .container {
  89. display: flex;
  90. align-items: center;
  91. justify-content: center;
  92. height: 100%;
  93. .login-form {
  94. max-width: 400px;
  95. width: 80%;
  96. .project-title {
  97. margin: 50px;
  98. h1 {
  99. font-size: 50px;
  100. font-weight: 100;
  101. text-align: center;
  102. }
  103. }
  104. .anticon {
  105. color: #a8a5a5 !important;
  106. }
  107. .login-form-button {
  108. }
  109. .footer {
  110. padding: 30px;
  111. text-align: center;
  112. }
  113. }
  114. }
  115. </style>