Skip to content

Commit 3488930

Browse files
spiritreePanJiaChen
authored andcommitted
add new export-excel function
1 parent 4467420 commit 3488930

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

src/router/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const ErrorLog = _import('errlog/index');
4646

4747
/* excel */
4848
const ExcelDownload = _import('excel/index');
49+
const SelectExcelDownload = _import('excel/excel2');
4950

5051
/* theme */
5152
const Theme = _import('theme/index');
@@ -174,8 +175,10 @@ export const asyncRouterMap = [
174175
redirect: 'noredirect',
175176
name: 'excel',
176177
icon: 'EXCEL',
177-
noDropdown: true,
178-
children: [{ path: 'download', component: ExcelDownload, name: '导出excel' }]
178+
children: [
179+
{ path: 'download', component: ExcelDownload, name: '导出excel' },
180+
{ path: 'download2', component: SelectExcelDownload, name: '选择导出excel' }
181+
]
179182
},
180183
{
181184
path: '/theme',

src/views/excel/excel2.vue

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<template>
2+
<div class="app-container">
3+
<el-button style='margin-bottom:20px;float:right' type="primary" icon="document" @click="handleDownload">导出excel</el-button>
4+
<el-table :data="list" v-loading.body="listLoading" element-loading-text="拼命加载中" border fit highlight-current-row
5+
@selection-change="handleSelectionChange" ref="multipleTable">
6+
<el-table-column type="selection" align="center"></el-table-column>
7+
<el-table-column align="center" label='ID' width="95">
8+
<template scope="scope">
9+
{{scope.$index}}
10+
</template>
11+
</el-table-column>
12+
<el-table-column label="文章标题">
13+
<template scope="scope">
14+
{{scope.row.title}}
15+
</template>
16+
</el-table-column>
17+
18+
<el-table-column label="作者" width="110">
19+
<template scope="scope">
20+
<span>{{scope.row.author}}</span>
21+
</template>
22+
</el-table-column>
23+
<el-table-column label="阅读数" width="105" align="center">
24+
<template scope="scope">
25+
{{scope.row.pageviews}}
26+
</template>
27+
</el-table-column>
28+
<el-table-column align="center" prop="created_at" label="发布时间" width="200">
29+
<template scope="scope">
30+
<i class="el-icon-time"></i>
31+
<span>{{scope.row.display_time}}</span>
32+
</template>
33+
</el-table-column>
34+
</el-table>
35+
</div>
36+
</template>
37+
38+
<script>
39+
import { getList } from 'api/article';
40+
41+
export default {
42+
data() {
43+
return {
44+
list: null,
45+
listLoading: true,
46+
multipleSelection: []
47+
}
48+
},
49+
created() {
50+
this.fetchData();
51+
},
52+
methods: {
53+
fetchData() {
54+
this.listLoading = true;
55+
getList(this.listQuery).then(response => {
56+
this.list = response.data;
57+
this.listLoading = false;
58+
})
59+
},
60+
handleSelectionChange(val) {
61+
this.multipleSelection = val;
62+
},
63+
handleDownload() {
64+
require.ensure([], () => {
65+
const {
66+
export_json_to_excel
67+
} = require('vendor/Export2Excel');
68+
const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间'];
69+
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time'];
70+
const list = this.multipleSelection;
71+
const data = this.formatJson(filterVal, list);
72+
export_json_to_excel(tHeader, data, '列表excel');
73+
this.$refs.multipleTable.clearSelection();
74+
})
75+
},
76+
formatJson(filterVal, jsonData) {
77+
return jsonData.map(v => filterVal.map(j => v[j]))
78+
}
79+
}
80+
};
81+
</script>

0 commit comments

Comments
 (0)