From 68b8ed3b4b7ddbb5fe113c1d7df3aa909dc66fb6 Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期三, 03 七月 2024 18:37:29 +0800
Subject: [PATCH] feat:新增随机时间题目配置

---
 src/views/answer/dataStatistics.vue |  306 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 184 insertions(+), 122 deletions(-)

diff --git a/src/views/answer/dataStatistics.vue b/src/views/answer/dataStatistics.vue
index 997726f..39c8bee 100644
--- a/src/views/answer/dataStatistics.vue
+++ b/src/views/answer/dataStatistics.vue
@@ -2,30 +2,94 @@
   <div style="padding: 10px" ref="pageContent">
     <el-form :model="queryParam" ref="queryForm" :inline="true" style="display: flex">
       <el-form-item label="璇曞嵎锛�">
-        <el-select v-model="queryParam.id" filterable placeholder="璇曞嵎">
-          <el-option v-for="item in examPaperList" :key="item.id" :value="item.id" :label="item.name" @change="getType(item.type)" />
+        <el-select v-model="queryParam.id" filterable placeholder="璇曞嵎" @change="getType">
+          <el-option v-for="item,index in examPaperList" :key="index" :value="item.id" :label="item.name" />
         </el-select>
       </el-form-item>
       <el-form-item>
         <el-button type="primary" @click="submitForm">鏌ヨ</el-button>
+        <el-button type="danger"  @click="handleExport" class="link-left">瀵煎嚭</el-button>
       </el-form-item>
 
     </el-form>
     <el-row :gutter="20">
-      <el-col :xl="12" class="echarts-row">
-        <el-card>
-          <div class="card-chart-container">
-            <div id="ageChart" ref="ageChart" class="chart-style" v-loading="chartLoading1" />
-          </div>
-        </el-card>
-      </el-col>
+      <el-col :xl="24" class="echarts-row">
+        <el-row :gutter="20">
+          <el-col :span="6">
+            <el-card>
+              <div class="data-item">
+                <div class="data-icon" :style="{ 'background-color': iconList[0].color }">
+                  <i class="el-icon-tickets"></i>
+                </div>
+                <div class="data-info">
+                  <div class="data-label">
+                    鎬昏�冭瘯娆℃暟
+                  </div>
+                  <div class="data-num">
+                    {{ totalInfo.examTotal }}
+                  </div>
+                </div>
+              </div>
+            </el-card>
 
-      <el-col :xl="12" class="echarts-row">
-        <el-card>
-          <div class="card-chart-container">
-            <div id="scoreChart" ref="scoreChart" class="chart-style" v-loading="chartLoading2" />
-          </div>
-        </el-card>
+          </el-col>
+
+          <el-col :span="6">
+            <el-card>
+              <div class="data-item">
+                <div class="data-icon" :style="{ 'background-color': iconList[1].color }">
+                  <i class="el-icon-s-claim"></i>
+                </div>
+                <div class="data-info">
+                  <div class="data-label">
+                    鍙傝�冧汉鏁�
+                  </div>
+                  <div class="data-num">
+                    {{ totalInfo.factPeopleTotal }}
+                  </div>
+                </div>
+              </div>
+            </el-card>
+
+          </el-col>
+
+          <el-col :span="6">
+            <el-card>
+              <div class="data-item">
+                <div class="data-icon" :style="{ 'background-color': iconList[2].color }">
+                  <i class="el-icon-edit"></i>
+                </div>
+                <div class="data-info">
+                  <div class="data-label">
+                    骞冲潎鍒�
+                  </div>
+                  <div class="data-num">
+                    {{ totalInfo.averageScore }}
+                  </div>
+                </div>
+              </div>
+            </el-card>
+
+          </el-col>
+
+          <el-col :span="6">
+            <el-card>
+              <div class="data-item">
+                <div class="data-icon" :style="{ 'background-color': iconList[3].color }">
+                  <i class="el-icon-s-data"></i>
+                </div>
+                <div class="data-info">
+                  <div class="data-label">
+                    鍙傝�冧汉鏁扮櫨鍒嗘瘮
+                  </div>
+                  <div class="data-num">
+                    {{ totalInfo.referencePercentage }}%
+                  </div>
+                </div>
+              </div>
+            </el-card>
+          </el-col>
+        </el-row>
       </el-col>
     </el-row>
 
@@ -33,7 +97,7 @@
       <el-col :xl="24">
         <el-card>
           <div class="card-chart-container">
