浏览代码

个人画像-历次成绩添加动态表头

吴朋磊 1 月之前
父节点
当前提交
ebe2729a46

+ 58 - 50
src/views/analysisReport/personalProfile/MyGradeHistory.vue

@@ -17,31 +17,10 @@
             {{scope.$index <10 ? '0' + (scope.$index + 1) : scope.$index + 1 }}
           </template>
         </el-table-column>
-        <el-table-column prop="examName" label="考试名称" align="center"></el-table-column>
-        <!-- <el-table-column prop="fullScore" label="满分" width="90" align="center"></el-table-column> -->
-        <!-- <el-table-column prop="rawScore" label="原始分" width="90" align="center"></el-table-column> -->
-        <el-table-column prop="displayName" :label="displayTypeLabel" width="90" align="center">
-          <template slot-scope="scope">
-            <template v-if="scope.row.displayType === 0 || scope.row.displayType === 2">
-              {{ scope.row.displayName }}
-            </template>
-            <template v-else-if="scope.row.displayType === 1">
-              <span v-if="scope.row.correctType === 0">错</span>
-              <span v-else-if="scope.row.correctType === 1">半对</span>
-              <span v-else-if="scope.row.correctType === 2">全对</span>
-              <span v-else>-</span>
-            </template>
-            <template v-else>-</template>
-          </template>
-        </el-table-column>
-        <!-- <el-table-column prop="classRank" label="班级排名" width="90" align="center"></el-table-column>
-        <el-table-column prop="gradeRank" label="年级排名" width="90" align="center"></el-table-column> -->
-        <!-- <el-table-column prop="standardScore" label="标准分" width="90" align="center"></el-table-column> -->
-        <el-table-column prop="scoreRate" label="得分率" width="90" align="center">
-          <template slot-scope="scope">
-            {{ scope.row.scoreRate }}%
-          </template>
-        </el-table-column>
+        <template v-for="(header, index) in tableHeaders">
+          <el-table-column v-if="header.display" :key="index" :prop="header.prop" :label="header.label" align="center">
+          </el-table-column>
+        </template>
         <el-table-column label="操作" width="120" align="center">
           <template slot-scope="scope">
             <el-button type="text" @click="viewDetails(scope.row)">查看答题卡</el-button>
@@ -178,23 +157,69 @@ export default {
         isTotal: this.$store.state.report.filterObject.isTotal //是否为总分科目 1为总分 0为非总分
       }
     }, //分析报告公共参数变量
+    // 根据displayType获取表头标签
+    displayTypeLabel() {
+      // 获取第一个数据行的displayType
+      const firstRow = this.tableData[0];
+      if (!firstRow) return '';
+      
+      switch (firstRow.displayType) {
+        case 0:
+          return '分数';
+        case 1:
+          return '对错';
+        case 2:
+          return '等级';
+        default:
+          return '';
+      }
+    },
+    // 获取表头配置
+    tableHeaders() {
+      if (Array.isArray(this.gradeHistoryData)) {
+        return this.gradeHistoryData[0]?.headers || [];
+      }
+      const records = this.gradeHistoryData.records || [];
+      return records[0]?.headers || [];
+    },
     // 处理数据,映射接口字段到表格字段
     tableData() {
-      const records = Array.isArray(this.gradeHistoryData) ? this.gradeHistoryData : (this.gradeHistoryData.records || []);
-      return records.map(item => ({
+      if (Array.isArray(this.gradeHistoryData)) {
+        return this.gradeHistoryData.map(item => ({
+          id: item.id || Math.random(),
+          examName: item.examName || '',
+          fullScore: item.fullScore,
+          originalScore: item.originalScore,
+          rawScore: item.originalScore,
+          classRank: item.classRank,
+          gradeRank: item.gradeRank,
+          standardScore: item.standardScore,
+          scoreRate: item.scoreRate,
+          examId: item.examId,
+          subjectId: item.subjectId,
+          displayType: item.displayType,
+          displayName: item.displayName || '',
+          correctType: item.correctType,
+        }));
+      }
+      const records = this.gradeHistoryData.records || [];
+      const firstRecord = records[0];
+      const data = firstRecord?.data || [];
+      return data.map(item => ({
         id: item.id || Math.random(),
         examName: item.examName || '',
         fullScore: item.fullScore,
-        rawScore: item.originalScore, // 接口字段originalScore映射到rawScore
+        originalScore: item.originalScore,
+        rawScore: item.originalScore,
         classRank: item.classRank,
         gradeRank: item.gradeRank,
         standardScore: item.standardScore,
         scoreRate: item.scoreRate,
-        examId: item.examId, //考试id
-        subjectId: item.subjectId, //科目id
-        displayType: item.displayType, //使用字段显示类型 0-分数 1-对错 2-等级
-        displayName: item.displayName || '', //使用字段显示值
-        correctType: item.correctType, //使用字段显示对错的时候 0-错 1-半对 2-全对
+        examId: item.examId,
+        subjectId: item.subjectId,
+        displayType: item.displayType,
+        displayName: item.displayName || '',
+        correctType: item.correctType,
       }));
     },
     // 表头样式
@@ -218,23 +243,6 @@ export default {
         lineHeight: '50px'
       };
     },
-    // 根据displayType获取表头标签
-    displayTypeLabel() {
-      // 获取第一个数据行的displayType
-      const firstRow = this.tableData[0];
-      if (!firstRow) return '';
-      
-      switch (firstRow.displayType) {
-        case 0:
-          return '分数';
-        case 1:
-          return '对错';
-        case 2:
-          return '等级';
-        default:
-          return '';
-      }
-    },
   },
   methods: {
     // 处理选择变化

+ 2 - 1
src/views/analysisReport/personalProfile/index.vue

@@ -209,8 +209,9 @@ export default {
                             data.total = Number(data.total);
                         }
                         this.gradeHistoryData = data;
-                        let examIds = (data.records || []).map(item => item.examId || '');
+                        let examIds = (data.records[0].data || []).map(item => item.examId || '');
                         this.portraitData.examIds = examIds;
+                        console.log(examIds);
                         // 加载状态
                         this.historyloading = false;