Browse Source

对接接口

huangtao 4 years ago
parent
commit
5e80b8a4b1

+ 2 - 33
src/App.vue

@@ -1,7 +1,6 @@
 <template>
   <div id="app">
-    <template v-if="!isInited"></template>
-    <router-view v-else />
+    <router-view />
   </div>
 </template>
 
@@ -10,9 +9,7 @@ export default {
   name: 'App',
   components: {},
   data() {
-    return {
-      isInited: false,
-    };
+    return {};
   },
   created() {
     this.initDataFun(); // 初始化数据
@@ -37,34 +34,6 @@ export default {
           this.$store.commit('common/SET_WINDOW_ONRESIZE'); // 通知网页内容区域可视化宽高有变化
         })();
       };
-      this.getEngineeringWorkList();
-    },
-    // 获取工种,并存到vuex
-    getEngineeringWorkList() {
-      this.$_http
-        .get(this.$_API.INTERFACE_GET_ENGINEERINGWORK_LIST)
-        .then((res) => {
-          this.$store.commit('common/SET_ENGINEERING_WORK_LIST', res.data);
-          this.getExamQuestionTypeConditionParentList();
-        })
-        .catch(() => {
-          this.isInited = true;
-        });
-    },
-    // 获取试题类型-父类信息,并存到vuex
-    getExamQuestionTypeConditionParentList() {
-      this.$_http
-        .get(this.$_API.INTERFACE_GET_EXAMS_QUESTION_TYPE_CONDITION_PARENT)
-        .then((res) => {
-          this.$store.commit(
-            'common/SET_EXAM_QUESTION_TYPE_CONDITION_PARENT',
-            res.data
-          );
-          this.isInited = true;
-        })
-        .catch(() => {
-          this.isInited = true;
-        });
     },
   },
 };

+ 1 - 1
src/api/modules/count.js

@@ -15,7 +15,7 @@ export default {
     INTERFACE_GET_COUNT_EXAMS_UP: 'admin/exams/month/count',
 
     // 查询考试平均成绩:本周、本月、全年
-    INTERFACE_GET_COUNT_BAR: '',
+    INTERFACE_GET_COUNT_BAR: 'admin/exams/averagepoints',
 
     // 获取文章类型比例
     INTERFACE_GET_COUNT_ARTICLE_PROPORTION: 'admin/materials/ratio',

+ 118 - 79
src/views/Home.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="app-container">
-    <a-spin :spinning="loading1 || loading2">
+    <a-spin :spinning="loading || loading1 || loading2 || loading3">
       <!-- 基础数据展示 -->
       <div class="count-basic-data">
         <div
@@ -31,7 +31,7 @@
               :class="{
                 'count-echarts-bar-title-right-btn': true,
                 'count-echarts-bar-title-right-btn-checked':
-                  barTabChecked === item.id,
+                  barTabChecked === item.code,
               }"
               v-for="(item, index) in barDataTab"
               :key="index"
