yellowtaotao 3 years ago
parent
commit
26fac44ad9

+ 1 - 1
src/store/modules/study.js

@@ -1,6 +1,6 @@
 const user = {
   state: {
-    isNeedChangeTab: false // 是否需要切换首页tab
+    homeChangeTabIndex: false // 是否需要切换首页tab
   },
   mutations: {
     updateStudyItemStore(state, { field, value }) {

+ 56 - 17
src/views/home/exam/page-exam.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="page-exam-box">
-    <div class="exam-list">
+    <div class="exam-list" v-if="examList.length > 0">
       <div
         class="exam-item"
         v-for="(item, index) in examList"
@@ -18,7 +18,7 @@
                 item.examStatus === examStatesType.STARTED,
               'exam-item-states-red':
                 item.examStatus === examStatesType.EXAMOVER ||
-                item.examStatus === examStatesType.NOTEXAM,
+                item.examStatus === examStatesType.NOTEXAM
             }"
           >
             {{ item.examStatusTxt }}
@@ -35,6 +35,12 @@
         </div>
       </div>
     </div>
+    <div v-else class="exam-list exam-question-card">
+      <div v-if="isInited" class="exam-question-card-nodata">暂无数据</div>
+      <div v-else class="exam-question-card-nodata exam-question-card-loading">
+        加载中...
+      </div>
+    </div>
   </div>
 </template>
 
@@ -53,7 +59,8 @@ export default {
         EXAMOVER: 3, // 已考完
         NOTEXAM: 4 // 未参考
       },
-      examList: []
+      examList: [],
+      isInited: false // 是否已加载完毕
     };
   },
   computed: {
@@ -62,13 +69,24 @@ export default {
       chooseEngneeringWork: state => state.user.chooseEngneeringWork
     })
   },
+  watch: {
+    // 监听:工种
+    chooseEngneeringWork(value) {
+      console.log(value.value);
+      if (value.value) {
+        this.getExamListFun(); // 查询:考试的场次列表信息
+      }
+    }
+  },
   created() {
     this.getExamListFun(); // 查询:考试的场次列表信息
   },
   methods: {
     // 查询:考试场次的列表信息
     getExamListFun() {
+      this.isInited = false;
       this.$store.commit("toggleLoading", true);
+      this.examList = [];
       let params = {
         type: this.chooseEngneeringWork.value
       };
@@ -84,8 +102,10 @@ export default {
               item.examStatus = obj.status;
               item.examStatusTxt = obj.statusTxt;
             });
-            this.examList = res.data;
-            console.log(this.examList);
+            this.$nextTick(() => {
+              this.examList = res.data;
+            });
+            this.isInited = true;
           }
           this.$store.commit("toggleLoading", false);
         })
