mirror of
https://github.com/Tencent/tdesign-vue-next-starter.git
synced 2024-11-10 07:28:24 +08:00
feat: 优化登录跳转支持回跳带query参数的页面 (#374)
This commit is contained in:
parent
6ccc3279f9
commit
6cd9fe9134
|
@ -143,7 +143,10 @@ const handleNav = (url) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
router.push(`/login?redirect=${router.currentRoute.value.fullPath}`);
|
router.push({
|
||||||
|
path: '/login',
|
||||||
|
query: { redirect: encodeURIComponent(router.currentRoute.value.fullPath) },
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const navToGitHub = () => {
|
const navToGitHub = () => {
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import QrcodeVue from 'qrcode.vue';
|
import QrcodeVue from 'qrcode.vue';
|
||||||
import { FormInstanceFunctions, MessagePlugin } from 'tdesign-vue-next';
|
import { FormInstanceFunctions, MessagePlugin } from 'tdesign-vue-next';
|
||||||
import { useCounter } from '@/hooks';
|
import { useCounter } from '@/hooks';
|
||||||
|
@ -116,6 +116,7 @@ const switchType = (val: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送验证码
|
* 发送验证码
|
||||||
|
@ -134,9 +135,9 @@ const onSubmit = async ({ validateResult }) => {
|
||||||
await userStore.login(formData.value);
|
await userStore.login(formData.value);
|
||||||
|
|
||||||
MessagePlugin.success('登陆成功');
|
MessagePlugin.success('登陆成功');
|
||||||
router.push({
|
const redirect = route.query.redirect as string;
|
||||||
path: '/dashboard/base',
|
const redirectUrl = redirect ? decodeURIComponent(redirect) : '/dashboard';
|
||||||
});
|
router.push(redirectUrl);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
MessagePlugin.error(e.message);
|
MessagePlugin.error(e.message);
|
||||||
|
|
|
@ -40,7 +40,10 @@ router.beforeEach(async (to, from, next) => {
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
MessagePlugin.error(error);
|
MessagePlugin.error(error);
|
||||||
next(`/login?redirect=${to.path}`);
|
next({
|
||||||
|
path: '/login',
|
||||||
|
query: { redirect: encodeURIComponent(to.fullPath) },
|
||||||
|
});
|
||||||
NProgress.done();
|
NProgress.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +52,10 @@ router.beforeEach(async (to, from, next) => {
|
||||||
if (whiteListRouters.indexOf(to.path) !== -1) {
|
if (whiteListRouters.indexOf(to.path) !== -1) {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
next(`/login?redirect=${to.path}`);
|
next({
|
||||||
|
path: '/login',
|
||||||
|
query: { redirect: encodeURIComponent(to.fullPath) },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
NProgress.done();
|
NProgress.done();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user