mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-30 09:24:46 +08:00
Revert "feat: 用户登录使用mock api, 可以使用test用户登录 (#233)"
This commit is contained in:
parent
dc219ed11a
commit
91df7349f4
23
mock/user.ts
23
mock/user.ts
@ -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[];
|
|
@ -7,7 +7,6 @@ import { remainingPaths } from "/@/router";
|
|||||||
import { transformI18n } from "/@/plugins/i18n";
|
import { transformI18n } from "/@/plugins/i18n";
|
||||||
import { storageSession } from "/@/utils/storage";
|
import { storageSession } from "/@/utils/storage";
|
||||||
import { useAppStoreHook } from "/@/store/modules/app";
|
import { useAppStoreHook } from "/@/store/modules/app";
|
||||||
import { useUserStoreHook } from "/@/store/modules/user";
|
|
||||||
import { useEpThemeStoreHook } from "/@/store/modules/epTheme";
|
import { useEpThemeStoreHook } from "/@/store/modules/epTheme";
|
||||||
|
|
||||||
export function useNav() {
|
export function useNav() {
|
||||||
@ -39,7 +38,8 @@ export function useNav() {
|
|||||||
|
|
||||||
// 退出登录
|
// 退出登录
|
||||||
function logout() {
|
function logout() {
|
||||||
useUserStoreHook().logOut();
|
storageSession.removeItem("info");
|
||||||
|
router.push("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
function backHome() {
|
function backHome() {
|
||||||
|
@ -61,11 +61,8 @@ export const usePermissionStore = defineStore({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 清空缓存
|
// 清空缓存页面
|
||||||
clearAllCachePage() {
|
clearAllCachePage() {
|
||||||
this.wholeMenus = [];
|
|
||||||
this.menusTree = [];
|
|
||||||
this.buttonAuth = [];
|
|
||||||
this.cachePageList = [];
|
this.cachePageList = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ export const useUserStore = defineStore({
|
|||||||
},
|
},
|
||||||
// 登入
|
// 登入
|
||||||
async loginByUsername(data) {
|
async loginByUsername(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
getLogin(data)
|
getLogin(data)
|
||||||
.then(res => {
|
.then(data => {
|
||||||
if (res) {
|
if (data) {
|
||||||
setToken(res);
|
setToken(data);
|
||||||
resolve(res);
|
resolve();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -14,9 +14,6 @@ import illustration4 from "/@/assets/login/illustration4.svg?component";
|
|||||||
import illustration5 from "/@/assets/login/illustration5.svg?component";
|
import illustration5 from "/@/assets/login/illustration5.svg?component";
|
||||||
import illustration6 from "/@/assets/login/illustration6.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();
|
const router = useRouter();
|
||||||
|
|
||||||
// eslint-disable-next-line vue/return-in-computed-property
|
// eslint-disable-next-line vue/return-in-computed-property
|
||||||
@ -45,17 +42,12 @@ let user = ref("admin");
|
|||||||
let pwd = ref("123456");
|
let pwd = ref("123456");
|
||||||
|
|
||||||
const onLogin = (): void => {
|
const onLogin = (): void => {
|
||||||
useUserStoreHook()
|
|
||||||
.loginByUsername({ username: user.value, password: pwd.value })
|
|
||||||
.then(async (res: any) => {
|
|
||||||
storageSession.setItem("info", {
|
storageSession.setItem("info", {
|
||||||
username: res.username,
|
username: "admin",
|
||||||
accessToken: res.accessToken
|
accessToken: "eyJhbGciOiJIUzUxMiJ9.test"
|
||||||
});
|
});
|
||||||
usePermissionStoreHook().clearAllCachePage();
|
initRouter("admin").then(() => {});
|
||||||
initRouter(res.username);
|
|
||||||
router.push("/");
|
router.push("/");
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function onUserFocus() {
|
function onUserFocus() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user