ReportClass.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div class="report-class">
  3. <report-box
  4. v-for="(page, pindex) in pages"
  5. :key="pindex"
  6. title="班级成绩分析"
  7. >
  8. <div
  9. v-for="(chart, index) in page.charts"
  10. :key="`chart-${index}`"
  11. class="college-chart"
  12. >
  13. <v-chart :option="chart" :init-options="initOption"></v-chart>
  14. </div>
  15. <table v-if="page.tables.length" class="report-table report-table-border">
  16. <tr>
  17. <th>班级</th>
  18. <th>平均分</th>
  19. <th>最高分</th>
  20. <th>最低分</th>
  21. <th>及格数</th>
  22. <th>及格率(%)</th>
  23. <th>优秀数</th>
  24. <th>优秀率(%)</th>
  25. </tr>
  26. <tr v-for="(item, ind) in page.tables" :key="ind">
  27. <td>{{ item.name }}</td>
  28. <td>{{ item.avgScore }}</td>
  29. <td>{{ item.maxScore }}</td>
  30. <td>{{ item.minScore }}</td>
  31. <td>{{ item.passCount }}</td>
  32. <td>{{ item.passRate }}</td>
  33. <td>{{ item.excellentCount }}</td>
  34. <td>{{ item.excellentRate }}</td>
  35. </tr>
  36. </table>
  37. </report-box>
  38. </div>
  39. </template>
  40. <script>
  41. import { mapState } from "vuex";
  42. import ReportBox from "./ReportBox.vue";
  43. import { sectionArr, getGroupNum, sectionArrFirstPage } from "./utils";
  44. import { getBarsOptions, initOption } from "./chart";
  45. export default {
  46. name: "report-class",
  47. components: { ReportBox },
  48. data() {
  49. return {
  50. pages: [],
  51. initOption,
  52. };
  53. },
  54. computed: {
  55. ...mapState("report", ["class"]),
  56. },
  57. mounted() {
  58. this.initData();
  59. },
  60. methods: {
  61. initData() {
  62. const classes = this.class.map((item) => {
  63. return {
  64. ...item,
  65. name: item.className,
  66. };
  67. });
  68. const maxChartCountPerPage = 4;
  69. const maxTableCountPerPage = 30;
  70. const groupNum = getGroupNum(classes.length, 6);
  71. const groupCharts = sectionArr(classes, groupNum).map((data) =>
  72. getBarsOptions(data)
  73. );
  74. let pages = [];
  75. let curPage = { charts: [], tables: [] };
  76. groupCharts.forEach((item) => {
  77. curPage.charts.push(item);
  78. if (curPage.charts.length === maxChartCountPerPage) {
  79. pages.push(curPage);
  80. curPage = { charts: [], tables: [] };
  81. }
  82. });
  83. const firstPageTableCount = Math.floor(
  84. (maxChartCountPerPage - curPage.charts.length) *
  85. (maxTableCountPerPage / maxChartCountPerPage)
  86. );
  87. const groupTables = sectionArrFirstPage(
  88. classes,
  89. maxTableCountPerPage,
  90. firstPageTableCount
  91. );
  92. groupTables.forEach((item) => {
  93. curPage.tables = item;
  94. pages.push(curPage);
  95. curPage = { charts: [], tables: [] };
  96. });
  97. this.pages = pages;
  98. },
  99. },
  100. };
  101. </script>