-            <div id="peopleChart" ref="peopleChart" class="chart-style" v-loading="chartLoading3" />
+            <div id="peopleChart" ref="peopleChart" class="chart-style" v-loading="chartLoading" />
           </div>
         </el-card>
       </el-col>
@@ -44,41 +108,35 @@
 import { mapGetters, mapState } from 'vuex';
 import dashboardApi from '@/api/dashboard';
 
-const colorList = ['#3498DB', '#E74C3C', '#F1C40F', '#95A5A6', '#8E44AD', '#F39C12', '#D35400'];
+const colorList = ['#3eba45', '#3da7f8', '#ffbe40', '#95A5A6', '#8E44AD', '#F39C12', '#D35400'];
 
 
-const ageLabel = {
-  'age0To19': '0-19宀�',
-  'age20To29': '20-29宀�',
-  'age30To39': '30-39宀�',
-  'age40To49': '40-49宀�',
-  'ageOver50': '澶т簬50宀�',
+const dataKeyMap = {
+  'factPeopleTotal': '鍙傝�冧汉鏁�',
+  'averageScore': '骞冲潎鍒�',
+  'referencePercentage': '鍙傝�冧汉鏁扮櫨鍒嗘瘮',
 };
-const scoreLabel = {
-  'score0To59': '灏忎簬60鍒�',
-  'score60To69': '60-69鍒�',
-  'score70To79': '70-79鍒�',
-  'score80To89': '80-89鍒�',
-  'score90To100': '90-100鍒�'
-};
-const pieLabel = {
-  'totalAttended': '鍙備笌鑰冭瘯',
-  'totalAbsent': '鏈弬涓庤�冭瘯'
-};
-let ageChart = null;
-let scroeChart = null;
+
 let peopleChart = null;
 let observer = null;
 export default {
   data() {
     return {
       examPaperList: [],
-      chartLoading1: false,
-      chartLoading2: false,
-      chartLoading3: false,
+      totalInfo: {},
+      dataList: [],
+      iconList: [
+        { icon: 'el-icon-tickets', color: '#7868d9' },
+        { icon: 'el-icon-s-claim', color: '#3eba45' },
+        { icon: 'el-icon-edit', color: '#3da7f8' },
+        { icon: 'el-icon-warning', color: '#ffbe40' },
+        { icon: 'el-icon-error', color: '#fe640d' },
+      ],
+      chartLoading: false,
       queryParam: {
         id: '',
-        type: 1
+        type: 1,
+        name: '鍒嗘暟缁熻'
       },
       admin: true
     };
@@ -87,49 +145,58 @@
     if (sessionStorage.getItem('deptAdmin') == 1) {
       this.admin = false;
     }
-    ageChart = echarts.init(this.$refs.ageChart);
-    scroeChart = echarts.init(this.$refs.scoreChart);
     peopleChart = echarts.init(this.$refs.peopleChart);
     dashboardApi.queryCondition().then(res => {
       this.examPaperList = res.response;
-      this.queryParam.id = this.examPaperList[0].id
-      this.queryParam.type = this.examPaperList[0].paperType
+      this.queryParam.id = this.examPaperList[0].id;
+      this.queryParam.type = this.examPaperList[0].paperType;
+      this.queryParam.name = this.examPaperList[0].name;
       this.getChartData();
       this.observe();
     });
   },
   methods: {
-    getType(type) {
-      this.queryParam.type = type;
+    handleExport(){
+      let that = this
+      let url ='/api/admin/examPaperAnswer/export?id=' +this.queryParam.id + '&type=' + this.queryParam.type
+      var x = new XMLHttpRequest();
+      x.open("GET", url, true);
+      x.responseType = "blob";
+      x.onload = function () {
+        var url = window.URL.createObjectURL(x.response);
+        var a = document.createElement("a");
+        a.href = url;
+        a.download = that.queryParam.name;
+        a.click();
+      };
+      x.send();
+    },
+    getType(val) {
+      const selectedItem = this.examPaperList.find(item => item.id === val);
+      this.queryParam.type = selectedItem.paperType;
+      this.queryParam.name = selectedItem.name;
       this.getChartData();
     },
     getChartData() {
-      this.chartLoading1 = true;
-      this.chartLoading2 = true;
-      this.chartLoading3 = true;
+      this.chartLoading = true;
       dashboardApi.data(this.queryParam).then(re => {
-        const { age, score, examPeopleNum } = re.response;
-
-        const ageOption = this.barOption('骞撮緞娈电粺璁�', age, ageLabel);
-        const scoreOption = this.barOption('鍒嗘暟娈电粺璁�', score, scoreLabel);
-        const peopleOption = this.pieOption('鑰冭瘯浜烘暟', examPeopleNum, pieLabel);
-
-        ageChart.setOption(ageOption, true);
-        scroeChart.setOption(scoreOption, true);
-        peopleChart.setOption(peopleOption, true);
-
-        this.chartLoading1 = false;
-        this.chartLoading2 = false;
-        this.chartLoading3 = false;
+        const { data, total } = re.response;
+        this.totalInfo = total;
+        this.dataList = data;
+        this.barOption(this.dataList);
+        this.chartLoading = false;
       });
     },
-    barOption(title, data, labelList) {
-      const dataKeys = data.map(item => labelList[Object.keys(item)[0]]);
-      const dataValues = data.map(item => Object.values(item)[0]);
-      return {
+
+    barOption(dataList) {
+      const nameList = dataList.map((item) => item.name);
+      const options = {
         title: {
-          text: title,
+          text: '閮ㄩ棬缁熻',
           x: 'left'
+        },
+        legend: {
+          orient: 'horizontal',
         },
         color: colorList,
         tooltip: {
@@ -138,69 +205,41 @@
         grid: {
           left: 10,
           right: 10,
-          bottom: 20,
+          bottom: 10,
           top: 40,
           containLabel: true
         },
         xAxis: {
           type: 'category',
-          data: dataKeys
+          data: nameList,
+          axisLabel: {
+            show: true,
+            rotate: 35,
+          },
         },
         yAxis: {
           type: 'value'
         },
-        series: [
-          {
-            type: 'bar',
-            label: {
-              show: true,
-              fontSize: 16
-            },
-            barMaxWidth: '40%',
-            data: dataValues,
-          }
-        ]
-
+        series: Object.keys(dataKeyMap).map(key => {
+          console.log(key);
+          return this.filterData(dataList, key);
+        })
       };
-
+      peopleChart.setOption(options, true);
     },
-    pieOption(title, data, labelList) {
-      const pieData = data.map(item => {
-        return {
-          name: labelList[Object.keys(item)[0]],
-          value: Object.values(item)[0]
-        };
-      });
+
+    filterData(data, key) {
+      const mapData = data.map(item => item[key]);
       return {
-        title: {
-          text: title,
-          x: 'left'
+        name: dataKeyMap[key],
+        type: 'bar',
+        label: {
+          show: true,
         },
-        color: ['#E74C3C', '#3498DB',  '#F1C40F', '#95A5A6', '#8E44AD', '#F39C12', '#D35400'],
-        tooltip: {
-          trigger: 'item'
-        },
-        legend: {
-          orient: 'horizontal',
-        },
-        series: [
-          {
-            type: 'pie',
-            radius: '50%',
-            data: pieData,
-            emphasis: {
-              itemStyle: {
-                shadowBlur: 10,
-                shadowOffsetX: 0,
-                shadowColor: 'rgba(0, 0, 0, 0.5)'
-              }
-            }
-          }
-        ]
-
+        data: mapData
       };
-
     },
+
     submitForm() {
       this.getChartData();
     },
@@ -218,12 +257,6 @@
     handleResize() {
       if (ageChart) {
         ageChart.resize();
-      }
-      if (scroeChart) {
-        scroeChart.resize();
-      }
-      if (peopleChart) {
-        peopleChart.resize();
       }
     }
   },
@@ -246,7 +279,7 @@
 
 .card-chart-container {
   width: 100%;
-  height: 400px;
+  height: 500px;
 }
 
 
@@ -254,4 +287,33 @@
   width: 100%;
   height: 100%;
 }
+
+.data-item {
+  width: 100%;
+  display: flex;
+  align-items: center;
+  border-radius: 10px;
+  overflow: hidden;
+
+  .data-icon {
+    font-size: 70px;
+    padding: 20px 30px;
+    color: #fff;
+    border-radius: 10px;
+    overflow: hidden;
+    margin-right: 20px;
+  }
+
+  .data-info {
+    .data-label {
+      font-size: 18px;
+      margin-bottom: 10px;
+      color: #707070;
+    }
+
+    .data-num {
+      font-size: 28px;
+    }
+  }
+}
 </style>

--
Gitblit v1.8.0