Browse Source

单点登录

谢杰标 3 years ago
parent
commit
7ba68ec0be

+ 8 - 0
src/apis/login.js

@@ -15,6 +15,14 @@ export default {
     })
   },
 
+  skipLogin(data) {
+    return request({
+      url: '/app/common/telphone_login',
+			method: 'post',
+			data: data,
+			noToken: true
+    })
+  },
   /**
    * 
    * @param {*} data 

+ 2 - 2
src/common/tools.js

@@ -48,14 +48,14 @@ export default {
 		return sessionStorage.getItem('uuid')
 	},
 
-	exit() {
+	exit(isJ = true) {
 
 		localStorage.removeItem('user_account')
 		localStorage.removeItem('token')
 		sessionStorage.removeItem('uuid')
 		store.state.userInfo = null
 
-		if (router.currentRoute.path != '/home') {
+		if (router.currentRoute.path != '/home'&&isJ) {
 			router.replace({
 				path: '/home'
 			})

+ 22 - 14
src/components/courseTree/CourseTree.vue

@@ -595,7 +595,6 @@ export default {
       teaIndex: 0,
       nowTime: 0,
       treeList: [],
-      query: this.$route.query,
       sectionExam: [],
       sectionExamList: [],
       dialogPalyVisible: false,
@@ -608,32 +607,22 @@ export default {
   methods: {
     async init() {
       this.nowTime = Number(new Date().getTime() / 1000).toFixed(0);
+      await this.getAllSectionList();
       this.treeList = await this.getDoubleTeacherList();
       let sectionItem = await this.backNextItem(
         this.treeList.find((e) => e.courseId == this.activeCourseId),
         0,
         false
       );
-      console.log(sectionItem, "sectionItem");
       if (this.query.sectionType == 1 && !!this.query.rebuild == this.rebuild) {
         this.toPlay(sectionItem);
       }
-      this.getAllSectionList();
     },
     activeFunc(courseId, index) {
       let { courseId: nowCourseId, courseList } = this.treeList[index];
       if (courseId == nowCourseId) {
         return;
       }
-      // if (index) {
-      //   let { stuAllNum, secAllNum } = this.treeList[index - 1];
-      //   if (stuAllNum != secAllNum) {
-      //     return this.$message({
-      //       type: "warning",
-      //       message: "需按课程顺序学习",
-      //     });
-      //   }
-      // }
       let course = this.courseList.find((e) => e.courseId == courseId);
       if (course) {
         course.courseList = courseList;
@@ -675,6 +664,7 @@ export default {
         });
     },
     openModule(module, isFresh = false) {
+      console.log("openModule");
       let { list, isRebuild, id, courseId, showList } = module;
       if (!isFresh) {
         module.showList = !showList;
@@ -746,14 +736,25 @@ export default {
         });
     },
     getAllSectionList() {
-      this.$request
+      return this.$request
         .getAllSectionList({
           gradeId: this.gradeId,
           goodsId: this.goodsId,
           rebuild: this.rebuild,
         })
         .then((res) => {
+          let { skipPort } = this.query;
+          if (skipPort) {
+            let { moduleId, chapterId, sectionId } = res.data[0];
+            const query = JSON.parse(JSON.stringify(this.$route.query));
+            query.moduleId = moduleId;
+            query.chapterId = chapterId;
+            query.sectionId = sectionId;
+            query.skipPort = undefined;
+            this.$router.push({ path: this.$route.path, query });
+          }
           this.allSectionList = res.data;
+          return Promise.resolve(res.data);
         });
     },
     /**
@@ -1128,11 +1129,18 @@ export default {
     },
   },
   computed: {
+    query() {
+      return this.$route.query;
+    },
     gradeId() {
       return this.query.gradeId;
     },
     activeCourseId() {
-      return this.query.courseId;
+      let courseId = this.query.courseId;
+      if (!courseId) {
+        courseId = this.treeList[0].courseId;
+      }
+      return courseId;
     },
     goodsId() {
       return this.$route.params.goodsId;

+ 6 - 2
src/pages/person-center/my-bank/index/index.vue

@@ -109,6 +109,7 @@ export default {
     getInfoData(data) {
       return new Promise((resolve, reject) => {
         this.$request.goodsDetail(data.goodsId).then((res) => {
+          console.log(res.data, 6666, data.orderGoodsId);
           res.data.orderGoodsId = data.orderGoodsId;
           resolve(res.data);
         });
@@ -116,7 +117,8 @@ export default {
     },
     getList() {
       this.$request.examrecordgetUserDoLast().then(async (res) => {
-        if (res.data && res.data.goodsId) {
+        let { goodsId } = this.$route.query;
+        if (res.data && res.data.goodsId && !goodsId) {
           const result = await this.getInfoData(res.data);
           this.bankData = result;
           this.$nextTick(() => {
@@ -127,7 +129,9 @@ export default {
             .bankquestionlistUserFreeUnionBuyGoodsList()
             .then((res) => {
               if (res.rows.length > 0) {
-                this.bankData = res.rows[0];
+                this.bankData = !goodsId
+                  ? res.rows[0]
+                  : res.rows.find((e) => e.goodsId == goodsId);
                 this.$nextTick(() => {
                   this.$refs.bankDetailCopy.initData(this.bankData);
                 });

+ 15 - 14
src/router/index.js

@@ -10,6 +10,7 @@ let bankAdmin = ['/person-center/bank-record', '/person-center/my-bank/index', '
 let canToBank = null;
 let courseAdmin = ['/my-course-detail/', '/course-exam/']
 let canToCourse = null;
+const signLoginPage = ['/my-course-detail', '/my-bank', '/my-live']
 
 const router = new Router({
   mode: 'history',
@@ -641,9 +642,7 @@ Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch((err) => err)
 }
 
-router.beforeEach((to, from, next) => {
-  console.log(to, 'to')
-  console.log(from, 'from')
+router.beforeEach(async (to, from, next) => {
   if (to.meta.content) {
     let head = document.getElementsByTagName('head');
     let meta = document.createElement('meta');
@@ -652,6 +651,7 @@ router.beforeEach((to, from, next) => {
     meta.content = to.meta.content;
     head[0].appendChild(meta)
   }
+
   if (to.meta.title) {
     document.title = to.meta.title;
   }
@@ -659,7 +659,7 @@ router.beforeEach((to, from, next) => {
     if (canToBank) {
       clearInterval(canToBank)
       canToBank = null;
-    } 
+    }
     if (canToCourse) {
       clearInterval(canToCourse)
       canToCourse = null;
@@ -668,9 +668,18 @@ router.beforeEach((to, from, next) => {
     next();
 
   } else {
-
+    // 处理携带skipPort隐式登录
+    let { skipPort } = to.query
+    if (skipPort && signLoginPage.some(path => to.path.includes(path))) {
+      try {
+        let { data } = await request.skipLogin({ sign: skipPort })
+        localStorage.setItem("user_account", data.user_account);
+        localStorage.setItem("token", data.token);
+      } catch (error) {
+        next('/login')
+      }
+    }
     let token = window.localStorage.getItem('token');
-
     //进入页面有token获取用户信息
     if (token) {
       store.token = token;
@@ -684,7 +693,6 @@ router.beforeEach((to, from, next) => {
       let isBankLock = bankAdmin.some(item => {
         return to.path.indexOf(item) != -1
       })
-      console.log(isBankLock, 'isBankLock', canToBank)
       if (isBankLock) {
 
         //没有执行定时器,开启锁定
@@ -754,8 +762,6 @@ router.beforeEach((to, from, next) => {
       let isCourseLock = courseAdmin.some(item => {
         return to.path.indexOf(item) != -1
       })
-
-      console.log(isCourseLock, 'isCourseLock')
       if (isCourseLock) {
 
         //没有执行定时器,开启锁定
@@ -798,9 +804,6 @@ router.beforeEach((to, from, next) => {
                 }, 10000);
                 next()
               })
-            // } else {
-            //   next()
-            // }
           })
 
 
@@ -829,10 +832,8 @@ router.beforeEach((to, from, next) => {
           })
         }
       }
-
       next()
     } else {
-
       next()
     }