Browse Source

退出时调用logout接口

Michael Wang 4 years ago
parent
commit
0bc90fedd4
4 changed files with 9 additions and 6 deletions
  1. 1 3
      src/api/login.js
  2. 2 0
      src/global.d.ts
  3. 5 2
      src/mixins/logout.js
  4. 1 1
      src/views/Layout/components/NavBar.vue

+ 1 - 3
src/api/login.js

@@ -13,9 +13,7 @@ export function loginByUsername({ loginName, password, code }) {
 }
 
 export function logout() {
-  return httpApp.post({
-    url: "/login/logout",
-  });
+  return httpApp.post("/api/admin/user/logout");
 }
 
 export function getLogo(code) {

+ 2 - 0
src/global.d.ts

@@ -71,6 +71,8 @@ declare module "vue/types/vue" {
   interface Vue {
     $http: AxiosInstance;
     // $api: api;
+    /** @param cause "?cause=正常退出" */
+    logout(cause?: string): Promise;
   }
 }
 

+ 5 - 2
src/mixins/logout.js

@@ -1,12 +1,15 @@
 import { removeToken } from "@/auth/auth";
+import { logout } from "@/api/login";
 import Vue from "vue";
 
 Vue.mixin({
   methods: {
     logout(cause = "") {
-      removeToken();
       // window._hmt.push(["_trackEvent", "退出", cause]);
-      this.$router.push("/login" + cause);
+      return logout().finally(() => {
+        removeToken();
+        this.$router.push("/login" + cause);
+      });
     },
   },
 });

+ 1 - 1
src/views/Layout/components/NavBar.vue

@@ -124,7 +124,7 @@ export default {
 
       if (!result) return;
 
-      this.$router.push("/login");
+      this.logout("?cause=点击退出");
     },
     checkDocIsFullscreen() {
       return (