@@ -75,17 +75,18 @@ export default {
   },
   data() {
     return {
+      loading: false, // 基础数据加载动画
       loading1: false, // 是否显示加载动画
       loading2: false, // 是否显示加载动画
       loading3: false, // 是否显示加载动画
       basicList: [], // 基础数据列表
       // 统计图
       barDataTab: [
-        { id: 1, title: '本周' },
-        { id: 2, title: '本月' },
-        { id: 3, title: '本年' },
+        { id: 1, title: '本周', code: 'week' },
+        { id: 2, title: '本月', code: 'month' },
+        { id: 3, title: '本年', code: 'year' },
       ], // 统计图的tab栏
-      barTabChecked: 1, // 当前选中的tab栏ID
+      barTabChecked: 'week', // 当前选中的tab栏ID
       barData: {}, // 统计图数据
       // 扇形-文章类型占比
       articlesProportion: {},
@@ -93,7 +94,9 @@ export default {
       examsProportion: {},
     };
   },
-  created() {},
+  created() {
+    this.getEngineeringWorkList();
+  },
   mounted() {
     this.initDataFun(); // 初始化数据
   },
@@ -103,6 +106,33 @@ export default {
     ...mapGetters(['userInfo']),
   },
   methods: {
+    // 获取工种,并存到vuex
+    getEngineeringWorkList() {
+      this.$_http
+        .get(this.$_API.INTERFACE_GET_ENGINEERINGWORK_LIST)
+        .then((res) => {
+          this.$store.commit('common/SET_ENGINEERING_WORK_LIST', res.data);
+          this.getExamQuestionTypeConditionParentList();
+        })
+        .catch(() => {
+          this.isInited = true;
+        });
+    },
+    // 获取试题类型-父类信息,并存到vuex
+    getExamQuestionTypeConditionParentList() {
+      this.$_http
+        .get(this.$_API.INTERFACE_GET_EXAMS_QUESTION_TYPE_CONDITION_PARENT)
+        .then((res) => {
+          this.$store.commit(
+            'common/SET_EXAM_QUESTION_TYPE_CONDITION_PARENT',
+            res.data
+          );
+          this.isInited = true;
+        })
+        .catch(() => {
+          this.isInited = true;
+        });
+    },
     // 初始化数据
     async initDataFun() {
       this.basicList = [
@@ -184,7 +214,7 @@ export default {
         .get(this.$_API.INTERFACE_GET_COUNT_EXAMS)
         .then((res) => {
           basicList[2].count = res.data;
-          this.getExamsCountUp(basicList);
+          this.getExamsCountUp(basicList); // 查询:本月新增考试数量
         })
         .catch(() => {
           this.loading1 = false;
@@ -196,7 +226,6 @@ export default {
         .get(this.$_API.INTERFACE_GET_COUNT_EXAMS_UP)
         .then((res) => {
           basicList[2].monthUp = res.data;
-          this.$refs.echartsBarRef.initDataFun(this.barData);
           this.loading1 = false;
         })
         .catch(() => {
@@ -206,46 +235,71 @@ export default {
     // 查询:统计图-考试平均成绩:本周、本月、全年
     getAverageTestScore() {
       this.loading2 = true;
-      this.barData = {
-        xAxis: {
-          data: [
-            '期终考试',
-            '期中考试',
-            '期末考试',
-            '4月',
-            '5月',
-            '6月',
-            '7月',
-            '8月',
-            '9月',
-            '10月',
-            '11月',
-            '12月',
-          ],
-        }, // x轴数据
-        series: {
-          data: [
-            1113,
-            823,
-            1140,
-            1110,
-            405,
-            813,
-            823,
-            389,
-            678,
-            407,
-            1178,
-            789,
-          ],
-        }, // 移入提示数据
+      let params = {
+        date: this.barTabChecked,
       };
-      this.loading2 = false;
-      // this.$_http
-      //   .get(this.$_API.INTERFACE_GET_COUNT_BAR)
-      //   .then((res) => {
-      //     this.loading2 = false;
-      //   })
+      this.$_http
+        .get(this.$_API.INTERFACE_GET_COUNT_BAR, { params })
+        .then((res) => {
+          console.log(res);
+          let dataArr = this.formateResDataToEcharts(res.data); // 格式化数据结构为echarts所需要的结构
+          let xAxis = dataArr.map((item) => {
+            return item.name;
+          });
+          let series = dataArr.map((item) => {
+            return item.value;
+          });
+          if (xAxis.length > 0 && series.length > 0) {
+            this.barData = {
+              xAxis: {
+                data: xAxis,
+              },
+              series: {
+                data: series,
+              },
+            };
+          } else {
+            this.barData = {
+              xAxis: {
+                data: [
+                  '期终考试',
+                  '期中考试',
+                  '期末考试',
+                  '4月',
+                  '5月',
+                  '6月',
+                  '7月',
+                  '8月',
+                  '9月',
+                  '10月',
+                  '11月',
+                  '12月',
+                ],
+              }, // x轴数据
+              series: {
+                data: [
+                  1113,
+                  823,
+                  1140,
+                  1110,
+                  405,
+                  813,
+                  823,
+                  389,
+                  678,
+                  407,
+                  1178,
+                  789,
+                ],
+              }, // 移入提示数据
+            };
+          }
+          this.loading2 = false;
+          this.$refs.echartsBarRef.initDataFun(this.barData);
+        })
+        .catch(() => {
+          this.loading2 = false;
+        });
     },
     // 查询:文章类别占比
     getArticlesProportion() {
@@ -253,20 +307,7 @@ export default {
       this.$_http
         .get(this.$_API.INTERFACE_GET_COUNT_ARTICLE_PROPORTION)
         .then((res) => {
-          let dataArr = [];
-          for (let key in res.data) {
-            dataArr.push({
-              name: key,
-              value: formate(res.data[key]),
-            });
-          }
-          function formate(value) {
-            if (value.includes('%')) {
-              return Math.round(Number(value.replace('%', '')));
-            } else {
-              return value;
-            }
-          }
+          let dataArr = this.formateResDataToEcharts(res.data); // 格式化数据结构为echarts所需要的结构
           this.articlesProportion = {
             title: '文章总计',
             seriesLabel: '文章类别占比',
@@ -285,27 +326,13 @@ export default {
       this.$_http
         .get(this.$_API.INTERFACE_GET_COUNT_QUESTIONS_PROPORTION)
         .then((res) => {
-          let dataArr = [];
-          for (let key in res.data) {
-            dataArr.push({
-              name: key,
-              value: formate(res.data[key]),
-            });
-          }
-          function formate(value) {
-            if (value.includes('%')) {
-              return Math.round(Number(value.replace('%', '')));
-            } else {
-              return value;
-            }
-          }
+          let dataArr = this.formateResDataToEcharts(res.data); // 格式化数据结构为echarts所需要的结构
           this.articlesProportion = {
             title: '试题总计',
             seriesLabel: '试题类别占比',
             count: count,
             data: dataArr,
           };
-          console.log(this.articlesProportion);
           this.$refs.echartsPieTwoRef.initDataFun(this.articlesProportion);
           this.loading3 = false;
         })
@@ -313,12 +340,24 @@ export default {
           this.loading3 = false;
         });
     },
+    // 格式化数据结构为echarts所需要的结构
+    formateResDataToEcharts(data) {
+      let dataArr = [];
+      for (let key in data) {
+        dataArr.push({
+          name: key,
+          value: data[key],
+        });
+      }
+      return dataArr;
+    },
     // 操作:切换统计图的tab
     handleEchartsTab(item) {
-      if (this.barTabChecked === item.id) {
+      if (this.barTabChecked === item.code) {
         return;
       }
-      this.barTabChecked = item.id;
+      this.barTabChecked = item.code;
+      this.getAverageTestScore(); // 查询:统计图-考试平均成绩:本周、本月、全年
     },
   },
 };

+ 1 - 1
src/views/examManagement/examManualVolumeFormation.vue

@@ -1179,7 +1179,7 @@ export default {
             tages: [],
             engineerTypes: [engineerTypeInfo], // 信息集合:工种
             examCategory: values.examTypeChooseValue, // 考试类别
-            totalpoints: this.current_tableGradesCount, // 总分
+            totalPoints: this.current_tableGradesCount, // 总分
           };
           if (this.examDetailData.id) {
             params.id = this.examDetailData.id;

+ 17 - 12
src/views/login/index.vue

@@ -94,18 +94,23 @@ export default {
       });
     },
     httpLoginFun(params) {
-      // this.$_http
-      //   .get(this.$_API.INTERFACE_GET_USER_LOGIN)
-      //   .then((res) => {
-      //     // 自己的操作
-      //     console.log(res);
-      //   })
-      //   .catch((err) => {
-      //     console.log(err);
-      //   });
-      this.$store.commit('user/SET_LOGIN', params); // // 存用户信息
-      this.$store.commit('user/SET_MENU', []); // 赋值菜单
-      this.$router.push({ name: 'home' });
+      this.$_http
+        .get(this.$_API.INTERFACE_GET_USER_LOGIN, {
+          auth: {
+            username: params.userName,
+            password: params.password,
+          },
+        })
+        .then((res) => {
+          // 自己的操作
+          console.log(res);
+          this.$store.commit('user/SET_LOGIN', res.data); // // 存用户信息
+          this.$store.commit('user/SET_MENU', []); // 赋值菜单
+          this.$router.push({ name: 'home' });
+        })
+        .catch((err) => {
+          console.log(err);
+        });
     },
   },
 };