Parcourir la source

点击返回按钮清楚缓存

liurongli il y a 1 mois
Parent
commit
c79c233a29

+ 8 - 0
src/api/analysis.ts

@@ -18,6 +18,14 @@ export const getAnalysisExamInfo = (data: any): Promise<ApiResponse> => {
     params: data,
   });
 };
+// 根据选择题判分系统ID获取考试的examId
+export const getIdByAiExamId = (data: any): Promise<ApiResponse> => {
+  return request({
+    url: "/api/v1/ai_analysis/get_id_by_ai_exam_id",
+    method: "get",
+    params: data,
+  });
+};
 // ==========================================成绩单============================================
 //获取单科成绩单下的表头数据
 export const studentTranscriptTitle = (data: any): Promise<ApiResponse> => {

+ 16 - 1
src/store/analysis.ts

@@ -61,6 +61,20 @@ export const useAnalysisStore = defineStore("analysis", () => {
     // 同步存储到 localStorage,确保持久化
     localStorage.setItem("childMenuPath", info);
   }
+  // 清除 localStorage 数据并重置 store 状态
+  const removeLocalStorage = () => {
+    // 1. 清除 localStorage 数据
+    localStorage.removeItem("filterObject");
+    localStorage.removeItem("analysisExamInfo");
+    localStorage.removeItem("filtersData");
+    localStorage.removeItem("childMenuPath");
+
+    // 2. 重置 store 中的响应式状态
+    filterObject.value = {} as FilterObject; // 重置为空对象(可根据业务需要设置默认值)
+    analysisExamInfo.value = {};
+    filtersData.value = [];
+    childMenuPath.value = '';
+  }
   return {
     filtersData,
     filterObject,
@@ -69,6 +83,7 @@ export const useAnalysisStore = defineStore("analysis", () => {
     setFiltersData,
     setFilterObject,
     setAnalysisExamInfo,
-    setChildMenuPath
+    setChildMenuPath,
+    removeLocalStorage
   };
 });

+ 20 - 6
src/views/analysis/index.vue

@@ -23,7 +23,8 @@ import FiltersItem from "@/components/FiltersItem.vue";
 // 重命名导入的 API 函数以避免冲突
 import {
   findCommonSelectList,
-  getAnalysisExamInfo as fetchAnalysisExamInfo,
+  getAnalysisExamInfo,
+  getIdByAiExamId,
 } from "@/api/analysis";
 import { onMounted, ref, computed } from "vue";
 import { useRoute } from "vue-router";
@@ -37,8 +38,12 @@ const reportContentRef = ref<HTMLElement | null>(null);
 
 // 考试科目 code
 const subjectCode = computed(() => {
+  console.log(examStore.currentExam, 33333);
   return examStore.currentExam?.examSubjectCode;
 });
+const aiExamId = computed(() => {
+  return examStore.currentExam?.id || "";
+});
 
 // --- 类型定义 ---
 interface FilterOption {
@@ -344,7 +349,7 @@ const loadAnalysisExamInfo = async () => {
       return;
     }
 
-    const res = await fetchAnalysisExamInfo({
+    const res = await getAnalysisExamInfo({
       examId: "2036963589738971137",
       subjectCode: currentSubjectCode,
     });
@@ -405,16 +410,25 @@ const handleSelectChange = (index: number, value: string) => {
   analysisStore.setFiltersData(filtersData.value);
   buildAndSaveFilterParams();
 };
-
+// 根据选择题判分系统ID获取考试的examId
+const GetIdByAiExamId = async () => {
+  const res = await getIdByAiExamId({
+    aiExamId: aiExamId.value,
+  });
+  if (res.code === 200 && res.data) {
+    
+  }
+};
 // 回到顶部
 const goToPageTop = () => {
   reportContentRef.value?.scrollTo({ top: 0, behavior: "smooth" });
 };
 
-onMounted(() => {
-  if(analysisStore?.filtersData?.length){
+onMounted(async () => {
+  await GetIdByAiExamId();
+  if (analysisStore?.filtersData?.length) {
     filtersData.value = analysisStore.filtersData;
-  }else{
+  } else {
     getCommonSelectList();
   }
   loadAnalysisExamInfo();

+ 3 - 0
src/views/exam/components/aside.vue

@@ -16,11 +16,13 @@
 </template>
 <script lang="ts" setup>
 import { useExamStore } from '@/store/exam'
+import { useAnalysisStore } from '@/store/analysis'
 import { useRouter } from 'vue-router'
 import { onMounted ,ref} from 'vue';
 import StepItem from './stepItem.vue'
 // 实例化 Store
 const examStore = useExamStore()
+const analysisStore = useAnalysisStore()
 const router = useRouter()
 
 
@@ -28,6 +30,7 @@ const menulist=ref<any[]>([]);//考试详情导航菜单
 
 const GoBack=()=>{
   examStore.clearExamInfo()//清空考试信息
+  analysisStore.removeLocalStorage()//清空分析信息
   router.push('/main/choice')//返回考试列表
 }
 

+ 0 - 1
src/views/exam/components/stepItem.vue

@@ -30,7 +30,6 @@ import { useAnalysisStore } from '@/store/analysis'
 const examStore = useExamStore()
 const analysisStore = useAnalysisStore()
 const getChildMenuPath = computed(() => analysisStore?.childMenuPath || '');
-console.log(getChildMenuPath.value,2333)
 // --- 响应式数据 ---
 const route = useRoute()//读取当前路由对象
 const router = useRouter()//访问全局路由方法