From 9f0a7ae776a4004d094d3d0d9b2170c0d9b448de Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期五, 24 一月 2025 10:42:01 +0800
Subject: [PATCH] 请求方法优化

---
 .env.product                                 |    6 +-
 src/assets/methods/resources.js              |   44 +++++++--------------
 src/books/mathBook/view/components/index.vue |    2 
 src/assets/methods/examination.js            |   63 ++++++++++++++-----------------
 4 files changed, 47 insertions(+), 68 deletions(-)

diff --git a/.env.product b/.env.product
index 20e7618..7ab6259 100644
--- a/.env.product
+++ b/.env.product
@@ -1,8 +1,8 @@
 VUE_APP_ENV = 'product'
 VUE_APP_API_URL = "https://jsek.bnuic.com"
 VUE_APP_RESOURCE_CTX = 'https://jsek.bnuic.com/books/resource/'
-VUE_APP_PUBLIC_PATH = 'https://jsek.bnuic.com/books/book/aviationEtiquette'
+VUE_APP_PUBLIC_PATH = 'https://jsek.bnuic.com/books/book/toddlerGameImplementation'
 # VUE_APP_RESOURCE_CTX = 'http://182.92.203.7:3007/books/resource/'
 # VUE_APP_PUBLIC_PATH = 'http://182.92.203.7:3007/books/book/botany'
-VUE_APP_BOOK_LIST = "childHealth/lifeCare/sportsAndHealth/embedded/english/artAndDance/artAndDrama/mathBook/botany/civilAviation/civilServices/meetingPlanners/aviationBasicSkills/aviationEtiquette/aviationSafety"
-VUE_APP_BOOK_ID = 'aviationEtiquette'
\ No newline at end of file
+VUE_APP_BOOK_LIST = "childHealth/lifeCare/sportsAndHealth/embedded/english/artAndDance/artAndDrama/mathBook/botany/civilAviation/civilServices/meetingPlanners/aviationBasicSkills/aviationEtiquette/aviationSafety/toddlerGameImplementation"
+VUE_APP_BOOK_ID = 'toddlerGameImplementation'
\ No newline at end of file
diff --git a/src/assets/methods/examination.js b/src/assets/methods/examination.js
index fb14270..742e446 100644
--- a/src/assets/methods/examination.js
+++ b/src/assets/methods/examination.js
@@ -1,11 +1,11 @@
 import MG from "@/assets/js/middleGround/WebMiddleGroundApi";
-import {tokenKey} from '@/assets/js/config'
+import { tokenKey } from "@/assets/js/config";
 import getPublicImage from "@/assets/js/middleGround/tool";
 // 鑾峰彇棰樼洰鍒楄〃
 const getQuestionList = async (page, questionList, activeBook) => {
-const token = localStorage.getItem(tokenKey)
-let collectList = []
-if(token)  collectList = await getCollectList(activeBook)
+  const token = localStorage.getItem(tokenKey);
+  let collectList = [];
+  if (token) collectList = await getCollectList(activeBook);
   const oldAnswerData = localStorage.getItem(activeBook.name + "oldAnswerData");
   let oldData = null;
   let oldList = [];
@@ -227,43 +227,36 @@
   return cardList.filter((item) => item.infoList.length > 0);
 };
 // 鑾峰彇鏀惰棌鍒楄〃
