|
@@ -19,12 +19,14 @@ router.beforeEach(async(to, from, next) => {
|
|
|
// determine whether the user has logged in
|
|
|
// const hasToken = getToken()
|
|
|
const hasToken = store.getters.id || getToken()
|
|
|
- const isWeChat = Cookies.get('isWeChat')
|
|
|
+ let isWeChat = Cookies.get('isWeChat')
|
|
|
if (to.query.courseid !== '' && to.query.courseid !== undefined) {
|
|
|
console.log(to.query.courseid)
|
|
|
+ isWeChat = '1'
|
|
|
await store.commit('SET_COURSEID', to.query.courseid)
|
|
|
}
|
|
|
if (to.query.testid !== '' && to.query.testid !== undefined) {
|
|
|
+ isWeChat = '1'
|
|
|
await store.commit('SET_TESTID', to.query.testid)
|
|
|
}
|
|
|
const shareCourseId =
|
|
@@ -32,15 +34,38 @@ router.beforeEach(async(to, from, next) => {
|
|
|
? window.location.href.split('?shareCourseId=')[1].toString()
|
|
|
: ''
|
|
|
if (shareCourseId) {
|
|
|
+ isWeChat = '1'
|
|
|
await store.commit('SET_SHARECOURSEID', shareCourseId)
|
|
|
}
|
|
|
if (hasToken) {
|
|
|
if (to.path === '/login' || to.path === '/login2') {
|
|
|
// if is logged in, redirect to the home page
|
|
|
store.commit('user/SET_ID', hasToken)
|
|
|
- if(isWeChat == '1'){
|
|
|
- next({ path: '/' })
|
|
|
- }else {
|
|
|
+ if (isWeChat === '1') {
|
|
|
+ const courseId = store.getters.courseId
|
|
|
+ const testId = store.getters.testId
|
|
|
+ const shareCourseId = store.getters.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({ path: '/' })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
next('/appStoreCopy')
|
|
|
}
|
|
|
NProgress.done()
|
|
@@ -64,11 +89,15 @@ router.beforeEach(async(to, from, next) => {
|
|
|
await store.commit('SET_SHARECOURSEID', '')
|
|
|
// // 根据角色生成可访问的路线图
|
|
|
if (courseId) {
|
|
|
- next({ ...to, query: { courseid: courseId }, replace: true })
|
|
|
+ next({ ...to, query: { courseid: courseId, userid: hasToken }, replace: true })
|
|
|
} else if (testId) {
|
|
|
- next({ ...to, query: { courseid: testId }, replace: true })
|
|
|
+ next({ ...to, query: { courseid: testId, userid: hasToken }, replace: true })
|
|
|
} else if (shareCourseId) {
|
|
|
- next({ path: '/courseDetail', query: { courseid: shareCourseId, urlType: 1 }, replace: true })
|
|
|
+ next({
|
|
|
+ path: '/courseDetail',
|
|
|
+ query: { courseid: shareCourseId, urlType: 1, userid: hasToken },
|
|
|
+ replace: true
|
|
|
+ })
|
|
|
} else {
|
|
|
next({ ...to, replace: true })
|
|
|
}
|