You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.8 KiB

5 years ago
  1. <template>
  2. <div class="app-container">
  3. <el-button :loading="downloadLoading" style="margin-bottom:20px" type="primary" icon="el-icon-document" @click="handleDownload">Export</el-button>
  4. <el-table
  5. ref="multipleTable"
  6. v-loading="listLoading"
  7. :data="list"
  8. element-loading-text="Loading"
  9. border
  10. fit
  11. highlight-current-row
  12. >
  13. <el-table-column align="center" label="Id" width="95">
  14. <template slot-scope="scope">
  15. {{ scope.$index }}
  16. </template>
  17. </el-table-column>
  18. <el-table-column label="Main Information" align="center">
  19. <el-table-column label="Title">
  20. <template slot-scope="scope">
  21. {{ scope.row.title }}
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="Author" width="110" align="center">
  25. <template slot-scope="scope">
  26. <el-tag>{{ scope.row.author }}</el-tag>
  27. </template>
  28. </el-table-column>
  29. <el-table-column label="Readings" width="115" align="center">
  30. <template slot-scope="scope">
  31. {{ scope.row.pageviews }}
  32. </template>
  33. </el-table-column>
  34. </el-table-column>
  35. <el-table-column align="center" label="Date" width="220">
  36. <template slot-scope="scope">
  37. <i class="el-icon-time" />
  38. <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. </div>
  43. </template>
  44. <script>
  45. import { fetchList } from '@/api/article'
  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. fetchData() {
  61. this.listLoading = true
  62. fetchList(this.listQuery).then(response => {
  63. this.list = response.data.items
  64. this.listLoading = false
  65. })
  66. },
  67. handleDownload() {
  68. this.downloadLoading = true
  69. import('@/vendor/Export2Excel').then(excel => {
  70. const multiHeader = [['Id', 'Main Information', '', '', 'Date']]
  71. const header = ['', 'Title', 'Author', 'Readings', '']
  72. const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
  73. const list = this.list
  74. const data = this.formatJson(filterVal, list)
  75. const merges = ['A1:A2', 'B1:D1', 'E1:E2']
  76. excel.export_json_to_excel({
  77. multiHeader,
  78. header,
  79. merges,
  80. data
  81. })
  82. this.downloadLoading = false
  83. })
  84. },
  85. formatJson(filterVal, jsonData) {
  86. return jsonData.map(v => filterVal.map(j => {
  87. if (j === 'timestamp') {
  88. return parseTime(v[j])
  89. } else {
  90. return v[j]
  91. }
  92. }))
  93. }
  94. }
  95. }
  96. </script>