Explorar el Código

بستن دیالوگ بعد از لاگین موفق

hgh hace 1 año
padre
commit
5f62ae898d

+ 1 - 0
src/components/Auth/ForgetStep.vue

@@ -283,6 +283,7 @@ export default {
       })
         .then(() => {
           this.loading = false
+          this.$emit('login-success', { user: 'ali' })
           this.redirectTo()
           // this.setRegisterStep('newPassword')
         })

+ 1 - 0
src/components/Auth/InformationStep.vue

@@ -119,6 +119,7 @@ export default {
         .then(() => {
           this.loadingList = false
           this.$axios.defaults.headers.common.Authorization = 'Bearer ' + this.$store.getters['Auth/accessToken']
+          this.$emit('login-success', { user: 'ali' })
           this.redirectTo()
         })
         .catch(() => {

+ 11 - 4
src/components/Auth/LoginComponent.vue

@@ -4,16 +4,20 @@
       <login-step v-if="step === 'login'"
                   @goToRegisterStep="goToRegisterStep"
                   @goToSendOtpStep="goToSendOtpStep"
-                  @goToForgetStep="goToForgetStep" />
+                  @goToForgetStep="goToForgetStep"
+                  @login-success="emitLoginSuccess" />
       <register-step v-if="showRegisterComponent"
                      :register-step-prop="this.step"
                      @goToLoginStep="goToLoginStep"
-                     @register="onRegister" />
+                     @register="onRegister"
+                     @login-success="emitLoginSuccess" />
       <forget-step v-if="step === 'forget'"
                    @goToLoginStep="goToLoginStep"
-                   @register="onRegister" />
+                   @register="onRegister"
+                   @login-success="emitLoginSuccess" />
       <information-step v-if="step === 'information'"
-                        @goToLoginStep="goToLoginStep" />
+                        @goToLoginStep="goToLoginStep"
+                        @login-success="emitLoginSuccess" />
     </template>
   </template-component>
 </template>
@@ -59,6 +63,9 @@ export default {
     },
     onRegister () {
       // console.log('onRegister')
+    },
+    emitLoginSuccess (payload) {
+      this.$emit('login-success', payload)
     }
   }
 }

+ 1 - 0
src/components/Auth/LoginStep.vue

@@ -133,6 +133,7 @@ export default {
         .then(() => {
           this.loadingList = false
           this.$axios.defaults.headers.common.Authorization = 'Bearer ' + this.$store.getters['Auth/accessToken']
+          this.$emit('login-success', { user: 'ali' })
           this.redirectTo()
         })
         .catch(() => {

+ 2 - 0
src/components/Auth/RegisterStep.vue

@@ -345,6 +345,7 @@ export default {
       })
         .then(() => {
           this.loading = false
+          this.$emit('login-success', { user: 'ali' })
           this.$router.push({ name: 'Public.Home' })
           // this.$store.commit('Auth/updateAccessToken', response.data.token.access_token)
           // this.$store.commit('Auth/setAccessToken', response.data.token.access_token)
@@ -444,6 +445,7 @@ export default {
       })
         .then(() => {
           this.loading = false
+          this.$emit('login-success', { user: 'ali' })
           this.$router.push({ name: 'Public.Home' })
           // this.setRegisterStep('information')
         })

+ 16 - 2
src/components/Widgets/AlertMe/AlertMe.vue

@@ -48,7 +48,8 @@ export default {
       is_enabled: false,
       loading: false,
       showLoginDialog: false,
-      isUserLogin: false
+      isUserLogin: false,
+      pendingToggleValue: null
     }
   },
   computed: {
@@ -59,6 +60,14 @@ export default {
       return this.localOptions.sourceId
     }
   },
+  watch: {
+    showLoginDialog (oldVal, newVal) {
+      if (oldVal === true && newVal === false && !this.isUserLogin) {
+        // یعنی کاربر دیالوگ رو بست (نه لاگین کرد)
+        this.is_enabled = false
+      }
+    }
+  },
   mounted () {
     this.loadAuthData()
     if (this.isUserLogin) {
@@ -89,7 +98,7 @@ export default {
       if (!this.isUserLogin) {
         this.showLoginDialog = true
         // برگردوندن toggle به حالت قبلی تا لاگین انجام بشه
-        this.is_enabled = !val
+        this.pendingToggleValue = val
         return
       }
       this.toggleNotification(val)
@@ -109,7 +118,12 @@ export default {
       })
     },
     onLoginSuccess () {
+      debugger
       this.showLoginDialog = false
+      if (this.pendingToggleValue) {
+        this.toggleNotification(this.pendingToggleValue)
+        this.pendingToggleValue = null
+      }
       this.fetchNotificationStatus()
     }
   }

+ 1 - 0
src/store/Auth/actions.js

@@ -6,6 +6,7 @@ export function login (context, data) {
   const setVars = (user, accessToken) => {
     context.commit('updateUser', user)
     context.commit('updateAccessToken', accessToken)
+    debugger
     if (typeof window !== 'undefined') {
       Cookies.set('BearerAccessToken', accessToken, {
         // domain: '.' + window.location.host,