zhaomiao il y a 3 ans
Parent
commit
debbcf8447
3 fichiers modifiés avec 24 ajouts et 8 suppressions
  1. 0 1
      src/api/axios.js
  2. 12 0
      src/store/modules/user.js
  3. 12 7
      src/views/headPortrait.vue

+ 0 - 1
src/api/axios.js

@@ -76,7 +76,6 @@ export function requestData (options) {
         Message.error((response.data && response.data.msg) || ("请求出错[" + response.data.code + "]"));
         setTimeout(() => {
           window.location.reload();
-          // window.__STATICVUE__.$router.replace('/login');
         }, 1000);
       }
     }).catch(error => {

+ 12 - 0
src/store/modules/user.js

@@ -1,4 +1,5 @@
 // import {getToken,setToken,removeToken} from '@/utils/auth'
+import { Message } from 'element-ui';
 const state = {
   authToken:localStorage.getItem('authToken') ? localStorage.getItem('authToken'):'', //设置token为共享状态   初始化vuex的时候 就先从缓存中读取
   username:'',
@@ -6,6 +7,17 @@ const state = {
 const mutations = {
   REMOVE_TOKEN(state){
     localStorage.removeItem('authToken');
+    localStorage.removeItem('username');
+    state.authToken = "";
+    state.username = "";
+    Message({
+      message: '退出成功',
+      type: 'success'
+    });
+    setTimeout(() => {
+      window.location.reload();
+    }, 1000);
+    
   },
   SET_TOKEN: (state, token_name) => {
     state.authToken = token_name.token;

+ 12 - 7
src/views/headPortrait.vue

@@ -1,13 +1,16 @@
 <template>
 <div class="head">
   <el-popover
-  placement="right"
-  width="400"
+  placement="bottom"
+  width="200"
   trigger="click">
   <div >
     <p>你好{{name}}</p>
     <el-divider></el-divider>
   </div>
+  <div>
+    <el-link icon="el-icon-unlock" @click="loginout">退出登录<i class="-icon--right"></i> </el-link>
+  </div>
   
   <el-button style="border-radius:50px;" icon="el-icon-user-solid" type="info"  slot="reference"></el-button>
 </el-popover>
@@ -15,13 +18,13 @@
 </template>
 
 <script>
-import { mapGetters } from 'vuex'
+import { mapGetters,mapMutations} from 'vuex'
 
 export default {
   
   data () {
     return {
-      name:this.username,
+      name:"",
 
     }
   },
@@ -35,10 +38,12 @@ export default {
     this.name = this.username?this.username:localStorage.getItem('username');
   },
   methods: {
-
+    ...mapMutations("user", ["REMOVE_TOKEN"]),
+    loginout(){
+      this.REMOVE_TOKEN();
+    }
   }
-
-};
+}
 </script>
 
 <style>