Browse Source

perf: 同步完整版代码

i18n
xiaoxian521 3 years ago
parent
commit
2bac78478c
  1. 23
      mock/user.ts
  2. 6
      src/layout/components/panel/index.vue
  3. 3
      src/layout/components/setting/index.vue
  4. 7
      src/layout/components/sidebar/horizontal.vue
  5. 1
      src/layout/components/sidebar/vertical.vue
  6. 4
      src/layout/hooks/nav.ts
  7. 6
      src/router/utils.ts
  8. 5
      src/store/modules/permission.ts
  9. 13
      src/store/modules/user.ts
  10. 14
      src/views/login.vue

23
mock/user.ts

@ -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[];

6
src/layout/components/panel/index.vue

@ -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;
overflow: auto;
height: calc(100vh - 60px);
overflow-y: auto;
} }
.project-configuration { .project-configuration {

3
src/layout/components/setting/index.vue

@ -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();
}); });

7
src/layout/components/sidebar/horizontal.vue

@ -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";

1
src/layout/components/sidebar/vertical.vue

@ -51,7 +51,6 @@ watch(
() => route.path, () => route.path,
() => { () => {
getSubMenuData(route.path); getSubMenuData(route.path);
menuSelect(route.path, routers);
} }
); );
</script> </script>

4
src/layout/hooks/nav.ts

@ -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");
router.push("/login");
useUserStoreHook().logOut();
} }
function backHome() { function backHome() {

6
src/router/utils.ts

@ -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) {

5
src/store/modules/permission.ts

@ -61,8 +61,11 @@ export const usePermissionStore = defineStore({
break; break;
} }
}, },
// 清空缓存页面
// 清空缓存
clearAllCachePage() { clearAllCachePage() {
this.wholeMenus = [];
this.menusTree = [];
this.buttonAuth = [];
this.cachePageList = []; this.cachePageList = [];
} }
} }

13
src/store/modules/user.ts

@ -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 => {
if (data) {
setToken(data);
resolve();
.then(res => {
if (res) {
setToken(res);
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", [
{ {

14
src/views/login.vue

@ -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 => {
useUserStoreHook()
.loginByUsername({ username: user.value, password: pwd.value })
.then(async (res: any) => {
storageSession.setItem("info", { storageSession.setItem("info", {
username: "admin",
accessToken: "eyJhbGciOiJIUzUxMiJ9.test"
username: res.username,
accessToken: res.accessToken
}); });
initRouter("admin").then(() => {});
usePermissionStoreHook().clearAllCachePage();
initRouter(res.username);
router.push("/"); router.push("/");
});
}; };
function onUserFocus() { function onUserFocus() {

Loading…
Cancel
Save