Browse Source

修改bug.

zhangfufeng 4 months ago
parent
commit
15395961f3
3 changed files with 13 additions and 37 deletions
  1. 1 2
      src/App.vue
  2. 3 22
      src/store/modules/user.js
  3. 9 13
      src/utils/auth.js

+ 1 - 2
src/App.vue

@@ -7,7 +7,7 @@
 </template>
 
 <script>
-import { getToken, removeToken, setLoginStatus, setToken } from '@/utils/auth'
+import { setToken } from '@/utils/auth'
 export default {
   name: 'App',
   created() {
@@ -17,7 +17,6 @@ export default {
       console.log('mall:' + token);
       this.$store.commit('SET_TOKEN', token);
       setToken(token);
-      setLoginStatus(true);
     }
     this.sleep(200);
 

+ 3 - 22
src/store/modules/user.js

@@ -1,5 +1,5 @@
 import {getUserInfo, loginByUsername, logout, verifyCode} from '@/api/login'
-import {getToken, removeToken, setLoginStatus, setToken} from '@/utils/auth'
+import {getToken, removeToken,setToken} from '@/utils/auth'
 
 const user = {
   state: {
@@ -53,7 +53,7 @@ const user = {
         verifyCode().then(response => {
           const token = response.headers['session_id']
           commit('SET_TOKEN', token)
-          setToken(token)
+          setToken(token,0)
           resolve(response)
         }).catch(error => {
           reject(error)
@@ -68,8 +68,7 @@ const user = {
         loginByUsername(username, userInfo.password, userInfo.verifyCode).then(response => {
           const token = response.data.data.token
           commit('SET_TOKEN', token)
-          setToken(token)
-          setLoginStatus(true)
+          setToken(token, 1)
           resolve()
         }).catch(error => {
           reject(error)
@@ -136,24 +135,6 @@ const user = {
         removeToken()
         resolve()
       })
-    },
-
-    // 动态修改权限
-    ChangeRoles({commit, dispatch}, role) {
-      return new Promise(resolve => {
-        commit('SET_TOKEN', role)
-        setToken(role)
-        getUserInfo(role).then(response => {
-          const data = response.data
-          commit('SET_ROLES', data.roles)
-          commit('SET_PERMS', data.perms)
-          commit('SET_NAME', data.name)
-          commit('SET_AVATAR', data.avatar)
-          commit('SET_INTRODUCTION', data.introduction)
-          dispatch('GenerateRoutes', data) // 动态修改权限后 重绘侧边菜单
-          resolve()
-        })
-      })
     }
   }
 }

+ 9 - 13
src/utils/auth.js

@@ -3,24 +3,20 @@ import Cookies from 'js-cookie'
 const TokenKey = 'X-JZ-Admin-Token'
 
 export function getToken() {
-  let token = Cookies.get(TokenKey);
-  if (token.includes(":")) {
-    token = token.split(":")[1]
-  }
-  return token;
+  return Cookies.get(TokenKey)
 }
 
-export function setToken(token) {
-  return Cookies.set(TokenKey, token)
+export function setToken(token,type=0) {
+  if (type === 1) {
+    Cookies.set("login", true, { expires: 7 });
+  }
+  Cookies.set(TokenKey,token , { expires: 7 })
 }
 
 export function removeToken() {
-  Cookies.remove("login")
-  return Cookies.remove(TokenKey)
-}
-
-export function setLoginStatus(status) {
-  return Cookies.set('login', status)
+  localStorage.removeItem('userInfo')
+  Cookies.remove('login')
+  Cookies.remove(TokenKey)
 }
 
 export function getLoginStatus() {