feature[Excel]: add export merge header excel demo
This commit is contained in:
parent
3d973f7ddd
commit
4b5b0a6e6b
|
@ -57,6 +57,7 @@ export default {
|
||||||
excel: 'Excel',
|
excel: 'Excel',
|
||||||
exportExcel: 'Export Excel',
|
exportExcel: 'Export Excel',
|
||||||
selectExcel: 'Export Selected',
|
selectExcel: 'Export Selected',
|
||||||
|
mergeHeader: 'Merge Header',
|
||||||
uploadExcel: 'Upload Excel',
|
uploadExcel: 'Upload Excel',
|
||||||
zip: 'Zip',
|
zip: 'Zip',
|
||||||
pdf: 'PDF',
|
pdf: 'PDF',
|
||||||
|
|
|
@ -57,6 +57,7 @@ export default {
|
||||||
excel: 'Excel',
|
excel: 'Excel',
|
||||||
exportExcel: 'Exportar a Excel',
|
exportExcel: 'Exportar a Excel',
|
||||||
selectExcel: 'Export seleccionado',
|
selectExcel: 'Export seleccionado',
|
||||||
|
mergeHeader: 'Merge Header',
|
||||||
uploadExcel: 'Subir Excel',
|
uploadExcel: 'Subir Excel',
|
||||||
zip: 'Zip',
|
zip: 'Zip',
|
||||||
pdf: 'PDF',
|
pdf: 'PDF',
|
||||||
|
|
|
@ -55,9 +55,10 @@ export default {
|
||||||
page404: '404',
|
page404: '404',
|
||||||
errorLog: '错误日志',
|
errorLog: '错误日志',
|
||||||
excel: 'Excel',
|
excel: 'Excel',
|
||||||
exportExcel: 'Export Excel',
|
exportExcel: '导出 Excel',
|
||||||
selectExcel: 'Export Selected',
|
selectExcel: '导出 已选择项',
|
||||||
uploadExcel: 'Upload Excel',
|
mergeHeader: '导出 多级表头',
|
||||||
|
uploadExcel: '上传 Excel',
|
||||||
zip: 'Zip',
|
zip: 'Zip',
|
||||||
pdf: 'PDF',
|
pdf: 'PDF',
|
||||||
exportZip: 'Export Zip',
|
exportZip: 'Export Zip',
|
||||||
|
|
|
@ -279,6 +279,12 @@ export const asyncRoutes = [
|
||||||
name: 'SelectExcel',
|
name: 'SelectExcel',
|
||||||
meta: { title: 'selectExcel' }
|
meta: { title: 'selectExcel' }
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'export-merge-header',
|
||||||
|
component: () => import('@/views/excel/mergeHeader'),
|
||||||
|
name: 'MergeHeader',
|
||||||
|
meta: { title: 'mergeHeader' }
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'upload-excel',
|
path: 'upload-excel',
|
||||||
component: () => import('@/views/excel/uploadExcel'),
|
component: () => import('@/views/excel/uploadExcel'),
|
||||||
|
|
|
@ -19,22 +19,20 @@
|
||||||
{{ scope.$index }}
|
{{ scope.$index }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="主要信息" align="center">
|
<el-table-column label="Title">
|
||||||
<el-table-column label="Title">
|
<template slot-scope="scope">
|
||||||
<template slot-scope="scope">
|
{{ scope.row.title }}
|
||||||
{{ scope.row.title }}
|
</template>
|
||||||
</template>
|
</el-table-column>
|
||||||
</el-table-column>
|
<el-table-column label="Author" width="110" align="center">
|
||||||
<el-table-column label="Author" width="110" align="center">
|
<template slot-scope="scope">
|
||||||
<template slot-scope="scope">
|
<el-tag>{{ scope.row.author }}</el-tag>
|
||||||
<el-tag>{{ scope.row.author }}</el-tag>
|
</template>
|
||||||
</template>
|
</el-table-column>
|
||||||
</el-table-column>
|
<el-table-column label="Readings" width="115" align="center">
|
||||||
<el-table-column label="Readings" width="115" align="center">
|
<template slot-scope="scope">
|
||||||
<template slot-scope="scope">
|
{{ scope.row.pageviews }}
|
||||||
{{ scope.row.pageviews }}
|
</template>
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column align="center" label="Date" width="220">
|
<el-table-column align="center" label="Date" width="220">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
|
@ -49,12 +47,10 @@
|
||||||
<script>
|
<script>
|
||||||
import { fetchList } from '@/api/article'
|
import { fetchList } from '@/api/article'
|
||||||
import { parseTime } from '@/utils'
|
import { parseTime } from '@/utils'
|
||||||
|
|
||||||
// options components
|
// options components
|
||||||
import FilenameOption from './components/FilenameOption'
|
import FilenameOption from './components/FilenameOption'
|
||||||
import AutoWidthOption from './components/AutoWidthOption'
|
import AutoWidthOption from './components/AutoWidthOption'
|
||||||
import BookTypeOption from './components/BookTypeOption'
|
import BookTypeOption from './components/BookTypeOption'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ExportExcel',
|
name: 'ExportExcel',
|
||||||
components: { FilenameOption, AutoWidthOption, BookTypeOption },
|
components: { FilenameOption, AutoWidthOption, BookTypeOption },
|
||||||
|
@ -82,17 +78,13 @@ export default {
|
||||||
handleDownload() {
|
handleDownload() {
|
||||||
this.downloadLoading = true
|
this.downloadLoading = true
|
||||||
import('@/vendor/Export2Excel').then(excel => {
|
import('@/vendor/Export2Excel').then(excel => {
|
||||||
const multiHeader = [['Id', '主要信息', '', '', 'Date']]
|
const tHeader = ['Id', 'Title', 'Author', 'Readings', 'Date']
|
||||||
const tHeader = ['', 'Title', 'Author', 'Readings', '']
|
|
||||||
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
|
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
|
||||||
const list = this.list
|
const list = this.list
|
||||||
const data = this.formatJson(filterVal, list)
|
const data = this.formatJson(filterVal, list)
|
||||||
const merges = ['A1:A2', 'B1:D1', 'E1:E2']
|
|
||||||
excel.export_json_to_excel({
|
excel.export_json_to_excel({
|
||||||
multiHeader,
|
|
||||||
header: tHeader,
|
header: tHeader,
|
||||||
data,
|
data,
|
||||||
merges,
|
|
||||||
filename: this.filename,
|
filename: this.filename,
|
||||||
autoWidth: this.autoWidth,
|
autoWidth: this.autoWidth,
|
||||||
bookType: this.bookType
|
bookType: this.bookType
|
||||||
|
@ -121,4 +113,3 @@ export default {
|
||||||
padding: 0 12px 0 30px;
|
padding: 0 12px 0 30px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
|
||||||
|
<el-button :loading="downloadLoading" style="margin-bottom:20px" type="primary" icon="document" @click="handleDownload">Export</el-button>
|
||||||
|
|
||||||
|
<el-table
|
||||||
|
v-loading="listLoading"
|
||||||
|
ref="multipleTable"
|
||||||
|
:data="list"
|
||||||
|
element-loading-text="Loading"
|
||||||
|
border
|
||||||
|
fit
|
||||||
|
highlight-current-row
|
||||||
|
>
|
||||||
|
<el-table-column align="center" label="Id" width="95">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
{{ scope.$index }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="Main Information" align="center">
|
||||||
|
<el-table-column label="Title">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
{{ scope.row.title }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="Author" width="110" align="center">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-tag>{{ scope.row.author }}</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="Readings" width="115" align="center">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
{{ scope.row.pageviews }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column align="center" label="Date" width="220">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<i class="el-icon-time"/>
|
||||||
|
<span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { fetchList } from '@/api/article'
|
||||||
|
import { parseTime } from '@/utils'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'MergeHeader',
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
list: null,
|
||||||
|
listLoading: true,
|
||||||
|
downloadLoading: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
fetchData() {
|
||||||
|
this.listLoading = true
|
||||||
|
fetchList(this.listQuery).then(response => {
|
||||||
|
this.list = response.data.items
|
||||||
|
this.listLoading = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleDownload() {
|
||||||
|
this.downloadLoading = true
|
||||||
|
import('@/vendor/Export2Excel').then(excel => {
|
||||||
|
const multiHeader = [['Id', 'Main Information', '', '', 'Date']]
|
||||||
|
const header = ['', 'Title', 'Author', 'Readings', '']
|
||||||
|
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
|
||||||
|
const list = this.list
|
||||||
|
const data = this.formatJson(filterVal, list)
|
||||||
|
const merges = ['A1:A2', 'B1:D1', 'E1:E2']
|
||||||
|
excel.export_json_to_excel({
|
||||||
|
multiHeader,
|
||||||
|
header,
|
||||||
|
merges,
|
||||||
|
data
|
||||||
|
})
|
||||||
|
this.downloadLoading = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
formatJson(filterVal, jsonData) {
|
||||||
|
return jsonData.map(v => filterVal.map(j => {
|
||||||
|
if (j === 'timestamp') {
|
||||||
|
return parseTime(v[j])
|
||||||
|
} else {
|
||||||
|
return v[j]
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in New Issue