|
@@ -5,6 +5,7 @@ import 'nprogress/nprogress.css' // progress bar style
|
|
|
// import { getToken } from '@/utils/auth' // get token from cookie
|
|
|
import Cookies from 'js-cookie'
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
+import user from './store/modules/user'
|
|
|
|
|
|
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
|
|
|
|
@@ -38,6 +39,7 @@ router.beforeEach(async(to, from, next) => {
|
|
|
await store.commit('SET_SHARECOURSEID', shareCourseId)
|
|
|
}
|
|
|
if (hasToken) {
|
|
|
+ await store.commit('user/SET_ID', hasToken)
|
|
|
if (to.path === '/login' || to.path === '/login2') {
|
|
|
// if is logged in, redirect to the home page
|
|
|
store.commit('user/SET_ID', hasToken)
|
|
@@ -75,33 +77,12 @@ router.beforeEach(async(to, from, next) => {
|
|
|
console.log('userinfo', userinfo)
|
|
|
// console.log('to', {...to} )
|
|
|
if (userinfo) {
|
|
|
- const data = await store.dispatch('user/getInfo')
|
|
|
- await store.commit('user/SET_USERINFO', data)
|
|
|
-
|
|
|
- const courseId = to.query.courseid
|
|
|
- const testId = to.query.testid
|
|
|
- const shareCourseId = to.query.shareCourseId
|
|
|
- await store.commit('SET_TESTID', '')
|
|
|
- await store.commit('SET_COURSEID', '')
|
|
|
- await store.commit('SET_SHARECOURSEID', '')
|
|
|
-
|
|
|
- // // 根据角色生成可访问的路线图
|
|
|
- if (courseId) {
|
|
|
- next({ path: '/courseDetail', query: { courseid: courseId, userid: hasToken }, replace: true })
|
|
|
- } else if (testId) {
|
|
|
- next({ path: '/testDetail', query: { courseid: testId, userid: hasToken }, replace: true })
|
|
|
- } else if (shareCourseId) {
|
|
|
- next({
|
|
|
- path: '/courseDetail',
|
|
|
- query: { courseid: shareCourseId, urlType: 1, userid: hasToken },
|
|
|
- replace: true
|
|
|
- })
|
|
|
- } else {
|
|
|
- next()
|
|
|
- }
|
|
|
+ console.log(store)
|
|
|
+ next()
|
|
|
} else {
|
|
|
try {
|
|
|
// 获取用户信息
|
|
|
+ console.log(store)
|
|
|
const data = await store.dispatch('user/getInfo')
|
|
|
await store.commit('user/SET_USERINFO', data)
|
|
|
const courseId = store.getters.courseId
|
|
@@ -128,6 +109,7 @@ router.beforeEach(async(to, from, next) => {
|
|
|
// remove token and go to login page to re-login
|
|
|
// await store.dispatch('user/resetToken')
|
|
|
// Notify({ type: 'danger', message: error || '发生异常' })
|
|
|
+ console.error(error)
|
|
|
next(`/login?redirect=${to.path}`)
|
|
|
NProgress.done()
|
|
|
}
|