Browse Source

修改不登陆进入预览 及code问题

秦鹏 3 years ago
parent
commit
8a6bec0b92
4 changed files with 53 additions and 52 deletions
  1. 2 1
      src/api/ajax.js
  2. 39 40
      src/permission.js
  3. 2 1
      src/router/index.js
  4. 10 10
      src/views/BookView2.vue

+ 2 - 1
src/api/ajax.js

@@ -11,8 +11,9 @@ export function getContent(MethodName, data) {
         UserType = user.user_type;
         SessionID = user.session_id;
     }
+    console.log();
     return request({
-        url: `/GCLSBookWebSI/ServiceInterface?MethodName=${MethodName}&UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}`,
+        url: `/GCLSBookWebSI/ServiceInterface?MethodName=${MethodName}&UserType=${UserType}&SessionID=${SessionID}&UserCode=${UserCode}`,
         method: 'post',
         data
     })

+ 39 - 40
src/permission.js

@@ -8,51 +8,50 @@ import getPageTitle from '@/utils/get-page-title'
 
 NProgress.configure({ showSpinner: false }) // NProgress Configuration
 
-const whiteList = ['/login'] // no redirect whitelist
+const whiteList = ['/login', '/npcBookView'] // no redirect whitelist
 
-router.beforeEach(async (to, from, next) => {
-  // start progress bar
-  NProgress.start()
-  // set page title
-  document.title = getPageTitle(to.meta.title)
-  //next();
-  NProgress.done()
-  const hasToken = getToken()
-
-  if (hasToken) {
-    let config = getConfig();
-    if (config) {
-      if (to.path === '/login') {
-        // if is logged in, redirect to the home page
-        next({ path: '/EnterSys' })
-        NProgress.done()
-      } else {
-        try {
-          next()
-        } catch (error) {
-          Message.error(error || 'Has Error')
-          next(`/login?redirect=${to.path}`)
-          NProgress.done()
+router.beforeEach(async(to, from, next) => {
+    // start progress bar
+    NProgress.start()
+        // set page title
+    document.title = getPageTitle(to.meta.title)
+        //next();
+    NProgress.done()
+    const hasToken = getToken()
+    if (hasToken) {
+        let config = getConfig();
+        if (config) {
+            if (to.path === '/login') {
+                // if is logged in, redirect to the home page
+                next({ path: '/EnterSys' })
+                NProgress.done()
+            } else {
+                try {
+                    next()
+                } catch (error) {
+                    Message.error(error || 'Has Error')
+                    next(`/login?redirect=${to.path}`)
+                    NProgress.done()
+                }
+            }
+        } else {
+            next(`/login?redirect=${to.path}`)
+            NProgress.done()
         }
-      }
-    } else {
-      next(`/login?redirect=${to.path}`)
-      NProgress.done()
-    }
-  } else {
-    /* has no token*/
-    if (whiteList.indexOf(to.path) !== -1) {
-      // in the free login whitelist, go directly
-      next()
     } else {
-      // other pages that do not have permission to access are redirected to the login page.
-      next(`/login?redirect=${to.path}`)
-      NProgress.done()
+        /* has no token*/
+        if (whiteList.indexOf(to.path) !== -1) {
+            // in the free login whitelist, go directly
+            next()
+        } else {
+            // other pages that do not have permission to access are redirected to the login page.
+            next(`/login?redirect=${to.path}`)
+            NProgress.done()
+        }
     }
-  }
 })
 
 router.afterEach(() => {
-  // finish progress bar
-  NProgress.done()
+    // finish progress bar
+    NProgress.done()
 })

+ 2 - 1
src/router/index.js

@@ -175,7 +175,8 @@ export const constantRoutes = [{
             import ('@/views/adultInput2')
     },
     {
-        path: "/bookView2",
+        path: "/npcBookView",
+        name: "npcBookView",
         component: () =>
             import ('@/views/BookView2')
     },

+ 10 - 10
src/views/BookView2.vue

@@ -9,9 +9,9 @@
     <div>
       <el-button @click="goperview('book3')">HSK标准教程1</el-button>
     </div>
-    <!-- <div>
+    <div>
       <el-button @click="goperview('book4')">新实用汉语</el-button>
-    </div> -->
+    </div>
   </div>
 </template>
 
@@ -19,7 +19,7 @@
 //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
 //例如:import 《组件名称》from ‘《组件路径》';
 import { getStaticContent } from "@/api/ajax";
-import { setToken ,removeToken} from "@/utils/auth";
+import { setToken, removeToken } from "@/utils/auth";
 
 export default {
   //import引入的组件需要注入到对象中才能使用
@@ -40,10 +40,10 @@ export default {
         name: "HSK标准教程1",
         id: "002-20211007-14-UNYIWU8EKW",
       },
-      // book4: {
-      //   name: "新实用汉语",
-      //   id: "003-20210908-10-1ZWNGSASZL",
-      // },
+      book4: {
+        name: "新实用汉语",
+        id: "003-20210908-10-1ZWNGSASZL",
+      },
       loading: false,
     };
   },
@@ -80,9 +80,9 @@ export default {
         }).then((res) => {
           this.loading = false;
           setToken(res);
-          // this.$router.push(
-          //   `/courseview?bookId=${id}&name=${name}&type=preview`
-          // );
+          this.$router.push(
+            `/courseview?bookId=${id}&name=${name}&type=preview`
+          );
         });
       });
     },