Auth.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div class="login-card"
  3. :class="{defaultLoginCard: defaultLayout}">
  4. <div v-if="!userLogin">
  5. <div v-if="loading"
  6. class="text-center login-loading">
  7. <q-spinner-ball color="primary"
  8. size="5em" />
  9. </div>
  10. <div v-else>
  11. <div v-if="defaultLayout"
  12. class="header">
  13. <q-btn flat
  14. rounded
  15. :to="{name: 'Public.Home'}">
  16. <q-avatar size="42px">
  17. <lazy-img src="https://nodes.alaatv.com/upload/alaa-logo.png"
  18. width="40"
  19. height="40"
  20. class="full-width" />
  21. </q-avatar>
  22. </q-btn>
  23. ثبت نام و ورود
  24. </div>
  25. <div class="phone-number">
  26. <div class="label">
  27. شماره همراه
  28. </div>
  29. <q-input ref="userName"
  30. v-model="username"
  31. bottom-slots
  32. hide-bottom-space
  33. autocomplete="off"
  34. pattern="[0-9]*"
  35. inputmode="numeric"
  36. onfocus="this.removeAttribute('readonly');"
  37. name="userName"
  38. placeholder=" - - - - - - - - - 09"
  39. @keydown.enter="getEnter('pass')" />
  40. </div>
  41. <div class="national-code">
  42. <div class="label">
  43. کد ملی
  44. </div>
  45. <q-input ref="pass"
  46. v-model="password"
  47. name="pass"
  48. hide-bottom-space
  49. type="password"
  50. pattern="[0-9]*"
  51. inputmode="numeric"
  52. @keydown.enter="login" />
  53. </div>
  54. <q-btn class="full-width login-btn"
  55. :class="{'bg-green-6': !defaultLayout}"
  56. unelevated
  57. color="primary"
  58. label="ثبت نام / ورود"
  59. @click="login" />
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import { mixinAuth } from 'src/mixin/Mixins.js'
  66. import LazyImg from 'src/components/lazyImg.vue'
  67. export default {
  68. name: 'AuthLogin',
  69. components: { LazyImg },
  70. mixins: [mixinAuth],
  71. props: {
  72. redirect: {
  73. type: (Object, Boolean),
  74. default: null
  75. },
  76. defaultLayout: {
  77. default: true,
  78. type: Boolean
  79. }
  80. },
  81. emits: ['onLoggedIn'],
  82. data: () => ({
  83. userLogin: false,
  84. loading: true,
  85. username: null,
  86. password: null
  87. }),
  88. mounted () {
  89. this.loading = false
  90. this.$store.dispatch('Auth/logOut', { redirectTo: false })
  91. },
  92. methods: {
  93. getToken () {
  94. return this.$store.getters['Auth/accessToken']
  95. },
  96. getEnter (targetRefKey) {
  97. this.$refs[targetRefKey].focus()
  98. },
  99. redirectTo () {
  100. let redirectTo = this.$store.getters['Auth/redirectTo']
  101. if (this.redirect) {
  102. redirectTo = this.redirect
  103. }
  104. if (this.redirect === false) {
  105. this.$store.commit('Auth/updateRedirectTo', null)
  106. return
  107. }
  108. if (redirectTo === null || typeof redirectTo !== 'object') {
  109. redirectTo = { name: 'Public.Home' }
  110. }
  111. this.$router.push(redirectTo)
  112. this.$store.commit('Auth/updateRedirectTo', null)
  113. },
  114. handleErr (err) {
  115. this.loading = false
  116. const messages = []
  117. for (const key in err.data.errors) {
  118. err.data.errors[key].forEach(message => {
  119. this.$q.notify({
  120. type: 'negative',
  121. message,
  122. position: 'top'
  123. })
  124. })
  125. }
  126. if (!err.data.errors) {
  127. if (err.data.message) messages.push(err.data.message)
  128. else messages.push(err.statusText)
  129. this.$q.notify({
  130. type: 'negative',
  131. message: messages,
  132. position: 'top'
  133. })
  134. }
  135. },
  136. login () {
  137. this.loading = true
  138. this.$store.dispatch('Auth/login', {
  139. mobile: this.username,
  140. password: this.password
  141. })
  142. .then(() => {
  143. this.loading = false
  144. // this.$axios.defaults.headers.common.Authorization = 'Bearer ' + this.$store.getters['Auth/accessToken']
  145. // this.getUserData()
  146. // .then(() => {
  147. // this.$store.commit('AppLayout/updateLoginDialog', false)
  148. // this.redirectTo()
  149. // })
  150. this.$store.commit('AppLayout/updateLoginDialog', false)
  151. this.$emit('onLoggedIn')
  152. this.redirectTo()
  153. })
  154. .catch(() => {
  155. this.loading = false
  156. })
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .defaultLoginCard{
  163. width: 434px;
  164. height: 485px;
  165. }
  166. .login-card {
  167. box-shadow: 2px -4px 10px rgba(255, 255, 255, 0.6), -2px 4px 10px rgba(112, 108, 162, 0.05);
  168. background: #fff;
  169. margin: auto;
  170. border-radius: 20px;
  171. padding:60px 67px;
  172. .login-loading {
  173. height: 100%;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. }
  178. .header{
  179. margin-bottom: 50px;
  180. font-style: normal;
  181. font-weight: 700;
  182. font-size: 24px;
  183. line-height: 37px;
  184. letter-spacing: -0.03em;
  185. color: var(--alaa-TextSecondary);
  186. }
  187. .label{
  188. font-weight: 400;
  189. font-size: 16px;
  190. line-height: 25px;
  191. letter-spacing: -0.03em;
  192. color: #434765;
  193. margin-bottom: 8px;
  194. }
  195. .login-btn{
  196. :deep(.q-btn__content){
  197. font-weight: 600;
  198. font-size: 14px;
  199. line-height: 22px;
  200. }
  201. }
  202. .phone-number{
  203. margin-bottom: 16px;
  204. }
  205. .national-code{
  206. margin-bottom: 56px;
  207. }
  208. :deep(.q-field--focused) {
  209. appearance: none;
  210. }
  211. &:deep(.q-field--focused .q-field__control) {
  212. background-color: rgba(255,255,255,0) !important;
  213. appearance: none;
  214. border: 1px solid #FFB74D;
  215. box-shadow: 0 0 0 2px #FFEDD2;
  216. border-radius: 8px;
  217. }
  218. &:deep(.q-field .q-field__control) {
  219. height: 40px;
  220. background: #F2F5F9;
  221. border-radius: 8px;
  222. padding-left: 0;
  223. }
  224. &:deep(.q-field__native) {
  225. font-style: normal;
  226. font-weight: 400;
  227. font-size: 14px;
  228. line-height: 22px;
  229. color: #6D708B !important;
  230. }
  231. :deep(.q-field__native, .q-field__prefix, .q-field__suffix, .q-field__input){
  232. padding: 8px 16px;
  233. border-radius: 8px
  234. }
  235. :deep(.q-field__control){
  236. &::after{
  237. height: 0;
  238. }
  239. &::before{
  240. border-bottom: none;
  241. }
  242. }
  243. }
  244. @media only screen and (max-width: 1023px){
  245. .default-login-card {
  246. width: 312px;
  247. height: 409px;
  248. border-radius: 16px;
  249. padding: 40px 30px;
  250. .header {
  251. margin-bottom: 30px;
  252. font-size: 20px;
  253. line-height: 31px;
  254. }
  255. .label {
  256. font-size: 14px;
  257. line-height: 22px;
  258. letter-spacing: -0.03em;
  259. }
  260. }
  261. }
  262. </style>