exportMergeHeaderExcel.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div class="export-merge-header-excel-container">
  3. <vab-query-form>
  4. <vab-query-form-left-panel :span="24">
  5. <el-button
  6. :loading="downloadLoading"
  7. type="primary"
  8. @click="handleDownload"
  9. >导出
  10. </el-button>
  11. </vab-query-form-left-panel>
  12. </vab-query-form>
  13. <el-table ref="multipleTable" v-loading="listLoading" :data="list">
  14. <el-table-column show-overflow-tooltip label="序号" width="55">
  15. <template slot-scope="scope">
  16. {{ scope.$index + 1 }}
  17. </template>
  18. </el-table-column>
  19. <el-table-column show-overflow-tooltip label="Main Information">
  20. <el-table-column show-overflow-tooltip label="Title">
  21. <template slot-scope="scope">
  22. {{ scope.row.title }}
  23. </template>
  24. </el-table-column>
  25. <el-table-column show-overflow-tooltip label="Author">
  26. <template slot-scope="scope">
  27. <el-tag>{{ scope.row.author }}</el-tag>
  28. </template>
  29. </el-table-column>
  30. <el-table-column show-overflow-tooltip label="Readings">
  31. <template slot-scope="scope">
  32. {{ scope.row.pageViews }}
  33. </template>
  34. </el-table-column>
  35. </el-table-column>
  36. <el-table-column show-overflow-tooltip label="Date">
  37. <template slot-scope="scope">
  38. <span>{{ scope.row.datetime }}</span>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. </div>
  43. </template>
  44. <script>
  45. import { getList } from "@/api/table";
  46. import { parseTime } from "@/utils";
  47. export default {
  48. name: "MergeHeader",
  49. data() {
  50. return {
  51. list: null,
  52. listLoading: true,
  53. downloadLoading: false,
  54. };
  55. },
  56. created() {
  57. this.fetchData();
  58. },
  59. methods: {
  60. async fetchData() {
  61. this.listLoading = true;
  62. const { data } = await getList(this.listQuery);
  63. this.list = data;
  64. this.listLoading = false;
  65. },
  66. async handleDownload() {
  67. this.downloadLoading = true;
  68. const { export_json_to_excel } = await import("@/vendor/ExportExcel");
  69. const multiHeader = [["Id", "Main Information", "", "", "Date"]];
  70. const header = ["", "Title", "Author", "Readings", ""];
  71. const filterVal = ["id", "title", "author", "pageViews", "datetime"];
  72. const list = this.list;
  73. const data = this.formatJson(filterVal, list);
  74. const merges = ["A1:A2", "B1:D1", "E1:E2"];
  75. export_json_to_excel({
  76. multiHeader,
  77. header,
  78. merges,
  79. data,
  80. });
  81. this.downloadLoading = false;
  82. },
  83. formatJson(filterVal, jsonData) {
  84. return jsonData.map((v) =>
  85. filterVal.map((j) => {
  86. if (j === "timestamp") {
  87. return parseTime(v[j]);
  88. } else {
  89. return v[j];
  90. }
  91. })
  92. );
  93. },
  94. },
  95. };
  96. </script>