diff --git a/mock/user.ts b/mock/user.ts deleted file mode 100644 index 34389c0d2..000000000 --- a/mock/user.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { MockMethod } from "vite-plugin-mock"; - -export default [ - { - url: "/login", - method: "post", - response: ({ body }) => { - if (body.username === "admin") { - return { - username: "admin", - expires: 24 * 60 * 60, - accessToken: "eyJhbGciOiJIUzUxMiJ9.admin" - }; - } else { - return { - username: "test", - expires: 24 * 60 * 60, - accessToken: "eyJhbGciOiJIUzUxMiJ9.test" - }; - } - } - } -] as MockMethod[]; diff --git a/src/layout/hooks/nav.ts b/src/layout/hooks/nav.ts index e5e224e6a..a162be933 100644 --- a/src/layout/hooks/nav.ts +++ b/src/layout/hooks/nav.ts @@ -7,7 +7,6 @@ import { remainingPaths } from "/@/router"; import { transformI18n } from "/@/plugins/i18n"; import { storageSession } from "/@/utils/storage"; import { useAppStoreHook } from "/@/store/modules/app"; -import { useUserStoreHook } from "/@/store/modules/user"; import { useEpThemeStoreHook } from "/@/store/modules/epTheme"; export function useNav() { @@ -39,7 +38,8 @@ export function useNav() { // 退出登录 function logout() { - useUserStoreHook().logOut(); + storageSession.removeItem("info"); + router.push("/login"); } function backHome() { diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index a2d84cf90..f2aa691d0 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -61,11 +61,8 @@ export const usePermissionStore = defineStore({ break; } }, - // 清空缓存 + // 清空缓存页面 clearAllCachePage() { - this.wholeMenus = []; - this.menusTree = []; - this.buttonAuth = []; this.cachePageList = []; } } diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index d744f3ebc..9f04254f1 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -33,12 +33,12 @@ export const useUserStore = defineStore({ }, // 登入 async loginByUsername(data) { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { getLogin(data) - .then(res => { - if (res) { - setToken(res); - resolve(res); + .then(data => { + if (data) { + setToken(data); + resolve(); } }) .catch(error => { diff --git a/src/views/login.vue b/src/views/login.vue index dcf256472..75dc2c956 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -14,9 +14,6 @@ import illustration4 from "/@/assets/login/illustration4.svg?component"; import illustration5 from "/@/assets/login/illustration5.svg?component"; import illustration6 from "/@/assets/login/illustration6.svg?component"; -import { useUserStoreHook } from "/@/store/modules/user"; -import { usePermissionStoreHook } from "/@/store/modules/permission"; - const router = useRouter(); // eslint-disable-next-line vue/return-in-computed-property @@ -45,17 +42,12 @@ let user = ref("admin"); let pwd = ref("123456"); const onLogin = (): void => { - useUserStoreHook() - .loginByUsername({ username: user.value, password: pwd.value }) - .then(async (res: any) => { - storageSession.setItem("info", { - username: res.username, - accessToken: res.accessToken - }); - usePermissionStoreHook().clearAllCachePage(); - initRouter(res.username); - router.push("/"); - }); + storageSession.setItem("info", { + username: "admin", + accessToken: "eyJhbGciOiJIUzUxMiJ9.test" + }); + initRouter("admin").then(() => {}); + router.push("/"); }; function onUserFocus() {