|
|
@@ -1,5 +1,6 @@
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
import {useStore} from "@/store";
|
|
|
+import authApis from "@/apis/auth";
|
|
|
|
|
|
const router = createRouter({
|
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
|
@@ -162,6 +163,27 @@ const router = createRouter({
|
|
|
*/
|
|
|
router.beforeEach((to) => {
|
|
|
const store = useStore()
|
|
|
+
|
|
|
+ // 判断是否从门户跳转过来,如果是则直接登录
|
|
|
+ if(to.path === '/login'){
|
|
|
+ if(to.query.id_token != null){
|
|
|
+ authApis.getUserByToken(to.query.id_token.toString())
|
|
|
+ .then((_res:any) => {
|
|
|
+ const data = _res.data.data
|
|
|
+ if (_res.data.code === 200) {
|
|
|
+ store.setUser(data);
|
|
|
+ store.setToken(data?.token)
|
|
|
+ localStorage.setItem('Authorization', data?.token);
|
|
|
+ localStorage.setItem('User', JSON.stringify(data));
|
|
|
+ console.log("登陆成功", data)
|
|
|
+ router.push('/home')
|
|
|
+ }
|
|
|
+ }).catch((_err:any) => {
|
|
|
+ console.log("登陆失败", _err)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 判断是否是登录页面,如果是则直接放行
|
|
|
if (to.path === '/login' || to.path === '/register' || to.path === '/passwordChange'|| to.path === '/admin/login') {
|
|
|
return true;
|