xiangpei
2024-07-12 b62c6c9ab29e933fd0333ac183ef837d00aba5d2
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,41 @@
      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(url, fileName) {
      // 获取base64图片
      const chartImgUrl = this.myChart.getDataURL({
          pixelRatio: 2,
          backgroundColor: '#fff'
      })
      console.log(chartImgUrl)
      // 下载base64图片
      this.downloadUrlFile(chartImgUrl, 'ECharts 2倍图')
    },
    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() {