Sign.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="Sign">
  3. <div class="wrap" :class="{ 'wrap--error': error }">
  4. <Form>
  5. <FormItem>
  6. <Input
  7. prefix="ios-contact-outline"
  8. v-model="username"
  9. placeholder="用户"
  10. :disabled="loading"
  11. @on-enter="submit" />
  12. </FormItem>
  13. <FormItem>
  14. <Input
  15. type="password"
  16. prefix="ios-lock-outline"
  17. v-model="password"
  18. placeholder="密码"
  19. :disabled="loading"
  20. @on-enter="submit" />
  21. </FormItem>
  22. <FormItem>
  23. <Button
  24. type="primary"
  25. long
  26. :disabled="!username || !password"
  27. :loading="loading"
  28. @click="submit">登录</Button>
  29. </FormItem>
  30. </Form>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { mapActions } from 'vuex'
  36. export default {
  37. data () {
  38. return {
  39. loading: false,
  40. error: false,
  41. username: null,
  42. password: null,
  43. }
  44. },
  45. methods: {
  46. ...mapActions('user', [
  47. 'login',
  48. ]),
  49. async submit () {
  50. this.loading = true
  51. try {
  52. await this.login({ username: this.username, password: this.password })
  53. this.$router.replace({ name: 'root' })
  54. } catch {
  55. this.error = true
  56. setTimeout(() => {
  57. this.error = false
  58. this.loading = false
  59. }, 300)
  60. }
  61. },
  62. },
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .Sign {
  67. display: flex;
  68. justify-content: center;
  69. align-items: center;
  70. height: 100vh;
  71. width: 100vw;
  72. background: #fafafa;
  73. }
  74. .wrap {
  75. width: 320px;
  76. padding: 24px;
  77. padding-bottom: 0;
  78. background: #fff;
  79. border-radius: 4px;
  80. box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
  81. &--error {
  82. @keyframes shake {
  83. 0%, 100% {
  84. transform: translate(0, 0);
  85. }
  86. 20%, 60% {
  87. transform: translate(-8px, 0);
  88. }
  89. 40%, 80% {
  90. transform: translate(8px, 0);
  91. }
  92. }
  93. animation: shake .3s linear forwards;
  94. }
  95. }
  96. </style>