Browse Source

fix(Student): 修复选择问题详情对话框中的数据获取逻辑

修复当 props.showData 或 workDetail 为空时导致的错误,并优化数据监听逻辑
SanHQin 2 weeks ago
parent
commit
1415eff412
1 changed files with 18 additions and 5 deletions
  1. 18 5
      src/views/Student/components/choiceQuestionDetailDialog.vue

+ 18 - 5
src/views/Student/components/choiceQuestionDetailDialog.vue

@@ -645,7 +645,7 @@ const setEchartsArea1 = () => {
 
 
 // 获取分析
 // 获取分析
 const getAnalysis = () => {
 const getAnalysis = () => {
-  if (!props.showData.workDetail.id) {
+  if (!props.showData || !props.showData.workDetail || !props.showData.workDetail.id) {
     return
     return
   }
   }
   const params = {
   const params = {
@@ -690,7 +690,12 @@ watch(
     else {
     else {
       myChart.value = null
       myChart.value = null
     }
     }
-    getAnalysis()
+
+    // console.log('newVal', newVal)
+    // if(newVal && newVal.workDetail && newVal.workDetail.id){
+    //   getAnalysis()
+    // }
+    // getAnalysis()
   },
   },
   { immediate: true, deep: true }
   { immediate: true, deep: true }
 )
 )
@@ -963,10 +968,18 @@ const saveAnalysis = () => {
 }
 }
 
 
 
 
+// 监听 props.showData.workDetail.id 变化
+watch(
+  () => props.showData?.workDetail?.id,
+  (newId, oldId) => {
+    if (newId && newId !== oldId) {
+      getAnalysis()
+    }
+  },
+  { immediate: true }
+)
+
 
 
-// watch(()=>props.slideIndex,()=>{
-//   getAnalysis()
-// })
 
 
 // onMounted(()=>{
 // onMounted(()=>{
 //   getAnalysis()
 //   getAnalysis()