|
@@ -9,7 +9,7 @@ NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
|
|
const whiteList = ['/login', '/resetpassword', '/help', '/echarts'] // no redirect whitelist
|
|
|
|
|
|
// eslint-disable-next-line prettier/prettier
|
|
|
-router.beforeEach(async(to, from, next) => {
|
|
|
+router.beforeEach(async (to, from, next) => {
|
|
|
// start progress bar
|
|
|
NProgress.start()
|
|
|
// set page title
|
|
@@ -24,6 +24,9 @@ router.beforeEach(async(to, from, next) => {
|
|
|
if (to.query.testid) {
|
|
|
await store.commit('SET_TESTID', to.query.testid)
|
|
|
}
|
|
|
+ if (to.query.shareCourseId) {
|
|
|
+ await store.commit('SET_SHARECOURSEID', to.query.shareCourseId)
|
|
|
+ }
|
|
|
if (hasToken) {
|
|
|
if (to.path === '/login') {
|
|
|
// if is logged in, redirect to the home page
|
|
@@ -32,8 +35,9 @@ router.beforeEach(async(to, from, next) => {
|
|
|
NProgress.done()
|
|
|
} else {
|
|
|
const userinfo = store.getters.userinfo && Object.keys(store.getters.userinfo).length > 0
|
|
|
- console.log(store.getters)
|
|
|
- console.log(userinfo)
|
|
|
+ console.log('store.getters', store.getters)
|
|
|
+ console.log('userinfo', userinfo)
|
|
|
+ // console.log('to', {...to} )
|
|
|
if (userinfo) {
|
|
|
next()
|
|
|
} else {
|
|
@@ -43,11 +47,15 @@ router.beforeEach(async(to, from, next) => {
|
|
|
await store.commit('user/SET_USERINFO', data)
|
|
|
const courseId = store.getters.courseId
|
|
|
const testId = store.getters.testId
|
|
|
+ const shareCourseId = store.getters.shareCourseId
|
|
|
// // 根据角色生成可访问的路线图
|
|
|
if (courseId) {
|
|
|
next({ ...to, query: { courseid: courseId }, replace: true })
|
|
|
} else if (testId) {
|
|
|
next({ ...to, query: { courseid: testId }, replace: true })
|
|
|
+ } else if (shareCourseId) {
|
|
|
+ localStorage.setItem('urlType', 1)
|
|
|
+ next({ ...to, query: { courseid: shareCourseId }, replace: true })
|
|
|
} else {
|
|
|
next({ ...to, replace: true })
|
|
|
}
|