Login.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="login-form">
  3. <div class="project-title">
  4. <h1>Nginx UI</h1>
  5. </div>
  6. <a-form
  7. id="components-form-demo-normal-login"
  8. :form="form"
  9. class="login-form"
  10. @submit="handleSubmit"
  11. >
  12. <a-form-item>
  13. <a-input
  14. v-decorator="[
  15. 'name',
  16. { rules: [{ required: true, message: 'Please input your username!' }] },
  17. ]"
  18. placeholder="Username"
  19. >
  20. <a-icon slot="prefix" type="user" style="color: rgba(0,0,0,.25)"/>
  21. </a-input>
  22. </a-form-item>
  23. <a-form-item>
  24. <a-input
  25. v-decorator="[
  26. 'password',
  27. { rules: [{ required: true, message: 'Please input your Password!' }] },
  28. ]"
  29. type="password"
  30. placeholder="Password"
  31. >
  32. <a-icon slot="prefix" type="lock" style="color: rgba(0,0,0,.25)"/>
  33. </a-input>
  34. </a-form-item>
  35. <a-form-item>
  36. <a-button type="primary" :block="true" html-type="submit" :loading="loading">
  37. 登录
  38. </a-button>
  39. </a-form-item>
  40. </a-form>
  41. <footer>
  42. Copyright © 2020 - {{ thisYear }} 0xJacky
  43. </footer>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. name: 'Login',
  49. data() {
  50. return {
  51. form: {},
  52. thisYear: new Date().getFullYear(),
  53. loading: false
  54. }
  55. },
  56. created() {
  57. this.form = this.$form.createForm(this)
  58. },
  59. mounted() {
  60. this.$api.install.get_lock().then(r=>{
  61. if (!r.lock) {
  62. this.$router.push('/install')
  63. }
  64. })
  65. if (this.$store.state.user.token) {
  66. this.$router.push('/')
  67. }
  68. },
  69. methods: {
  70. login(values) {
  71. this.$api.auth.login(values.name, values.password).then(async () => {
  72. await this.$message.success('登录成功', 1)
  73. const next = this.$route.query.next ? this.$route.query.next : '/'
  74. await this.$router.push(next)
  75. }).catch(r => {
  76. console.log(r)
  77. this.$message.error(r.message ?? '服务器错误')
  78. })
  79. },
  80. handleSubmit: async function (e) {
  81. e.preventDefault()
  82. this.loading = true
  83. await this.form.validateFields(async (err, values) => {
  84. if (!err) {
  85. await this.login(values)
  86. }
  87. this.loading = false
  88. })
  89. },
  90. },
  91. };
  92. </script>
  93. <style lang="less">
  94. .project-title {
  95. margin: 50px;
  96. h1 {
  97. font-size: 50px;
  98. font-weight: 100;
  99. text-align: center;
  100. }
  101. }
  102. .login-form {
  103. max-width: 500px;
  104. margin: 0 auto;
  105. }
  106. .login-form-button {
  107. }
  108. footer {
  109. padding: 30px;
  110. text-align: center;
  111. }
  112. </style>