mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-08 01:17:23 +08:00
feat: 用户登录使用mock api, 可以使用test用户登录 (#233)
* feat: 用户登录使用mock api, 可以使用test用户登录 * Update permission.ts
This commit is contained in:
parent
bafd9522e0
commit
0becf0b4bc
23
mock/user.ts
Normal file
23
mock/user.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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[];
|
@ -8,6 +8,7 @@ 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 { useEpThemeStoreHook } from "/@/store/modules/epTheme";
|
import { useEpThemeStoreHook } from "/@/store/modules/epTheme";
|
||||||
|
import { useUserStoreHook } from "/@/store/modules/user";
|
||||||
|
|
||||||
export function useNav() {
|
export function useNav() {
|
||||||
const pureApp = useAppStoreHook();
|
const pureApp = useAppStoreHook();
|
||||||
@ -38,8 +39,7 @@ export function useNav() {
|
|||||||
|
|
||||||
// 退出登录
|
// 退出登录
|
||||||
function logout() {
|
function logout() {
|
||||||
storageSession.removeItem("info");
|
useUserStoreHook().logOut();
|
||||||
router.push("/login");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function backHome() {
|
function backHome() {
|
||||||
|
@ -61,8 +61,11 @@ 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<void>((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
getLogin(data)
|
getLogin(data)
|
||||||
.then(data => {
|
.then(res => {
|
||||||
if (data) {
|
if (res) {
|
||||||
setToken(data);
|
setToken(res);
|
||||||
resolve();
|
resolve(res);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -14,6 +14,9 @@ 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
|
||||||
@ -42,12 +45,17 @@ let user = ref("admin");
|
|||||||
let pwd = ref("123456");
|
let pwd = ref("123456");
|
||||||
|
|
||||||
const onLogin = (): void => {
|
const onLogin = (): void => {
|
||||||
storageSession.setItem("info", {
|
useUserStoreHook()
|
||||||
username: "admin",
|
.loginByUsername({ username: user.value, password: pwd.value })
|
||||||
accessToken: "eyJhbGciOiJIUzUxMiJ9.test"
|
.then(async (res: any) => {
|
||||||
});
|
storageSession.setItem("info", {
|
||||||
initRouter("admin").then(() => {});
|
username: res.username,
|
||||||
router.push("/");
|
accessToken: res.accessToken
|
||||||
|
});
|
||||||
|
usePermissionStoreHook().clearAllCachePage();
|
||||||
|
initRouter(res.username);
|
||||||
|
router.push("/");
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function onUserFocus() {
|
function onUserFocus() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user