lsc 2 years ago
parent
commit
25c4fcc39b

+ 57 - 4
src/components/pages/dataBoard/school/index.vue

@@ -14,7 +14,7 @@
             </div>
             <div class="info greenBG">
               <span>周使用频次</span>
-              <span>15620</span>
+              <span>{{weekCount}}</span>
             </div>
             <div class="info blueBG">
               <span>登录频次</span>
@@ -25,7 +25,7 @@
               <span>{{(loginCount / count).toFixed(0)}}</span>
             </div>
           </div>
-          <loginCount style="height: calc(100% - 140px)"></loginCount>
+          <loginCount style="height: calc(100% - 140px)" :monthArray="loginCountMonthArray"></loginCount>
         </div>
       </div>
       <div class="bottom">
@@ -274,7 +274,9 @@ export default {
       loginCount:0,
       loginTime:0,
       courseCount:0,
-      teacherCount:0
+      teacherCount:0,
+      loginCountMonthArray:[],
+      weekCount:0,
     }
   },
   mounted() {
@@ -297,7 +299,58 @@ export default {
           this.loginTime = parseInt(res.data[3][0].time) / 60  / 60
           this.courseCount = res.data[5][0].courseCount
           this.teacherCount = res.data[6][0].count
-          
+
+          let loginCountMonthArray = []
+          const date = new Date()
+          var Month = date.getMonth() + 1
+          var Year = date.getFullYear()
+          for(var i = Month;i>Month-6;i--){
+            if(i <= 0){
+              loginCountMonthArray.push({
+                Year:Year-1,
+                Month:12+i,
+                student:0,
+                teacher:0
+              })
+            }else{
+              loginCountMonthArray.push({
+                Month:i,
+                Year:Year,
+                student:0,
+                teacher:0
+              })
+            }
+          }
+          loginCountMonthArray = loginCountMonthArray.reverse()
+          let teacherLoginCountYear = res.data[7] // 老师半年登录次数统计
+          let studentLoginCountYear = res.data[8] // 学生半年登录次数统计
+
+          for(var i = 0;i<teacherLoginCountYear.length;i++){
+            let _date = new Date(teacherLoginCountYear[i].create_at)
+            var _month = _date.getMonth() + 1
+            var _year = _date.getFullYear() 
+            for(var j = 0;j<loginCountMonthArray.length;j++){
+              if(_month == loginCountMonthArray[j].Month && _year == loginCountMonthArray[j].Year){
+                loginCountMonthArray[j].teacher++
+                break;
+              }
+            }
+          }
+          for(var i = 0;i<studentLoginCountYear.length;i++){
+            let _date = new Date(studentLoginCountYear[i].create_at)
+            var _month = _date.getMonth() + 1
+            var _year = _date.getFullYear() 
+            for(var j = 0;j<loginCountMonthArray.length;j++){
+              if(_month == loginCountMonthArray[j].Month && _year == loginCountMonthArray[j].Year){
+                loginCountMonthArray[j].student++
+                break;
+              }
+            }
+          }
+          console.log(loginCountMonthArray);
+          this.loginCountMonthArray = loginCountMonthArray
+
+          this.weekCount = res.data[9][0].count
         })
         .catch((err) => {
           this.isLoading = false;

+ 54 - 8
src/components/pages/dataBoard/school/loginCount/index.vue

@@ -8,12 +8,18 @@
   
 <script>
 export default {
+    props: {
+        monthArray: {
+            type: Array,
+        },
+    },
     data() {
         return {
             chartObj: null,
             ooption: {
                 xdata: [],
-                sdata: [],
+                teacher: [],
+                student: [],
             },
             option: {
                 tooltip: {
@@ -24,7 +30,7 @@ export default {
                     right: '10'
                 },
                 grid: {
-                    top:'30',
+                    top: '30',
                     left: '5%',
                     right: '5%',
                     bottom: '5%',
@@ -33,7 +39,8 @@ export default {
                 xAxis: {
                     type: 'category',
                     boundaryGap: true,
-                    data: ['1月', '2月', '3月', '4月', '5月', '6月']
+                    // data: ['1月', '2月', '3月', '4月', '5月', '6月']
+                    data: []
                 },
                 yAxis: {
                     type: 'value'
@@ -42,12 +49,14 @@ export default {
                     {
                         name: '老师',
                         type: 'line',
-                        data: [120, 50, 101, 130, 110, 120]
+                        // data: [120, 50, 101, 130, 110, 120]
+                        data: []
                     },
                     {
                         name: '学生',
                         type: 'line',
-                        data: [220, 182, 191, 234, 290, 330]
+                        // data: [220, 182, 191, 234, 290, 330]
+                        data: []
                     },
                 ]
             },
@@ -65,8 +74,9 @@ export default {
                     //劳动课程
                     this.$el.querySelector("#charts_canvas")
                 );
-                //   this.option.xAxis.data = option.xdata;
-                //   this.option.series[0].data = option.sdata;
+                this.option.xAxis.data = this.ooption.xdata;
+                this.option.series[0].data = this.ooption.teacher;
+                this.option.series[1].data = this.ooption.student;
                 // 初始化雷达图
                 this.chartObj = chartObj;
                 this.chartObj.setOption(this.option);
@@ -74,10 +84,46 @@ export default {
         },
     },
     watch: {
+        monthArray: {
+            immediate: true,
+            deep: true,
+            handler(newValue, oldValue) {
+                this.ooption = {
+                    xdata: [],
+                    teacher: [],
+                    student: [],
+                }
+                let _array = newValue
+                for (var i = 0; i < _array.length; i++) {
+                    this.ooption.xdata.push(_array[i].Month + '月')
+                    this.ooption.teacher.push(_array[i].teacher)
+                    this.ooption.student.push(_array[i].student)
+                }
 
+                if (!this.chartObj) {
+                    this.setChart(this.ooption);
+                } else {
+                    this.option.xAxis.data = option.xdata;
+                    this.option.series[0].data = option.teacher;
+                    this.option.series[1].data = option.student;
+                    this.chartObj.setOption(this.option);
+                }
+                this.$forceUpdate();
+            },
+        },
     },
     mounted() {
-
+        this.ooption = {
+            xdata: [],
+            teacher: [],
+            student: [],
+        }
+        let _array = this.monthArray
+        for (var i = 0; i < _array.length; i++) {
+            this.ooption.xdata.push(_array[i].Month + '月')
+            this.ooption.teacher.push(_array[i].teacher)
+            this.ooption.student.push(_array[i].student)
+        }
         this.setChart(this.ooption);
         var _this = this;
         window.addEventListener("resize", () => {