@@ -149,12 +169,24 @@ export default {
     },
     // 操作:点击了某个考试
     handleClickExamItemFun(item) {
-      if (item.examStatus === this.examStatesType.NOT_START) {
-        Toast("考试未开始");
-        return;
+      let isCouldExam = false;
+      switch (item.examStatus) {
+        case this.examStatesType.NOT_START:
+          Toast("考试未开考");
+          break;
+        case this.examStatesType.EXAMOVER:
+          Toast("已考完");
+          break;
+        case this.examStatesType.STARTED:
+        case this.examStatesType.STARTEXAMING:
+        case this.examStatesType.NOTEXAM:
+          isCouldExam = true;
+          break;
+        default:
+          isCouldExam = true;
+          break;
       }
-      if (item.examStatus === this.examStatesType.OVER) {
-        Toast("考试已结束");
+      if (!isCouldExam) {
         return;
       }
       this.$store.commit("updateExamItemStore", {
@@ -191,20 +223,17 @@ export default {
         align-items: center;
         border-bottom: 1px solid #e4e8eb;
         .exam-item-name {
-          height: 2rem;
-          line-height: 2rem;
-          text-align: center;
+          padding: 0.5rem 0 0.25rem;
           font-size: 0.65rem;
           font-weight: bold;
           color: #000;
-          white-space: nowrap;
-          text-overflow: ellipsis;
-          overflow: hidden;
+          word-break: break-all;
+          word-wrap: break-word;
         }
         .exam-item-states {
           font-size: 0.6rem;
           border-radius: 0.2rem;
-          margin-left: 0.5rem;
+          margin-left: 1rem;
           flex-wrap: nowrap;
           white-space: nowrap;
         }
@@ -229,5 +258,15 @@ export default {
       }
     }
   }
+  .exam-question-card-loading,
+  .exam-question-card-nodata {
+    width: 100%;
+    height: 5rem;
+    color: #333;
+    font-size: 0.7rem;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+  }
 }
 </style>

+ 11 - 9
src/views/home/index.vue

@@ -87,22 +87,24 @@ export default {
   computed: {
     ...mapState({
       user: state => state.user,
-      isNeedChangeTab: state => state.study.isNeedChangeTab
+      homeChangeTabIndex: state => state.study.homeChangeTabIndex
     })
   },
   created() {
     this.initFun();
   },
   watch: {
-    isNeedChangeTab(value) {
-      if (value) {
-        this.activeTabName = 0;
-        this.onChangeTabFun(this.activeTabName);
-        this.$store.commit("updateStudyItemStore", {
-          field: "isNeedChangeTab",
-          value: false
-        });
+    // 监听:首页切换tab的下标
+    homeChangeTabIndex(value) {
+      if (value === null || value === undefined) {
+        return;
       }
+      this.activeTabName = value;
+      this.onChangeTabFun(this.activeTabName);
+      this.$store.commit("updateStudyItemStore", {
+        field: "homeChangeTabIndex",
+        value: null
+      });
     }
   },
   methods: {

+ 17 - 5
src/views/home/person/exam-history.vue

@@ -5,14 +5,14 @@
       <div class="exam-history-grades-div">
         <div class="exam-history-name-description">考试积分</div>
         <div class="exam-history-grades">
-          {{ this.user.userInfo.examPoints }}
+          {{ this.user.userInfo.examPoints || 0 }}
         </div>
         <div class="exam-history-description" @click="clickExamRule">
           积分说明
         </div>
         <div class="exam-history-class-box">
-          <div class="exam-history-class-item">专项考试积分:XX</div>
-          <div class="exam-history-class-item">普通考试积分:XX</div>
+          <div class="exam-history-class-item">专项考试积分:0</div>
+          <div class="exam-history-class-item">普通考试积分:0</div>
         </div>
       </div>
 
@@ -27,12 +27,14 @@
             <div class="exam-history-item-left-percentage">
               <div class="exam-history-item-left-schedule">
                 <van-progress
-                  :percentage="formatePercentageFun(item.points, 10)"
+                  :percentage="
+                    formatePercentageFun(item.earnedpoints, item.points)
+                  "
                   :show-pivot="false"
                 />
               </div>
               <div class="exam-history-item-left-schedule-text">
-                {{ item.earnedpoints }}分 / 满分10
+                {{ item.earnedpoints || 0 }} 分 / 满分 {{ item.points || 0 }} 
               </div>
             </div>
           </div>
@@ -72,6 +74,15 @@ export default {
   methods: {
     // 格式化已获得的积分/总积分的数
     formatePercentageFun(getPoints, totaPonits) {
+      if (
+        (!getPoints && getPoints !== 0) ||
+        (!totaPonits && totaPonits !== 0)
+      ) {
+        return 0;
+      }
+      if (isNaN(getPoints) || isNaN(totaPonits)) {
+        return 0;
+      }
       return Math.round((getPoints / totaPonits) * 100);
     },
     // 操作:返回
@@ -105,6 +116,7 @@ export default {
           })
         )
         .then(res => {
+          console.log(item, res);
           this.examHistoryList.push({ ...item, examName: res.data.name });
           if (isLast) {
             this.$store.commit("toggleLoading", false);

+ 63 - 25
src/views/home/person/user-manual.vue

@@ -40,13 +40,18 @@
                 />
               </div>
               <div class="user-manual-item-left-schedule-text">
-                已获得{{ item.getPoints }}分 / 上限{{ item.totalPonits }}分
+                已获得 {{ item.getPoints || 0 }} 分 / 上限
+                {{ item.totalPonits }} 分
               </div>
             </div>
           </div>
           <div class="user-manual-item-right">
             <div class="user-manual-item-btn" @click="toManualEarnFun(item)">
-              {{ item.rightButton }}
+              {{
+                item.getPoints === item.totalPonits
+                  ? "已完成"
+                  : item.rightButton
+              }}
             </div>
           </div>
         </div>
@@ -70,7 +75,7 @@ export default {
           type: "LOGIN",
           rule: "1分/登录",
           isFinish: false,
-          getPoints: 0,
+          getPoints: 1,
           totalPonits: 1,
           rightButton: "已完成",
           router: ""
@@ -182,7 +187,7 @@ export default {
       this.$_http
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_DAIYL_POINTS, path))
         .then(res => {
-          this.todayEarnPoints = res.data;
+          this.todayEarnPoints = res.data || 0;
         })
         .catch(() => {
           this.$store.commit("toggleLoading", false);
@@ -196,7 +201,7 @@ export default {
       this.$_http
         .get(this.$pathParams(this.$_API.JTXT_GET_USER_ALL_POINTS, path))
         .then(res => {
-          this.userTotalPonits = res.data;
+          this.userTotalPonits = res.data || 0;
         })
         .catch(() => {
           this.$store.commit("toggleLoading", false);
@@ -204,6 +209,15 @@ export default {
     },
     // 格式化已获得的积分/总积分的数
     formatePercentageFun(getPoints, totaPonits) {
+      if (
+        (!getPoints && getPoints !== 0) ||
+        (!totaPonits && totaPonits !== 0)
+      ) {
+        return 0;
+      }
+      if (isNaN(getPoints) || isNaN(totaPonits)) {
+        return 0;
+      }
       return Math.round((getPoints / totaPonits) * 100) || 0;
     },
     // 操作:返回
@@ -216,21 +230,42 @@ export default {
     },
     // 操作:点击了去看看、去学习、去训练
     toManualEarnFun(item) {
-      console.log("item" + JSON.stringify(item));
-      if (item.name === "今日必答") {
-        this.$store.commit("updateAnswerItemStore", {
-          field: "answerRecruitId",
-          value: "daily-questions" // item.id
-        });
-        this.$router.push({ name: "answerRecruit" });
-      } else if (item.name === "今日必读") {
-        this.$router.push({
-          name: "home"
-        });
-        this.$store.commit("updateStudyItemStore", {
-          field: "isNeedChangeTab",
-          value: true
-        });
+      // 获得的积分已满,不作操作
+      if (item.getPoints === item.totalPonits) {
+        return;
+      }
+      switch (item.rightButton) {
+        case "已完成":
+          break;
+        case "去看看":
+          // 1.跳转到首页
+          this.$router.replace({
+            name: "home"
+          });
+          // 2.告知需要首页切换tab-阅读
+          this.$store.commit("updateStudyItemStore", {
+            field: "homeChangeTabIndex",
+            value: 0
+          });
+          break;
+        case "去答题":
+          // 1. 重置vuex的answerRecruitId
+          this.$store.commit("updateAnswerItemStore", {
+            field: "answerRecruitId",
+            value: "daily-questions" // item.id
+          });
+          // 2.跳转到首页
+          this.$router.replace({
+            name: "home"
+          });
+          // 3.告知需要首页切换tab-答题
+          this.$store.commit("updateStudyItemStore", {
+            field: "homeChangeTabIndex",
+            value: 1
+          });
+          break;
+        default:
+          break;
       }
     }
   }
@@ -239,13 +274,13 @@ export default {
 
 <style lang="scss" scoped>
 .user-manual-box {
-  width: 100%;
-  height: 100vh;
-  font-size: 0.6rem;
-  background-color: #fff;
   .user-manual-div {
+    width: 100%;
+    height: 100vh;
     overflow-y: auto;
     padding: 0 0.75rem;
+    background-color: #fff;
+    font-size: 0.6rem;
     .user-manual-grades-div {
       display: flex;
       flex-direction: column;
@@ -323,11 +358,14 @@ export default {
           }
         }
         .user-manual-item-right {
+          margin-left: 1rem;
           .user-manual-item-btn {
+            padding: 0.1rem 0.25rem;
             border-radius: 0.1rem;
             color: #0088e9;
             background-color: #d8e9f5;
-            padding: 0.1rem 0.25rem;
+            flex-wrap: nowrap;
+            white-space: nowrap;
           }
         }
       }