fix:修复用户登录和切换访客登录的问题

This commit is contained in:
Xwen
2023-12-16 10:03:29 +08:00
parent a03a7162dd
commit 3a2d8846bc
5 changed files with 27 additions and 5 deletions

View File

@@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1702690681392" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3423" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M575.215 547.318c53.367-24.316 90.562-78.011 90.562-140.522 0-85.257-69.149-154.383-154.406-154.383-85.299 0-154.427 69.126-154.427 154.383 0 62.49 37.172 116.185 90.562 140.522-87.156 27.24-150.586 108.698-150.586 204.715 0 12.071 9.779 21.827 21.827 21.827s21.827-9.756 21.827-21.827c0-94.161 76.613-170.774 170.776-170.774 94.184 0 170.797 76.613 170.797 170.774 0 12.071 9.756 21.827 21.827 21.827 12.07 0 21.827-9.756 21.827-21.827 0.021-95.994-63.43-177.475-150.586-204.715zM400.621 406.817c0-61.072 49.678-110.729 110.773-110.729 61.072 0 110.75 49.657 110.75 110.729 0 61.094-49.678 110.794-110.75 110.794-61.095 0-110.773-49.7-110.773-110.794z" p-id="3424" fill="#515151"></path><path d="M511.371 960.81c-246.951 0-447.869-200.918-447.869-447.891 0-246.93 200.919-447.871 447.869-447.871 246.973 0 447.892 200.919 447.892 447.871 0 246.973-200.919 447.891-447.892 447.891z m0-854.269c-224.098 0-406.398 182.301-406.398 406.377s182.3 406.397 406.398 406.397c224.099 0 406.42-182.321 406.42-406.397S735.47 106.541 511.371 106.541z" p-id="3425" fill="#515151"></path></svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -96,7 +96,7 @@ const Init = () => {
userInfo.nick = userStore.name;
userInfo.role = userStore.role;
userInfo.id = userStore.id;
iconUrl.value = iconUrlHandler(userInfo.icon);
iconUrl.value = userInfo.icon;
}
};
</script>
@@ -134,7 +134,8 @@ const Init = () => {
}
.el-avatar {
margin-right: 1.2rem;
margin-right: 1rem;
--el-avatar-bg-color: none;
}
.remarks {

View File

@@ -51,13 +51,16 @@
<el-dropdown trigger="click">
<AvatarInfo :size="30" :isSelf="true" />
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-menu v-if="isLogin">
<el-dropdown-item @click="enterProfile"
>进入个人中心</el-dropdown-item
>
<el-dropdown-item @click="enterProfile">其他</el-dropdown-item>
<el-dropdown-item @click="logout">登出</el-dropdown-item>
</el-dropdown-menu>
<el-dropdown-menu v-else="isLogin">
<el-dropdown-item @click="toLogin">去登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
@@ -69,6 +72,9 @@ import { ref } from "vue";
import { useRouter } from "vue-router";
import useUserStore from "@/stores/user.js";
import useConfigStore from "@/stores/config";
import useAuths from "@/hooks/useAuths";
const { getToken } = useAuths();
const configStore = useConfigStore();
const router = useRouter();
const userStore = useUserStore();
@@ -99,12 +105,16 @@ const enterIndex = () => {
const enterProfile = () => {
router.push("/profile");
};
const toLogin = () => {
router.push("/login");
};
const search = () => {
var routerPer = { path: `/discuss`, query: { q: searchText.value } };
searchText.value = "";
router.push(routerPer);
};
const isLogin = getToken("AccessToken") ? true : false;
</script>
<style scoped lang="scss">

View File

@@ -42,6 +42,7 @@ router.beforeEach((to, from, next) => {
next();
} else {
next();
useUserStore().resetInfo();
// next(`/login?redirect=${to.path}&unTourist=true`); // 否则全部重定向到登录页
NProgress.done();
}

View File

@@ -1,4 +1,4 @@
import { login, logout, getInfo, register } from "@/apis/accountApi";
import { login, logout, register } from "@/apis/accountApi";
import { getUserDetailInfo } from "@/apis/auth";
import useAuths from "@/hooks/useAuths";
import { defineStore } from "pinia";
@@ -106,6 +106,15 @@ const useUserStore = defineStore("user", {
});
});
},
// 重置用户信息
resetInfo() {
this.roles = [];
this.permissions = [];
this.name = "未登录";
this.icon = "/src/assets/common/icons/login.svg";
this.userName = "";
this.id = "";
},
},
});
export default useUserStore;