ScoreReportPreview.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <el-dialog
  3. class="report-preview"
  4. :visible.sync="modalIsShow"
  5. top="0"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. :show-close="false"
  9. append-to-body
  10. fullscreen
  11. >
  12. <div class="box-justify" slot="title">
  13. <h2 class="el-dialog__title">成绩报告</h2>
  14. <span>{{ title }}</span>
  15. <div>
  16. <el-button
  17. type="primary"
  18. :loading="downloading"
  19. icon="el-icon-download"
  20. @click="toExportScore"
  21. >下载报告</el-button
  22. >
  23. <el-button class="btn-back" @click="cancel">
  24. 返回<i class="el-icon-arrow-right"></i>
  25. </el-button>
  26. </div>
  27. </div>
  28. <report v-if="modalIsShow" ref="reportRef" :baseinfo="instance"></report>
  29. <div slot="footer"></div>
  30. </el-dialog>
  31. </template>
  32. <script>
  33. import Report from "./report/Report.vue";
  34. import { downloadByApi } from "@/plugins/download";
  35. import { scoreReportExport } from "../api";
  36. export default {
  37. name: "score-report-preview",
  38. components: { Report },
  39. props: {
  40. instance: {
  41. type: Object,
  42. default() {
  43. return {};
  44. },
  45. },
  46. },
  47. data() {
  48. return {
  49. modalIsShow: false,
  50. downloading: false,
  51. };
  52. },
  53. computed: {
  54. title() {
  55. const course = `${this.instance.courseName}(${this.instance.courseCode})`;
  56. return course;
  57. },
  58. },
  59. methods: {
  60. cancel() {
  61. this.modalIsShow = false;
  62. },
  63. open() {
  64. this.modalIsShow = true;
  65. },
  66. async toExportScore() {
  67. if (this.downloading) return;
  68. this.downloading = true;
  69. const filename = `${this.title}.pdf`;
  70. const res = await downloadByApi(() => {
  71. const formData = new FormData();
  72. const htmlFile = new File(
  73. [this.$refs.reportRef.getTemp()],
  74. `${Date.now()}.html`,
  75. { type: "text/html" }
  76. );
  77. formData.append("file", htmlFile);
  78. return scoreReportExport(formData);
  79. }, filename).catch((e) => {
  80. this.$message.error(e || "下载失败,请重新尝试!");
  81. });
  82. this.downloading = false;
  83. if (!res) return;
  84. this.$message.success("下载成功!");
  85. },
  86. },
  87. };
  88. </script>