Browse Source

perf: 同步完整版代码

i18n
xiaoxian521 3 years ago
parent
commit
736f1c27cd
  1. 23
      mock/user.ts
  2. 4
      src/layout/components/navbar.vue
  3. 4
      src/layout/components/sidebar/horizontal.vue
  4. 4
      src/layout/components/sidebar/mixNav.vue
  5. 8
      src/layout/hooks/nav.ts
  6. 5
      src/store/modules/permission.ts
  7. 10
      src/store/modules/user.ts
  8. 20
      src/views/login.vue

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

4
src/layout/components/navbar.vue

@ -23,7 +23,7 @@ const {
changeTitle,
toggleSideBar,
pureApp,
usename,
username,
getDropdownItemStyle
} = useNav();
@ -94,7 +94,7 @@ function translationEn() {
<el-dropdown trigger="click">
<span class="el-dropdown-link">
<img :src="avatars" />
<p>{{ usename }}</p>
<p>{{ username }}</p>
</span>
<template #dropdown>
<el-dropdown-menu class="logout">

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

@ -29,7 +29,7 @@ const {
changeTitle,
handleResize,
menuSelect,
usename,
username,
getDropdownItemStyle
} = useNav();
@ -115,7 +115,7 @@ function translationEn() {
<el-dropdown trigger="click">
<span class="el-dropdown-link">
<img :src="avatars" />
<p>{{ usename }}</p>
<p>{{ username }}</p>
</span>
<template #dropdown>
<el-dropdown-menu class="logout">

4
src/layout/components/sidebar/mixNav.vue

@ -32,7 +32,7 @@ const {
menuSelect,
resolvePath,
pureApp,
usename,
username,
getDropdownItemStyle
} = useNav();
@ -167,7 +167,7 @@ function translationEn() {
<el-dropdown trigger="click">
<span class="el-dropdown-link">
<img :src="avatars" />
<p>{{ usename }}</p>
<p>{{ username }}</p>
</span>
<template #dropdown>
<el-dropdown-menu class="logout">

8
src/layout/hooks/nav.ts

@ -7,13 +7,12 @@ 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() {
const pureApp = useAppStoreHook();
// 用户名
const usename: string = storageSession.getItem("info")?.username;
const username: string = storageSession.getItem("info")?.username;
// 设置国际化选中后的样式
const getDropdownItemStyle = computed(() => {
@ -39,7 +38,8 @@ export function useNav() {
// 退出登录
function logout() {
useUserStoreHook().logOut();
storageSession.removeItem("info");
router.push("/login");
}
function backHome() {
@ -112,7 +112,7 @@ export function useNav() {
resolvePath,
isCollapse,
pureApp,
usename,
username,
getDropdownItemStyle
};
}

5
src/store/modules/permission.ts

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

10
src/store/modules/user.ts

@ -33,12 +33,12 @@ export const useUserStore = defineStore({
},
// 登入
async loginByUsername(data) {
return new Promise((resolve, reject) => {
return new Promise<void>((resolve, reject) => {
getLogin(data)
.then(res => {
if (res) {
setToken(res);
resolve(res);
.then(data => {
if (data) {
setToken(data);
resolve();
}
})
.catch(error => {

20
src/views/login.vue

@ -8,26 +8,18 @@ import bg from "/@/assets/login/bg.png";
import avatar from "/@/assets/login/avatar.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();
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() {

Loading…
Cancel
Save