Jelajahi Sumber

Apply stash (message contains: )

dsy 3 minggu lalu
induk
melakukan
afdb7ff734

+ 12 - 0
src/api/app.js

@@ -107,3 +107,15 @@ export function CheckBookPreviewIdentityCode(data) {
     data,
   );
 }
+
+/**
+ * 校验识别码
+ * @param {object} data 请求数据
+ * @param {string} data.identity_code 识别码
+ * @param {string} data.check_code 校验码
+ * @param {string} data.app_id 应用标识
+ * @param {string} data.user_name 用户名
+ */
+export function obocCheckIdentityCode(data) {
+  return http.post(`${process.env.VUE_APP_EepServer}?MethodName=oboc-CheckIdentityCode`, data);
+}

+ 4 - 3
src/enterPage.vue

@@ -4,7 +4,7 @@
 
 <script>
 import { CheckBookPreviewIdentityCode } from '@/api/app';
-import { setToken } from '@/utils/auth';
+import { setToken, setLocalStore } from '@/utils/auth';
 
 export default {
   name: 'EnterPage',
@@ -31,10 +31,11 @@ export default {
         .then((response) => {
           this.data = response;
           setToken(response);
+          setLocalStore('book_id', this.data.book_id);
           if (this.isMobile()) {
-            this.$router.replace({ name: 'MobileBookPreview', query: { book_id: this.data.book_id } });
+            this.$router.replace({ name: 'MobileBookPreview' });
           } else {
-            this.$router.replace({ name: 'BookPreview', query: { book_id: this.data.book_id } });
+            this.$router.replace({ name: 'BookPreview' });
           }
         })
         .catch(() => {});

+ 4 - 2
src/mobile_preview/index.vue

@@ -55,9 +55,9 @@
 <script>
 import MobileCoursewarePreview from '@/views/book/courseware/preview/MobileCoursewarePreview.vue';
 import MenuPopover from '@/views/personal_workbench/common/MenuPopover.vue';
+
 import { isTrue } from '@/utils/validate';
 import * as OpenCC from 'opencc-js';
-
 import { GetBookCoursewareInfo, GetCoursewareAuditRemarkList } from '@/api/project';
 import {
   ContentGetCoursewareContent_View,
@@ -66,6 +66,7 @@ import {
   GetLanguageTypeList,
   GetBookUnifiedAttrib,
 } from '@/api/book';
+import { getLocalStore } from '@/utils/auth';
 
 export default {
   name: 'CommonPreview',
@@ -82,8 +83,9 @@ export default {
     };
   },
   data() {
+    const book_id = getLocalStore('book_id') || '';
     return {
-      book_id: this.$route.query.book_id || '',
+      book_id,
       select_node: '',
       courseware_info: {
         book_name: '',

+ 1 - 3
src/router/guard/index.js

@@ -1,11 +1,9 @@
-import { getToken } from '@/utils/auth';
-
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 
 NProgress.configure({ showSpinner: false });
 
-const whiteList = []; // 重定向白名单
+// const whiteList = []; // 重定向白名单
 
 export function setupRouterGuard(router) {
   // 全局前置守卫

+ 6 - 0
src/router/modules/basic.js

@@ -4,6 +4,12 @@ export const EnterPage = {
   component: () => import('@/enterPage.vue'),
 };
 
+export const OBOCPage = {
+  path: '/OBOC',
+  name: 'OBOCPage',
+  component: () => import('@/views/oboc/index.vue'),
+};
+
 export const BookPreview = {
   path: '/book_preview',
   name: 'BookPreview',

+ 2 - 2
src/router/modules/index.js

@@ -1,3 +1,3 @@
-import { BookPreview, MobileBookPreview, EnterPage, NotFoundPage } from './basic';
+import { BookPreview, MobileBookPreview, EnterPage, OBOCPage, NotFoundPage } from './basic';
 
-export const routes = [BookPreview, MobileBookPreview, EnterPage, NotFoundPage];
+export const routes = [BookPreview, MobileBookPreview, EnterPage, OBOCPage, NotFoundPage];

+ 25 - 7
src/utils/auth.js

@@ -48,7 +48,7 @@ const TokenKey = 'GCLS_Token';
 
 export function getSessionID() {
   const token = getItemWithExpiry(TokenKey);
-  return token ? token.session_id ?? '' : '';
+  return token ? (token.session_id ?? '') : '';
 }
 
 export function getToken() {
@@ -83,23 +83,41 @@ export function removeConfig() {
 /**
  * 设置本地存储
  * @param {string} key - 存储的键
- * @param {*} value - 存储的值
+ * @param {any} value - 存储的值
  */
 export function setLocalStore(key, value) {
-  localStorage.setItem(key, JSON.stringify(value));
+  try {
+    if (value === undefined) {
+      localStorage.removeItem(key);
+      return;
+    }
+    const toStore = typeof value === 'string' ? value : JSON.stringify(value);
+    localStorage.setItem(key, toStore);
+  } catch (e) {
+    // 序列化或存储失败时退回到字符串存储,若仍失败则忽略
+    try {
+      localStorage.setItem(key, String(value));
+    } catch (_) {
+      /* noop */
+    }
+  }
 }
 
 /**
  * 获取本地存储
  * @param {string} key - 存储的键
- * @returns {*} 返回存储的值
+ * @returns {any} 返回存储的值
  */
 export function getLocalStore(key) {
   const value = localStorage.getItem(key);
-  if (value) {
-    return JSON.parse(value);
+  try {
+    if (value) {
+      return JSON.parse(value);
+    }
+    return null;
+  } catch (e) {
+    return value;
   }
-  return null;
 }
 
 /**

+ 61 - 0
src/views/oboc/index.vue

@@ -0,0 +1,61 @@
+<template>
+  <div></div>
+</template>
+
+<script>
+import { obocCheckIdentityCode } from '@/api/app';
+import { setToken, setLocalStore } from '@/utils/auth';
+
+export default {
+  name: 'OBOCPage',
+  data() {
+    const { IdentityCode, AppID, CheckCode, UserName } = this.$route.query;
+    return {
+      identity_code: IdentityCode || '',
+      app_id: AppID || '',
+      check_code: CheckCode || '',
+      user_name: UserName || '',
+      data: {
+        book_id: null,
+        access_token: null,
+        gcls_sys_session_info: null,
+      },
+    };
+  },
+  created() {
+    this.checkIdentityCode();
+  },
+  methods: {
+    checkIdentityCode() {
+      if (!this.identity_code || !this.app_id || !this.check_code || !this.user_name) {
+        this.$message.error('缺少必要参数');
+        return;
+      }
+      obocCheckIdentityCode({
+        identity_code: this.identity_code,
+        app_id: this.app_id,
+        check_code: this.check_code,
+        user_name: this.user_name,
+      })
+        .then((response) => {
+          this.data = response;
+          setToken(response);
+          setLocalStore('book_id', this.data.book_id);
+          if (this.isMobile()) {
+            this.$router.replace({ name: 'MobileBookPreview' });
+          } else {
+            this.$router.replace({ name: 'BookPreview' });
+          }
+        })
+        .catch(() => {});
+    },
+    // 判断当前是web端还是手机端
+    isMobile() {
+      const userAgent = navigator.userAgent || navigator.vendor || window.opera;
+      return /android|iphone|ipad|ipod/i.test(userAgent);
+    },
+  },
+};
+</script>
+
+<style lang="scss" scoped></style>

+ 12 - 2
src/web_preview/index.vue

@@ -276,6 +276,7 @@ import {
   GetMyCollectList,
   DeleteMyCollect,
 } from '@/api/book';
+import { getLocalStore } from '@/utils/auth';
 
 export default {
   name: 'CommonPreview',
@@ -311,9 +312,9 @@ export default {
       // { icon: 'translate', title: '翻译', handle: '', param: {} },
       // { icon: 'setting', title: '设置', handle: '', param: {} },
     ];
-
+    const book_id = getLocalStore('book_id') || '';
     return {
-      projectId: this.$route.query.book_id || '',
+      projectId: book_id,
       select_node: this.id,
       courseware_info: {
         book_name: '',
@@ -442,6 +443,15 @@ export default {
     this.getProjectInfo();
   },
   methods: {
+<<<<<<< Updated upstream
+=======
+    selectFirstLeafNode() {
+      if (!this.node_list || this.node_list.length === 0) return;
+      let node = this.node_list.find((x) => this.isTrue(x.is_leaf_chapter));
+      if (!node) return;
+      this.selectChapterNode(node.id, true);
+    },
+>>>>>>> Stashed changes
     getBookBaseInfo() {
       GetBookBaseInfo({ id: this.projectId }).then(({ book_info }) => {
         this.courseware_info = { ...this.courseware_info, ...book_info, book_name: book_info.name };