LoginStep.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div>
  3. <q-banner class="banner">
  4. ورود به سامانه
  5. </q-banner>
  6. <label for="username">
  7. ایمیل یا شماره تلفن همراه یا کدملی
  8. </label>
  9. <q-input id="username"
  10. v-model="username"
  11. outlined
  12. class="username-input"
  13. label="ایمیل یا شماره تلفن همراه خود را وارد کنید"
  14. @keydown.enter="login">
  15. <template v-slot:prepend>
  16. <q-icon name="person" />
  17. </template>
  18. </q-input>
  19. <label class="password-label"
  20. for="password">
  21. <span>
  22. گذرواژه
  23. </span>
  24. <span class="btn-forgot-pass-span"
  25. @click="goToForgetStep">
  26. فراموشی گذرواژه
  27. </span>
  28. </label>
  29. <q-input id="password"
  30. v-model="password"
  31. outlined
  32. class="password-input"
  33. label="گذرواژه خود را وارد کنید"
  34. @keydown.enter="login">
  35. <template v-slot:prepend>
  36. <q-icon name="person" />
  37. </template>
  38. <template v-slot:append>
  39. <q-icon name="person" />
  40. </template>
  41. </q-input>
  42. <q-btn class="full-width btn-login"
  43. color="primary"
  44. label="ورود به سامانه"
  45. @click="login" />
  46. <div>
  47. حساب کاربری ندارید؟
  48. <span class="btn-register-span"
  49. @click="goToRegisterStep">
  50. ثبت نام کنید
  51. </span>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { mixinAuth } from 'src/mixin/Mixins.js'
  57. export default {
  58. name: 'LoginStep',
  59. mixins: [mixinAuth],
  60. props: {
  61. redirect: {
  62. type: Boolean,
  63. default: false
  64. }
  65. },
  66. data: () => ({
  67. userLogin: false,
  68. loadingList: false,
  69. otpStep: 'sendOtp',
  70. username: '09123456789',
  71. password: '09123456789',
  72. otp: null
  73. }),
  74. computed: {
  75. user () {
  76. return this.$store.getters['Auth/user']
  77. }
  78. },
  79. created () {
  80. // if (this.getToken()) {
  81. // this.getUserData(() => { this.redirectTo() })
  82. // }
  83. },
  84. methods: {
  85. getToken () {
  86. return this.$store.getters['Auth/accessToken']
  87. },
  88. getEnter (targetRefKey) {
  89. this.$refs[targetRefKey].focus()
  90. },
  91. redirectTo () {
  92. let redirectTo = this.$store.getters['Auth/redirectTo']
  93. // if (!redirectTo) {
  94. // redirectTo = 'Admin.User.Index'
  95. // }
  96. if (!redirectTo && this.user.canSeeAdminPanel()) {
  97. redirectTo = { name: 'Admin.User.Index' }
  98. } else if (!redirectTo) {
  99. redirectTo = { name: 'Public.Home' }
  100. }
  101. this.$router.push(redirectTo)
  102. },
  103. login () {
  104. this.loadingList = true
  105. this.$store.dispatch('Auth/login', {
  106. input: this.username,
  107. password: this.password
  108. })
  109. .then(() => {
  110. this.loadingList = false
  111. this.$axios.defaults.headers.common.Authorization = 'Bearer ' + this.$store.getters['Auth/accessToken']
  112. this.redirectTo()
  113. })
  114. .catch(() => {
  115. this.loadingList = false
  116. })
  117. },
  118. goToRegisterStep () {
  119. this.$emit('goToRegisterStep')
  120. },
  121. goToForgetStep () {
  122. this.$emit('goToForgetStep')
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped>
  128. .banner {
  129. margin-bottom: 30px;
  130. }
  131. .username-input, .password-input {
  132. margin-top: 6px;
  133. }
  134. .username-input {
  135. margin-bottom: 27px;
  136. }
  137. .password-input {
  138. margin-bottom: 50px;
  139. }
  140. .btn-login {
  141. margin-bottom: 40px;
  142. font-size: 18px;
  143. }
  144. .password-label {
  145. display: flex;
  146. justify-content: space-between;
  147. }
  148. .btn-forgot-pass-span {
  149. color: #5B7A5F;
  150. font-size: 14px;
  151. cursor: pointer;
  152. }
  153. .btn-register-span {
  154. color: #475F4A;
  155. font-size: 16px;
  156. cursor: pointer;
  157. }
  158. </style>