You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.6 KiB

5 years ago
  1. <template>
  2. <v-card class="elevation-12">
  3. <v-toolbar color="primary" dark flat>
  4. <v-toolbar-title>Login</v-toolbar-title>
  5. </v-toolbar>
  6. <v-card-text>
  7. <v-form
  8. ref="form"
  9. v-model="valid"
  10. >
  11. <v-text-field
  12. v-model="username"
  13. :rules="userNameRules"
  14. label="Login"
  15. name="login"
  16. prepend-icon="person"
  17. type="text"
  18. />
  19. <v-text-field
  20. id="password"
  21. v-model="password"
  22. :rules="passwordRules"
  23. label="Password"
  24. name="password"
  25. prepend-icon="lock"
  26. type="password"
  27. />
  28. </v-form>
  29. </v-card-text>
  30. <v-card-actions>
  31. <div class="flex-grow-1" />
  32. <v-btn
  33. :disabled="!valid"
  34. color="primary"
  35. @click="tryLogin"
  36. >
  37. Login
  38. </v-btn>
  39. </v-card-actions>
  40. </v-card>
  41. </template>
  42. <script>
  43. import { userNameRules, passwordRules } from '@/rules/index'
  44. export default {
  45. props: {
  46. login: {
  47. type: Function,
  48. default: () => {}
  49. }
  50. },
  51. data() {
  52. return {
  53. valid: false,
  54. username: '',
  55. password: '',
  56. userNameRules,
  57. passwordRules
  58. }
  59. },
  60. methods: {
  61. cancel() {
  62. this.$emit('close')
  63. },
  64. validate() {
  65. return this.$refs.form.validate()
  66. },
  67. reset() {
  68. this.$refs.form.reset()
  69. },
  70. tryLogin() {
  71. if (this.validate()) {
  72. this.login({
  73. username: this.username,
  74. password: this.password
  75. })
  76. this.reset()
  77. this.cancel()
  78. }
  79. }
  80. }
  81. }
  82. </script>