龚焕茏
2024-07-16 eae62f5e1c79695a51fc487c6db9f28e2bcbeb9d
src/views/answer/dataStatistics.vue
@@ -8,6 +8,8 @@
      </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-button type="danger"  @click="downloadUrlFile" class="link-left">截图</el-button>
      </el-form-item>
    </el-form>
@@ -134,7 +136,8 @@
      chartLoading: false,
      queryParam: {
        id: '',
        type: 1
        type: 1,
        name: '分数统计'
      },
      admin: true
    };
@@ -148,14 +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: {
    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() {