소스 검색

链接跳转

11wqe1 1 년 전
부모
커밋
bbc314ca15
5개의 변경된 파일23개의 추가작업 그리고 30개의 파일을 삭제
  1. 0 16
      src/App.vue
  2. 10 5
      src/permission.js
  3. 11 5
      src/views/courseDetail/index.vue
  4. 2 2
      src/views/home/components/courseItem.vue
  5. 0 2
      src/views/test/components/courseItem.vue

+ 0 - 16
src/App.vue

@@ -19,22 +19,6 @@ export default {
     }
   },
   created() {
-    const url = window.location.href
-    const paramRegex = /[?&]([^=#]+)=([^&#]*)/g
-    const params = {}
-    let match
-
-    while ((match = paramRegex.exec(url)) !== null) {
-      const paramName = decodeURIComponent(match[1])
-      const paramValue = decodeURIComponent(match[2])
-      params[paramName] = paramValue
-    }
-    // console.log('window.location.href', params)
-    // console.log('params99999999999999999999',params);
-    if (!!params.shareCourseId) {
-      localStorage.setItem('urlType',1)
-      this.$router.push(`/courseDetail?courseid=${params.shareCourseId}`)
-    }
     console.log(this.$wx)
   },
   methods: {

+ 10 - 5
src/permission.js

@@ -18,14 +18,16 @@ router.beforeEach(async(to, from, next) => {
   // const hasToken = getToken()
   const hasToken = store.getters.id
 
-  if (to.query.courseid) {
+  if (to.query.courseid !== '' && to.query.courseid !== undefined) {
+    console.log(to.query.courseid);
     await store.commit('SET_COURSEID', to.query.courseid)
   }
-  if (to.query.testid) {
+  if (to.query.testid !== '' && to.query.testid !== undefined) {
     await store.commit('SET_TESTID', to.query.testid)
   }
-  if (to.query.shareCourseId) {
-    await store.commit('SET_SHARECOURSEID', to.query.shareCourseId)
+  let shareCourseId = window.location.href.indexOf("?shareCourseId=")!=-1?window.location.href.split("?shareCourseId=")[1].toString():''
+  if (shareCourseId) {
+    await store.commit('SET_SHARECOURSEID', shareCourseId)
   }
   if (hasToken) {
     if (to.path === '/login') {
@@ -48,13 +50,16 @@ router.beforeEach(async(to, from, next) => {
           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({ ...to, query: { courseid: courseId }, replace: true })
           } else if (testId) {
             next({ ...to, query: { courseid: testId }, replace: true })
           } else if (shareCourseId) {
-            next({ path: '/course', query: { courseid: shareCourseId, urlType: 1 }, replace: true })
+            next({ path: '/courseDetail', query: { courseid: shareCourseId, urlType: 1 }, replace: true })
           } else {
             next({ ...to, replace: true })
           }

+ 11 - 5
src/views/courseDetail/index.vue

@@ -94,13 +94,19 @@ export default {
     }
   },
   mounted() {
+    console.log('type', this.$route.query)
+    if (this.$route.query.urlType) {
+      localStorage.setItem('urlType', this.$route.query.urlType)
+    }
+
+    this.routeType = localStorage.getItem('urlType')
     // console.log('hahahha',!localStorage.getItem('urlType'));
     // console.log('kakakaka', this.$store.getters.shareCourseId)
-    if (localStorage.getItem('urlType') == 1) {
-      this.routeType = 1
-    } else {
-      this.routeType = 0
-    }
+    // if (localStorage.getItem('urlType') == 1) {
+    //   this.routeType = 1
+    // } else {
+    //   this.routeType = 0
+    // }
     this.getCourse()
   }
 }

+ 2 - 2
src/views/home/components/courseItem.vue

@@ -40,9 +40,9 @@ export default {
   },
   methods: {
     goTo(cid) {
-      localStorage.setItem('urlType',0)
+      // localStorage.setItem('urlType',0)
       // eslint-disable-next-line prettier/prettier
-      this.$router.push({ path: '/courseDetail', query: { courseid: cid} })
+      this.$router.push({ path: '/courseDetail', query: { courseid: cid , urlType: 0 } })
     }
   }
 }

+ 0 - 2
src/views/test/components/courseItem.vue

@@ -164,8 +164,6 @@ export default {
     },
     goTo(cid) {
       // return console.log(cid)
-      debugger
-
       // eslint-disable-next-line prettier/prettier
       this.$router.push({ path: '/testDetail', query: { courseid: cid.courseId, userid: cid.userid }})
     },