LoginStep.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 class="full-width div-btn-register-login-opt">
  51. حساب کاربری ندارید؟
  52. <q-btn class="full-width btn-login-otp"
  53. color="secondary"
  54. label="ثبت نام کنید"
  55. :loading="loadingList"
  56. @click="goToRegisterStep" />
  57. <div class="btn-otp-div"
  58. @click="goToSendOtpStep">
  59. ورود با رمز یکبار مصرف
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import { mixinAuth } from 'src/mixin/Mixins.js'
  66. export default {
  67. name: 'LoginStep',
  68. mixins: [mixinAuth],
  69. props: {
  70. redirect: {
  71. type: Boolean,
  72. default: false
  73. }
  74. },
  75. data () {
  76. return {
  77. userLogin: false,
  78. loadingList: false,
  79. visibilityIcon: 'visibility',
  80. otpStep: 'sendOtp',
  81. username: null,
  82. password: null,
  83. otp: null
  84. }
  85. },
  86. created () {
  87. // if (this.getToken()) {
  88. // this.getUserData(() => { this.redirectTo() })
  89. // }
  90. },
  91. methods: {
  92. toggleVisibilityIcon () {
  93. this.visibilityIcon = this.visibilityIcon === 'visibility' ? 'visibility_off' : 'visibility'
  94. },
  95. getToken () {
  96. return this.$store.getters['Auth/accessToken']
  97. },
  98. getEnter (targetRefKey) {
  99. this.$refs[targetRefKey].focus()
  100. },
  101. redirectTo () {
  102. let redirectTo = this.$store.getters['Auth/redirectTo']
  103. // if (!redirectTo) {
  104. // redirectTo = 'Admin.User.Index'
  105. // }
  106. if (!redirectTo && this.user.canSeeAdminPanel()) {
  107. redirectTo = { name: 'Admin.User.Index' }
  108. } else if (!redirectTo) {
  109. redirectTo = { name: 'Public.Home' }
  110. }
  111. this.$router.push(redirectTo)
  112. },
  113. login () {
  114. if (!this.username || !this.password) {
  115. this.$q.notify({
  116. type: 'negative',
  117. message: 'نام کاربری و کلمه عبور را وارد کنید.'
  118. })
  119. return
  120. }
  121. this.loadingList = true
  122. this.$store.dispatch('Auth/login', {
  123. input: this.username,
  124. password: this.password
  125. })
  126. .then(() => {
  127. this.loadingList = false
  128. this.$axios.defaults.headers.common.Authorization = 'Bearer ' + this.$store.getters['Auth/accessToken']
  129. this.$emit('login-success', { user: 'ali' })
  130. if (this.redirect) {
  131. this.redirectTo()
  132. }
  133. })
  134. .catch(() => {
  135. this.loadingList = false
  136. })
  137. },
  138. goToSendOtpStep () {
  139. this.$emit('goToSendOtpStep')
  140. },
  141. goToRegisterStep () {
  142. this.$emit('goToRegisterStep')
  143. },
  144. goToForgetStep () {
  145. this.$emit('goToForgetStep')
  146. }
  147. }
  148. }
  149. </script>
  150. <style scoped>
  151. .banner {
  152. margin-bottom: 30px;
  153. }
  154. .username-input, .password-input {
  155. margin-top: 6px;
  156. }
  157. .username-input {
  158. margin-bottom: 27px;
  159. }
  160. .password-input {
  161. margin-bottom: 50px;
  162. }
  163. .btn-login {
  164. margin-bottom: 16px;
  165. font-size: 18px;
  166. }
  167. .btn-login-otp {
  168. font-size: 18px;
  169. }
  170. .password-label {
  171. display: flex;
  172. justify-content: space-between;
  173. }
  174. .btn-forgot-pass-span {
  175. color: #5B7A5F;
  176. font-size: 14px;
  177. cursor: pointer;
  178. }
  179. .btn-register-span {
  180. color: #475F4A;
  181. font-size: 16px;
  182. cursor: pointer;
  183. }
  184. .btn-register-span {
  185. color: #475F4A;
  186. font-size: 16px;
  187. cursor: pointer;
  188. }
  189. .btn-otp-div {
  190. display: flex;
  191. font-size: 18px;
  192. cursor: pointer;
  193. justify-content: center;
  194. align-self: stretch;
  195. }
  196. .div-btn-register-login-opt{
  197. display: flex;
  198. flex-direction: column;
  199. padding: 16px 0px;
  200. align-items: flex-start;
  201. gap: 16px;
  202. }
  203. </style>