-const getCollectList = async(activeBook) => {
+const getCollectList = async (activeBook) => {
   const allCollect = [
     {
-      type:'bits',
-      collectList:[]
+      type: "bits",
+      collectList: [],
     },
     {
-      type:'json',
-      collectList:[]
+      type: "json",
+      collectList: [],
     },
-  ]
-  await MG.identity
-  .getUserKey({
-    domain: 'collectData',
-    keys: [activeBook.bookId]
-  })
-  .then((res) => {
-    try {
-      const collect = JSON.parse(res[0].value)
-      if (collect.length) {
-        allCollect[0].collectList = collect.find(
-          (citem) => citem.type == 'bits'
-        ).collectList
-        allCollect[1].collectList = collect.find(
-          (citem) => citem.type == 'json'
-        ).collectList
-      }
-    } catch (error) {
-      console.log('鏆傛棤鏁版嵁')
+  ];
+  const res = await MG.identity.getUserKey({
+    domain: "collectData",
+    keys: [activeBook.bookId],
+  });
+  try {
+    const collect = JSON.parse(res[0].value);
+    if (collect.length) {
+      allCollect[0].collectList = collect.find(
+        (citem) => citem.type == "bits"
+      ).collectList;
+      allCollect[1].collectList = collect.find(
+        (citem) => citem.type == "json"
+      ).collectList;
     }
-  })
-  .catch(() => {
-    console.log('鑾峰彇鏀惰棌鎶ラ敊');
-  })
-  console.log('鏀惰棌鏁版嵁',allCollect.find(item => item.type == 'bits').collectList)
-  return allCollect.find(item => item.type == 'bits').collectList
-}
+  } catch (error) {
+    console.log("鏆傛棤鏁版嵁");
+  }
+  return allCollect.find((item) => item.type == "bits").collectList;
+};
 const getQuestionData = async (chapter, chapterData, activeBook) => {
   const data = { ...chapterData };
   const oldAnswerData = localStorage.getItem("oldAnswerData");
diff --git a/src/assets/methods/resources.js b/src/assets/methods/resources.js
index f98cbb3..8c3829d 100644
--- a/src/assets/methods/resources.js
+++ b/src/assets/methods/resources.js
@@ -2,38 +2,24 @@
 import identityApi from "../js/middleGround/api/identity";
 import { tokenKey } from "../js/config";
 export const getResourcePath = async (md5, appRefCode = "jingshieke") => {
-  let path = "";
-  await fileApi
-    .getAliVod({
-      md5,
-      appRefCode,
-    })
-    .then((res) => {
-      if (res.data != "" && res.data != undefined) {
-        path = res.data;
-      } else {
-        path = process.env.VUE_APP_API_URL + "/file/api/ApiDownload?md5=" + md5;
-      }
-    });
-  return path;
+  const res = fileApi.getAliVod({
+    md5,
+    appRefCode,
+  });
+  return res.data != "" && res.data != undefined
+    ? res.data
+    : process.env.VUE_APP_API_URL + "/file/api/ApiDownload?md5=" + md5;
 };
 // 鑾峰彇鏀惰棌鐨勮祫婧�
 export const getCollectResource = async (key) => {
-  if(!localStorage.getItem(tokenKey)) return []
-  let list = []
-  await identityApi
-  .getUserKey({
+  if (!localStorage.getItem(tokenKey)) return [];
+  const res = await identityApi.getUserKey({
     domain: "collectResource",
     keys: [key],
-  })
-  .then((res) => {
-    if(res.length) {
-      list = JSON.parse(res[0].value)
-    }
   });
-  return list
-}
-export const setCollectResource = (key,list) => {
+  return res.length ? JSON.parse(res[0].value) : [];
+};
+export const setCollectResource = (key, list) => {
   identityApi.setUserKey({
     setKeyRequests: [
       {
@@ -42,12 +28,12 @@
         value: JSON.stringify(list),
       },
     ],
-  })
-}
+  });
+};
 const MT = {
   getResourcePath,
   getCollectResource,
-  setCollectResource
+  setCollectResource,
 };
 
 export default MT;
diff --git a/src/books/mathBook/view/components/index.vue b/src/books/mathBook/view/components/index.vue
index 7a27465..433fef6 100644
--- a/src/books/mathBook/view/components/index.vue
+++ b/src/books/mathBook/view/components/index.vue
@@ -871,7 +871,7 @@
             console.log("鏆傛棤鏁版嵁");
           }
         })
-        .catch((res) => {
+        .catch(() => {
           console.log("index 璇锋眰棰樼洰鏀惰棌id鎶ラ敊");
         });
       console.log('鏀惰棌id',this.collectId);

--
Gitblit v1.9.1