LoginStep.vue 4.2 KB

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