11<template >
2- <div class =" errPage-container" >
3- aaa
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+ <el-table-column align =" center" label =' ID' width =" 95" >
6+ <template scope="scope">
7+ {{scope.$index}}
8+ </template >
9+ </el-table-column >
10+ <el-table-column label =" 文章标题" >
11+ <template scope="scope">
12+ {{scope.row.title}}
13+ </template >
14+ </el-table-column >
15+
16+ <el-table-column label =" 作者" width =" 110" >
17+ <template scope="scope">
18+ <span >{{scope.row.author}}</span >
19+ </template >
20+ </el-table-column >
21+ <el-table-column label =" 阅读数" width =" 105" align =" center" >
22+ <template scope="scope">
23+ {{scope.row.pageviews}}
24+ </template >
25+ </el-table-column >
26+ <el-table-column align =" center" prop =" created_at" label =" 发布时间" width =" 200" >
27+ <template scope="scope">
28+ <i class =" el-icon-time" ></i >
29+ <span >{{scope.row.display_time}}</span >
30+ </template >
31+ </el-table-column >
32+ </el-table >
433 </div >
534</template >
635<script >
@@ -9,14 +38,7 @@ export default {
938 data () {
1039 return {
1140 list: null ,
12- total: null ,
13- listLoading: true ,
14- listQuery: {
15- page: 1 ,
16- limit: 20 ,
17- area: undefined ,
18- department: undefined
19- }
41+ listLoading: true
2042 }
2143 },
2244 created () {
@@ -26,12 +48,22 @@ export default {
2648 fetchData () {
2749 this .listLoading = true ;
2850 getList (this .listQuery ).then (response => {
29- console .log (response)
30- const data = response .data ;
31- this .list = data .items ;
32- this .total = data .item_count ;
51+ this .list = response .data ;
3352 this .listLoading = false ;
3453 })
54+ },
55+ handleDownload () {
56+ require .ensure ([], () => {
57+ const { export_json_to_excel } = require (' vendor/Export2Excel' );
58+ const tHeader = [' 序号' , ' 文章标题' , ' 作者' , ' 阅读数' , ' 发布时间' ];
59+ const filterVal = [' id' , ' title' , ' author' , ' pageviews' , ' display_time' ];
60+ const list = this .list ;
61+ const data = this .formatJson (filterVal, list);
62+ export_json_to_excel (tHeader, data, ' 列表excel' );
63+ })
64+ },
65+ formatJson (filterVal , jsonData ) {
66+ return jsonData .map (v => filterVal .map (j => v[j]))
3567 }
3668 }
3769};
0 commit comments