mirror of
https://github.com/pure-admin/pure-admin-thin.git
synced 2025-04-24 23:47:17 +08:00
perf: 同步完整版代码
This commit is contained in:
parent
bc8a0f3b35
commit
2bac78478c
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[];
|
@ -54,7 +54,7 @@ emitter.on("openPanel", () => {
|
|||||||
|
|
||||||
.right-panel {
|
.right-panel {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 300px;
|
max-width: 315px;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -105,8 +105,8 @@ emitter.on("openPanel", () => {
|
|||||||
|
|
||||||
.right-panel-items {
|
.right-panel-items {
|
||||||
margin-top: 60px;
|
margin-top: 60px;
|
||||||
height: 100vh;
|
height: calc(100vh - 60px);
|
||||||
overflow: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.project-configuration {
|
.project-configuration {
|
||||||
|
@ -266,6 +266,7 @@ function setLayoutThemeColor(theme: string) {
|
|||||||
|
|
||||||
// 设置ep主题色
|
// 设置ep主题色
|
||||||
const setEpThemeColor = (color: string) => {
|
const setEpThemeColor = (color: string) => {
|
||||||
|
// @ts-expect-error
|
||||||
writeNewStyle(createNewStyle(color));
|
writeNewStyle(createNewStyle(color));
|
||||||
useEpThemeStoreHook().setEpThemeColor(color);
|
useEpThemeStoreHook().setEpThemeColor(color);
|
||||||
body.style.setProperty("--el-color-primary-active", shadeBgColor(color));
|
body.style.setProperty("--el-color-primary-active", shadeBgColor(color));
|
||||||
@ -298,7 +299,7 @@ nextTick(() => {
|
|||||||
settings.weakVal &&
|
settings.weakVal &&
|
||||||
document.querySelector("html")?.setAttribute("class", "html-weakness");
|
document.querySelector("html")?.setAttribute("class", "html-weakness");
|
||||||
settings.tabsVal && tagsChange();
|
settings.tabsVal && tagsChange();
|
||||||
|
// @ts-expect-error
|
||||||
writeNewStyle(createNewStyle(epThemeColor.value));
|
writeNewStyle(createNewStyle(epThemeColor.value));
|
||||||
dataThemeChange();
|
dataThemeChange();
|
||||||
});
|
});
|
||||||
|
@ -46,13 +46,6 @@ watch(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
|
||||||
() => route.path,
|
|
||||||
() => {
|
|
||||||
menuSelect(route.path, routers);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
function translationCh() {
|
function translationCh() {
|
||||||
instance.locale = { locale: "zh" };
|
instance.locale = { locale: "zh" };
|
||||||
locale.value = "zh";
|
locale.value = "zh";
|
||||||
|
@ -51,7 +51,6 @@ watch(
|
|||||||
() => route.path,
|
() => route.path,
|
||||||
() => {
|
() => {
|
||||||
getSubMenuData(route.path);
|
getSubMenuData(route.path);
|
||||||
menuSelect(route.path, routers);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
@ -7,6 +7,7 @@ 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() {
|
||||||
@ -38,8 +39,7 @@ export function useNav() {
|
|||||||
|
|
||||||
// 退出登录
|
// 退出登录
|
||||||
function logout() {
|
function logout() {
|
||||||
storageSession.removeItem("info");
|
useUserStoreHook().logOut();
|
||||||
router.push("/login");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function backHome() {
|
function backHome() {
|
||||||
|
@ -234,7 +234,11 @@ function addAsyncRoutes(arrRoutes: Array<RouteRecordRaw>) {
|
|||||||
} else if (v.meta?.frameSrc) {
|
} else if (v.meta?.frameSrc) {
|
||||||
v.component = IFrame;
|
v.component = IFrame;
|
||||||
} else {
|
} else {
|
||||||
const index = modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
|
// 对后端传component组件路径和不传做兼容(如果后端传component组件路径,那么path可以随便写,如果不传,component组件路径会根path保持一致)
|
||||||
|
const index = v?.component
|
||||||
|
? // @ts-expect-error
|
||||||
|
modulesRoutesKeys.findIndex(ev => ev.includes(v.component))
|
||||||
|
: modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
|
||||||
v.component = modulesRoutes[modulesRoutesKeys[index]];
|
v.component = modulesRoutes[modulesRoutesKeys[index]];
|
||||||
}
|
}
|
||||||
if (v.children) {
|
if (v.children) {
|
||||||
|
@ -61,8 +61,11 @@ export const usePermissionStore = defineStore({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 清空缓存页面
|
// 清空缓存
|
||||||
clearAllCachePage() {
|
clearAllCachePage() {
|
||||||
|
this.wholeMenus = [];
|
||||||
|
this.menusTree = [];
|
||||||
|
this.buttonAuth = [];
|
||||||
this.cachePageList = [];
|
this.cachePageList = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ import { defineStore } from "pinia";
|
|||||||
import { store } from "/@/store";
|
import { store } from "/@/store";
|
||||||
import { userType } from "./types";
|
import { userType } from "./types";
|
||||||
import { router } from "/@/router";
|
import { router } from "/@/router";
|
||||||
|
import { storageSession } from "/@/utils/storage";
|
||||||
import { getLogin, refreshToken } from "/@/api/user";
|
import { getLogin, refreshToken } from "/@/api/user";
|
||||||
import { storageLocal, storageSession } from "/@/utils/storage";
|
|
||||||
import { getToken, setToken, removeToken } from "/@/utils/auth";
|
import { getToken, setToken, removeToken } from "/@/utils/auth";
|
||||||
import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
|
import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
|
||||||
|
|
||||||
@ -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 => {
|
||||||
@ -51,7 +51,6 @@ export const useUserStore = defineStore({
|
|||||||
this.token = "";
|
this.token = "";
|
||||||
this.name = "";
|
this.name = "";
|
||||||
removeToken();
|
removeToken();
|
||||||
storageLocal.clear();
|
|
||||||
storageSession.clear();
|
storageSession.clear();
|
||||||
useMultiTagsStoreHook().handleTags("equal", [
|
useMultiTagsStoreHook().handleTags("equal", [
|
||||||
{
|
{
|
||||||
|
@ -8,18 +8,26 @@ import bg from "/@/assets/login/bg.png";
|
|||||||
import avatar from "/@/assets/login/avatar.svg?component";
|
import avatar from "/@/assets/login/avatar.svg?component";
|
||||||
import illustration from "/@/assets/login/illustration.svg?component";
|
import illustration from "/@/assets/login/illustration.svg?component";
|
||||||
|
|
||||||
|
import { useUserStoreHook } from "/@/store/modules/user";
|
||||||
|
import { usePermissionStoreHook } from "/@/store/modules/permission";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
let user = ref("admin");
|
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