|
@@ -124,6 +124,7 @@ onBeforeMount(async () => {
|
|
|
const router = useRouter();
|
|
|
// 登录成功后的跳转
|
|
|
const signInSuccess = (isNoPower: boolean | undefined) => {
|
|
|
+ window.history.replaceState({}, document.title, window.location.pathname);
|
|
|
if (isNoPower) {
|
|
|
ElNotification({
|
|
|
title: '提示',
|
|
@@ -133,6 +134,9 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
|
|
|
Session.clear();
|
|
|
Cookie.clear();
|
|
|
Local.clear();
|
|
|
+ setTimeout(()=>{
|
|
|
+ window.location.reload();
|
|
|
+ },2000)
|
|
|
} else {
|
|
|
router.push('/');
|
|
|
// 设置登录成功后的时间问候语
|
|
@@ -192,48 +196,24 @@ onMounted(() => {
|
|
|
// 获取url特殊参数 实现登录跳转
|
|
|
// 单点登录进来的参数
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
- const source = urlParams.get('source');
|
|
|
- const username = urlParams.get('username');
|
|
|
+ const source = urlParams.get('token');
|
|
|
// 判断是否是单点登录
|
|
|
- const isSingleSignOn = source === 'oldhotline' && username;
|
|
|
- if (isSingleSignOn) {
|
|
|
+ if (source) {
|
|
|
Cookie.remove('token');
|
|
|
- getTokenByUrl({ userName: username })
|
|
|
- .then(async (res: any) => {
|
|
|
- //登录
|
|
|
- // 存储 token 到浏览器缓存
|
|
|
- Cookie.set('token', res.result);
|
|
|
- window.history.replaceState({}, document.title, window.location.pathname);
|
|
|
- if (!themeConfig.value.isRequestRoutes) {
|
|
|
- // 前端控制路由,2、请注意执行顺序
|
|
|
- const isNoPower = await initFrontEndControlRoutes();
|
|
|
- signInSuccess(isNoPower);
|
|
|
- } else {
|
|
|
- // 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
|
|
|
- // 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
|
|
|
- const isNoPower = await initBackEndControlRoutes();
|
|
|
- // 执行完 initBackEndControlRoutes,再执行 signInSuccess
|
|
|
- signInSuccess(isNoPower);
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((err) => {
|
|
|
- const message = err.response.data.message;
|
|
|
- ElMessageBox.alert(message, '登录失败', {
|
|
|
- confirmButtonText: '确定',
|
|
|
- type: 'error',
|
|
|
- showClose: false,
|
|
|
- draggable: true,
|
|
|
- callback: () => {
|
|
|
- window.history.replaceState({}, document.title, window.location.pathname);
|
|
|
- // 清除缓存/token等
|
|
|
- Local.clear();
|
|
|
- Session.clear();
|
|
|
- Cookie.clear();
|
|
|
- // 使用 reload 时,不需要调用 resetRoute() 重置路由
|
|
|
- window.location.reload();
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
+ //登录
|
|
|
+ // 存储 token 到浏览器缓存
|
|
|
+ Cookie.set('token', source);
|
|
|
+ if (!themeConfig.value.isRequestRoutes) {
|
|
|
+ // 前端控制路由,2、请注意执行顺序
|
|
|
+ const isNoPower = await initFrontEndControlRoutes();
|
|
|
+ signInSuccess(isNoPower);
|
|
|
+ } else {
|
|
|
+ // 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
|
|
|
+ // 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
|
|
|
+ const isNoPower = await initBackEndControlRoutes();
|
|
|
+ // 执行完 initBackEndControlRoutes,再执行 signInSuccess
|
|
|
+ signInSuccess(isNoPower);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log(error);
|