xiangpei
2024-12-03 8c3eaeddeff2c9c5a92352e6bf830e5000ff5882
src/views/answer/dataStatistics.vue
@@ -1,14 +1,15 @@
<template>
  <div style="padding: 10px" ref="pageContent">
  <div class="app-container" 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.paperType)" />
        <el-select v-model="queryParam.id" filterable placeholder="试卷" @change="getType" size="small">
          <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="primary" @click="submitForm" size="small">查询</el-button>
        <el-button type="danger"  @click="handleExport" size="small" class="link-left">导出</el-button>
        <el-button type="success"  @click="downloadUrlFile" size="small" class="link-left">截图</el-button>
      </el-form-item>
    </el-form>
@@ -135,7 +136,8 @@
      chartLoading: false,
      queryParam: {
        id: '',
        type: 1
        type: 1,
        name: '分数统计'
      },
      admin: true
    };
@@ -149,13 +151,44 @@
      this.examPaperList = res.response;
      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;
    downloadUrlFile() {
      var fileName = this.queryParam.name + '.png';
      var canvasElement  = document.getElementsByTagName('canvas')[0];
      var MIME_TYPE = "image/png";
      var imgURL = canvasElement.toDataURL(MIME_TYPE);
      var dlLink = document.createElement('a');
      dlLink.download = fileName;
      dlLink.href = imgURL;
      dlLink.dataset.downloadurl = [MIME_TYPE, dlLink.download, dlLink.href].join(':');
      document.body.appendChild(dlLink);
      dlLink.click();
      document.body.removeChild(dlLink);
    },
    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 + '.xlsx';
        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() {