Эх сурвалжийг харах

教辅作业前后端对接

吴朋磊 3 долоо хоног өмнө
parent
commit
8c8903c972

BIN
src/assets/homeworkTask/correct.png


BIN
src/assets/homeworkTask/fullMarks.png


BIN
src/assets/homeworkTask/quantity.png


BIN
src/assets/homeworkTask/score.png


BIN
src/assets/homeworkTask/scoringRate.png


+ 4 - 4
src/http/api/teachingHomework.js

@@ -4,10 +4,10 @@ import base from '../common/base';
 
 const teachingHomework = {
   // 作业任务列表
-  // params: { subjectCode, submitStatus, keyword, pageNum, pageSize }
-  // submitStatus: 0未提交 1已提交
-  getHomeworkList(data) {
-    return post(base.prefix + `/api/v1/studentHomework/list`, data);
+  // params: { pageNum, pageSize, courseCode, status, queryStr }
+  // status: 0未提交 1已提交
+  queryClassHomeWorkByPage(data) {
+    return get(base.prefix + `/api/v1/student_class_home_work/query_class_home_work_by_page`, data);
   },
 };
 

+ 24 - 36
src/views/teachingHomework/homeworkTask/analysis.vue

@@ -33,14 +33,9 @@
           <div class="card_title">作业概况</div>
           <div class="metric_row">
             <div class="metric" v-for="item in overviewList" :key="item.key">
-              <span class="metric_icon" :class="item.iconClass">
-                <i v-if="item.icon" :class="item.icon"></i>
-                <span v-else>%</span>
-              </span>
-              <div class="metric_text">
-                <div class="metric_label">{{ item.label }}</div>
-                <div class="metric_value">{{ item.value }}</div>
-              </div>
+              <img class="metric_icon" :src="item.icon" alt="">
+              <span class="metric_label">{{ item.label }}</span>
+              <span class="metric_value">{{ item.value }}</span>
             </div>
           </div>
         </section>
@@ -359,11 +354,11 @@ export default {
     },
     overviewList() {
       return [
-        { key: 'full', label: '满分', value: this.overview.fullScore, icon: 'el-icon-document', iconClass: 'icon_blue' },
-        { key: 'score', label: '得分', value: this.overview.score, icon: 'el-icon-star-on', iconClass: 'icon_gold' },
-        { key: 'rate', label: '得分率', value: this.overview.rate, icon: '', iconClass: 'icon_teal' },
-        { key: 'correct', label: '答对题数', value: this.overview.correctCount, icon: 'el-icon-circle-check', iconClass: 'icon_green' },
-        { key: 'count', label: '试题数量', value: this.overview.questionCount, icon: 'el-icon-time', iconClass: 'icon_orange' },
+        { key: 'full', label: '满分', value: this.overview.fullScore, icon: require('@/assets/homeworkTask/fullMarks.png') },
+        { key: 'score', label: '得分', value: this.overview.score, icon: require('@/assets/homeworkTask/score.png') },
+        { key: 'rate', label: '得分率', value: this.overview.rate, icon: require('@/assets/homeworkTask/scoringRate.png') },
+        { key: 'correct', label: '答对题数', value: this.overview.correctCount, icon: require('@/assets/homeworkTask/correct.png') },
+        { key: 'count', label: '试题数量', value: this.overview.questionCount, icon: require('@/assets/homeworkTask/quantity.png') },
       ];
     },
     chartQuestions() {
@@ -618,7 +613,7 @@ export default {
 
   .card {
     margin-bottom: 10px;
-    padding: 16px;
+    padding: 20px;
     background: #fff;
     border-radius: 10px;
     box-sizing: border-box;
@@ -640,17 +635,18 @@ export default {
 
   .metric_row {
     display: flex;
-    gap: 12px;
-    margin-top: 16px;
+    gap: 24px;
+    margin-top: 10px;
 
     .metric {
       flex: 1;
       min-width: 0;
       display: flex;
       align-items: center;
-      gap: 12px;
-      padding: 14px 12px;
-      background: #F7F9FC;
+      gap: 10px;
+      padding: 14px 16px;
+      background: #fff;
+      border: 1px solid #EBEEF5;
       border-radius: 8px;
       box-sizing: border-box;
     }
@@ -659,29 +655,21 @@ export default {
       flex-shrink: 0;
       width: 36px;
       height: 36px;
-      border-radius: 8px;
-      display: inline-flex;
-      align-items: center;
-      justify-content: center;
-      color: #fff;
-      font-size: 18px;
-
-      &.icon_blue { background: #409EFF; }
-      &.icon_gold { background: #E6A23C; }
-      &.icon_teal { background: #3BA8A0; font-size: 16px; font-weight: 550; }
-      &.icon_green { background: #67C23A; }
-      &.icon_orange { background: #F5A623; }
+      display: block;
+      object-fit: contain;
     }
 
     .metric_label {
-      font-size: 13px;
-      color: #999;
-      line-height: 18px;
+      flex: 1;
+      min-width: 0;
+      font-size: 14px;
+      color: #333333;
+      line-height: 20px;
     }
 
     .metric_value {
-      margin-top: 4px;
-      font-size: 22px;
+      flex-shrink: 0;
+      font-size: 24px;
       font-weight: 550;
       color: #333;
       line-height: 28px;

+ 64 - 179
src/views/teachingHomework/homeworkTask/list.vue

@@ -28,30 +28,26 @@
         </div>
         <div
           v-for="item in list"
-          :key="item.id || item.homeworkId"
+          :key="item.homeWorkStuId || item.homeWorkId"
           class="homework_card">
           <div class="card_left">
             <div class="card_title_row">
               <span
                 class="subject_badge"
-                :style="{ background: getSubjectColor(item.subjectName) }">
-                {{ item.subjectName || subjectName || '科目' }}
+                :style="{ background: getSubjectColor(item.courseName) }">
+                {{ item.courseName || subjectName || '科目' }}
               </span>
-              <span class="card_title" :title="item.homeworkName || item.taskName">
-                {{ item.homeworkName || item.taskName }}
+              <span class="card_title" :title="item.homeWorkName">
+                {{ item.homeWorkName }}
               </span>
             </div>
             <div class="card_meta">
-              <template v-if="submitStatus === 0">
-                <span>开始时间:{{ item.startTime || '-' }}</span>
-                <span>结束时间:{{ item.endTime || '-' }}</span>
-              </template>
-              <span v-else>更新时间:{{ item.updateTime || item.endTime || '-' }}</span>
-              <span>试题数量:{{ item.questionNum != null ? item.questionNum : '-' }}</span>
+              <span>提交截止:{{ item.submitEndTime || '-' }}</span>
+              <span>试题数量:{{ item.questionNumber != null ? item.questionNumber : '-' }}</span>
               <span>
                 状态:
-                <em :class="submitStatus === 0 ? 'status_todo' : 'status_done'">
-                  {{ submitStatus === 0 ? '未提交' : '已提交' }}
+                <em :class="item.status === 1 ? 'status_done' : 'status_todo'">
+                  {{ item.status === 1 ? '已提交' : '未提交' }}
                 </em>
               </span>
             </div>
@@ -61,6 +57,7 @@
               v-if="submitStatus === 0"
               type="primary"
               class="enter_btn"
+              :disabled="item.canWrite !== 1"
               @click="handleEnter(item)">
               进入作答
             </el-button>
@@ -110,130 +107,6 @@ export default {
       pageNum: 1,
       pageSize: 10,
       total: 0,
-      // TODO: 接口就绪后删除假数据
-      mockList: [
-        {
-          id: 1,
-          subjectName: '语文',
-          homeworkName: '9月11日作业任务',
-          startTime: '26-08-10 19:00:00',
-          endTime: '26-08-10 19:00:00',
-          questionNum: 12,
-          submitStatus: 0,
-        },
-        {
-          id: 2,
-          subjectName: '数学',
-          homeworkName: '9月11日作业任务',
-          startTime: '26-08-10 19:00:00',
-          endTime: '26-08-10 19:00:00',
-          questionNum: 12,
-          submitStatus: 0,
-        },
-        {
-          id: 3,
-          subjectName: '英语',
-          homeworkName: '9月12日单元练习',
-          startTime: '26-08-11 08:00:00',
-          endTime: '26-08-12 18:00:00',
-          questionNum: 20,
-          submitStatus: 0,
-        },
-        {
-          id: 4,
-          subjectName: '物理',
-          homeworkName: '力学专项训练',
-          startTime: '26-08-09 10:00:00',
-          endTime: '26-08-15 22:00:00',
-          questionNum: 15,
-          submitStatus: 0,
-        },
-        {
-          id: 5,
-          subjectName: '语文',
-          homeworkName: '9月11日作业任务',
-          startTime: '26-08-10 19:00:00',
-          endTime: '26-08-10 19:00:00',
-          updateTime: '26-08-10 19:00:00',
-          questionNum: 12,
-          submitStatus: 1,
-          analysisDisabled: false,
-        },
-        {
-          id: 6,
-          subjectName: '语文',
-          homeworkName: '9月11日作业任务',
-          startTime: '26-08-10 19:00:00',
-          endTime: '26-08-10 19:00:00',
-          updateTime: '26-08-10 19:00:00',
-          questionNum: 12,
-          submitStatus: 1,
-          analysisDisabled: true,
-        },
-        {
-          id: 7,
-          subjectName: '语文',
-          homeworkName: '9月11日作业任务',
-          startTime: '26-08-10 19:00:00',
-          endTime: '26-08-10 19:00:00',
-          updateTime: '26-08-10 19:00:00',
-          questionNum: 12,
-          submitStatus: 1,
-          analysisDisabled: false,
-        },
-        {
-          id: 8,
-          subjectName: '语文',
-          homeworkName: '文言文阅读专项',
-          startTime: '26-08-05 19:00:00',
-          endTime: '26-08-11 19:00:00',
-          updateTime: '26-08-11 19:00:00',
-          questionNum: 12,
-          submitStatus: 0,
-        },
-        {
-          id: 9,
-          subjectName: '语文',
-          homeworkName: '9月11日作业任务',
-          startTime: '26-08-04 19:00:00',
-          endTime: '26-08-10 19:00:00',
-          updateTime: '26-08-10 19:00:00',
-          questionNum: 12,
-          submitStatus: 1,
-          analysisDisabled: false,
-        },
-        {
-          id: 10,
-          subjectName: '英语',
-          homeworkName: '完形填空强化练习',
-          startTime: '26-08-03 19:00:00',
-          endTime: '26-08-09 19:00:00',
-          questionNum: 14,
-          submitStatus: 0,
-        },
-        {
-          id: 11,
-          subjectName: '语文',
-          homeworkName: '9月11日作业任务',
-          startTime: '26-08-02 19:00:00',
-          endTime: '26-08-08 19:00:00',
-          updateTime: '26-08-08 19:00:00',
-          questionNum: 12,
-          submitStatus: 1,
-          analysisDisabled: true,
-        },
-        {
-          id: 12,
-          subjectName: '语文',
-          homeworkName: '9月11日作业任务',
-          startTime: '26-08-01 19:00:00',
-          endTime: '26-08-07 19:00:00',
-          updateTime: '26-08-07 19:00:00',
-          questionNum: 12,
-          submitStatus: 1,
-          analysisDisabled: false,
-        },
-      ],
     };
   },
   computed: {
@@ -264,70 +137,82 @@ export default {
     handleRefresh() {
       this.fetchList();
     },
-    // TODO: 接口就绪后改为真实请求
     fetchList() {
-      this.loading = true;
-      const keyword = (this.keyword || '').trim();
-      let rows = this.mockList.filter(item => item.submitStatus === this.submitStatus);
-      if (keyword) {
-        rows = rows.filter(item => {
-          const name = item.homeworkName || item.taskName || '';
-          return name.indexOf(keyword) !== -1;
-        });
+      if (!this.subjectCode) {
+        this.list = [];
+        this.total = 0;
+        return;
       }
-      this.total = rows.length;
-      const start = (this.pageNum - 1) * this.pageSize;
-      this.list = rows.slice(start, start + this.pageSize);
-      this.$nextTick(() => {
+      this.loading = true;
+      const params = {
+        pageNum: this.pageNum,
+        pageSize: this.pageSize,
+        courseCode: this.subjectCode,
+        status: this.submitStatus,
+        queryStr: (this.keyword || '').trim(),
+      };
+      this.$api.teachingHomework.queryClassHomeWorkByPage(params).then(res => {
+        this.applyPage(res);
+      }).catch(err => {
+        const body = this.pickBody(err);
+        if (body) {
+          this.applyPage(body);
+          return;
+        }
+        this.list = [];
+        this.total = 0;
+      }).finally(() => {
         this.loading = false;
       });
     },
+    // 公共请求把 code 为 0 的成功响应放进了 reject,这里两种都认
+    pickBody(payload) {
+      if (!payload) return null;
+      if (payload.code === 0 || payload.code === 200) return payload;
+      if (payload.data && (payload.data.code === 0 || payload.data.code === 200)) return payload.data;
+      if (payload.response) return this.pickBody(payload.response);
+      return null;
+    },
+    applyPage(res) {
+      const page = (res && res.data) || {};
+      this.list = page.records || [];
+      this.total = page.total || 0;
+    },
+    homeworkPayload(item) {
+      return {
+        id: item.homeWorkStuId || item.homeWorkId,
+        homeWorkId: item.homeWorkId,
+        homeWorkStuId: item.homeWorkStuId,
+        subjectName: item.courseName || this.subjectName || '',
+        courseCode: item.courseCode || this.subjectCode,
+        homeworkName: item.homeWorkName || '',
+        questionNum: item.questionNumber,
+        endTime: item.submitEndTime || '',
+      };
+    },
     handleEnter(item) {
+      if (item.canWrite !== 1) return;
       sessionStorage.setItem('teachingHomeworkAnswer', JSON.stringify({
-        homework: {
-          id: item.id,
-          subjectName: item.subjectName || this.subjectName || '',
-          homeworkName: item.homeworkName || item.taskName || '',
-          teacherName: item.teacherName || '王老师',
-          className: item.className || '1班',
-          questionNum: item.questionNum,
-          endTime: item.endTime || '',
-        },
+        homework: this.homeworkPayload(item),
         currentIndex: 0,
         answers: {},
         remainSeconds: 10 * 60,
       }));
       this.$router.push('/teachingHomework/answer');
     },
-    // 查看分析是否置灰(假数据用 analysisDisabled,接口可改为 analysisStatus 等)
-    isAnalysisDisabled(item) {
-      return !!(item && item.analysisDisabled);
+    isAnalysisDisabled() {
+      return false;
     },
     handleViewAnswer(item) {
       sessionStorage.setItem('teachingHomeworkViewAnswer', JSON.stringify({
-        homework: {
-          id: item.id,
-          subjectName: item.subjectName || this.subjectName || '',
-          homeworkName: item.homeworkName || item.taskName || '',
-          teacherName: item.teacherName || '王老师',
-          className: item.className || '1班',
-          questionNum: item.questionNum,
-        },
+        homework: this.homeworkPayload(item),
         currentIndex: 0,
       }));
       this.$router.push('/teachingHomework/viewAnswer');
     },
     handleViewAnalysis(item) {
-      if (this.isAnalysisDisabled(item)) return;
       sessionStorage.setItem('teachingHomeworkAnalysis', JSON.stringify({
-        homework: {
-          id: item.id,
-          subjectName: item.subjectName || this.subjectName || '',
-          homeworkName: item.homeworkName || item.taskName || '',
-          teacherName: item.teacherName || '王老师',
-          className: item.className || '1班',
-          questionNum: item.questionNum,
-        },
+        homework: this.homeworkPayload(item),
       }));
       this.$router.push('/teachingHomework/analysis');
     },