loulijun2021
2022-06-22 fd59571a8536d48d4029eb7b09a717393f19e210
src/layout/components/Navbar.vue
@@ -44,7 +44,9 @@
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import { getCookie } from '@/utils/auth'
import { getCookie, removeCookie, removeToken } from '@/utils/auth'
import { logout } from '@/api/user'
import { resetRouter } from '@/router'
export default {
  components: {
@@ -70,8 +72,30 @@
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
      // await this.$store.dispatch('user/logout')
      const usercode = getCookie('navTabId')
      const username = getCookie('admin')
      const usertype = getCookie('usertype')
      const userid = getCookie('userid')
      const data = {
        usercode,
        username,
        usertype,
        userid
      }
      const res = await logout(data)
      if (res.code === '200') {
        removeToken()
        resetRouter()
        removeCookie('admin')
        removeCookie('navTabId')
        removeCookie('usertype')
        removeCookie('userid')
        this.$message.success('退出成功!')
        this.$router.push(`/login?redirect=${this.$route.fullPath}`)
        // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
      }
      // this.$router.push(`/login`)
    }
  }
}