11wqe1 1 год назад
Родитель
Сommit
ffa157a043

+ 11 - 3
src/permission.js

@@ -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 })
           }

+ 1 - 0
src/store/getters.js

@@ -1,6 +1,7 @@
 const getters = {
   courseId: state => state.app.courseId,
   testId: state => state.app.testId,
+  shareCourseId: state => state.app.shareCourseId,
   id: state => state.user.id,
   userinfo: state => state.user.userinfo
 }

+ 5 - 1
src/store/modules/app.js

@@ -1,6 +1,7 @@
 const state = {
   courseId: '',
-  testId: ''
+  testId: '',
+  shareCourseId: ''
 }
 const mutations = {
   SET_COURSEID: (state, courseId) => {
@@ -8,6 +9,9 @@ const mutations = {
   },
   SET_TESTID: (state, courseId) => {
     state.testId = courseId
+  },
+  SET_SHARECOURSEID: (state, courseId) => {
+    state.shareCourseId = courseId
   }
 }
 const actions = {}

+ 1 - 1
src/views/course/index.vue

@@ -147,7 +147,7 @@ export default {
           this.courseDetail = res[0][0]
           this.chapInfo = JSON.parse(this.courseDetail.chapters)[this.courseType]
           this.chapList = JSON.parse(this.courseDetail.chapters)
-          console.log('this.courseDetail',this.chapList);
+          // console.log('this.courseDetail',this.chapList);
 
           this.oid = res[0][0].organizeid
           this.tcid = this.arrayToArray(

+ 2 - 1
src/views/courseDetail/index.vue

@@ -95,7 +95,8 @@ export default {
   },
   mounted() {
     // console.log('hahahha',!localStorage.getItem('urlType'));
-    if (localStorage.getItem('urlType')==1) {
+    // console.log('kakakaka', this.$store.getters.shareCourseId)
+    if (localStorage.getItem('urlType') == 1) {
       this.routeType = 1
     } else {
       this.routeType = 0