perf:优化未登陆时的跳转路由体验
This commit is contained in:
@@ -80,8 +80,6 @@ export default function useAuths(opt) {
|
|||||||
Session.clear();
|
Session.clear();
|
||||||
Local.clear();
|
Local.clear();
|
||||||
removeToken();
|
removeToken();
|
||||||
window.location.reload();
|
|
||||||
Session.set("vuex", null);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 用户名密码登录
|
// 用户名密码登录
|
||||||
@@ -116,10 +114,16 @@ export default function useAuths(opt) {
|
|||||||
// 存储用户信息
|
// 存储用户信息
|
||||||
await getUserInfo(); // 用户信息
|
await getUserInfo(); // 用户信息
|
||||||
// 登录成功后 路由跳转
|
// 登录成功后 路由跳转
|
||||||
router.replace({
|
// 如果有记录当前跳转页面
|
||||||
path: option.loginReUrl ? option.loginReUrl : option.homeUrl,
|
const currentPath = Session.get("currentPath");
|
||||||
query: option.otherQuery,
|
if (currentPath) {
|
||||||
});
|
router.push(currentPath);
|
||||||
|
} else {
|
||||||
|
router.replace({
|
||||||
|
path: option.loginReUrl ? option.loginReUrl : option.homeUrl,
|
||||||
|
query: option.otherQuery,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
removeToken();
|
removeToken();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -69,14 +69,16 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import AvatarInfo from "@/components/AvatarInfo.vue";
|
import AvatarInfo from "@/components/AvatarInfo.vue";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
import useUserStore from "@/stores/user.js";
|
import useUserStore from "@/stores/user.js";
|
||||||
import useConfigStore from "@/stores/config";
|
import useConfigStore from "@/stores/config";
|
||||||
import useAuths from "@/hooks/useAuths";
|
import useAuths from "@/hooks/useAuths";
|
||||||
|
import { Session } from "@/utils/storage";
|
||||||
|
|
||||||
const { getToken } = useAuths();
|
const { getToken } = useAuths();
|
||||||
const configStore = useConfigStore();
|
const configStore = useConfigStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const activeIndex = ref("1");
|
const activeIndex = ref("1");
|
||||||
const searchText = ref("");
|
const searchText = ref("");
|
||||||
@@ -106,6 +108,7 @@ const enterProfile = () => {
|
|||||||
router.push("/profile");
|
router.push("/profile");
|
||||||
};
|
};
|
||||||
const toLogin = () => {
|
const toLogin = () => {
|
||||||
|
Session.set("currentPath", route.path);
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
};
|
};
|
||||||
const search = () => {
|
const search = () => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { getUserDetailInfo } from "@/apis/auth";
|
|||||||
import useAuths from "@/hooks/useAuths";
|
import useAuths from "@/hooks/useAuths";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
|
|
||||||
const { getToken, setToken, removeToken } = useAuths();
|
const { getToken, setToken, clearStorage } = useAuths();
|
||||||
|
|
||||||
const useUserStore = defineStore("user", {
|
const useUserStore = defineStore("user", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -81,7 +81,7 @@ const useUserStore = defineStore("user", {
|
|||||||
this.token = "";
|
this.token = "";
|
||||||
this.roles = [];
|
this.roles = [];
|
||||||
this.permissions = [];
|
this.permissions = [];
|
||||||
removeToken();
|
clearStorage();
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user