1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
| <template>
| <el-dialog title="提示"
| :visible.sync="sonPrintDialogVisible"
| width="30%"
| center>
| <span>请选择导出范围</span>
| <span slot="footer"
| class="dialog-footer">
| <el-button type="primary"
| @click="exprotCurPage">仅 本 页 导 出</el-button>
| <el-button type="success"
| @click="exprotAll">全 部 导 出</el-button>
| <el-button @click="sonPrintDialogVisible = false">取 消 导 出</el-button>
|
| </span>
| </el-dialog>
| </template>
| <script>
| import XLSX, { WorkSheet } from "xlsx";
| import { getNowFormatDateForExport } from '../../util/tools'
| export default {
| name: "ToolbarExport",
| data () {
| return {
| sonPrintDialogVisible: false
| };
| },
| props: {
| exportFileName: {
| type: String,
| required: true,
| },
| //接受父组件传值
| filterVal: {
| type: Array,
| required: true,
| },
| tHeader: {
| type: Array,
| required: true,
| },
| currentPageData: {
| type: Array,
| required: true,
| }
| },
| methods: {
| showPrintPage () {
| this.sonPrintDialogVisible = true
| },
| // 仅导出本页
| exprotCurPage () {
| this.export2Excel(this.currentPageData)
| },
| // 导出全部
| exprotAll () {
| this.$parent.exportAllData()
| },
| /** 加载方法 */
| loadingToload (text) {
| const loading = this.$loading({
| lock: true,
| text: text,
| spinner: 'el-icon-loading',
| background: 'rgba(255, 255, 255, 0.8)',
| target: document.querySelector('#mainDiv')
| })
| this.curLoading = loading
| },
| // 导出Excel表格
| export2Excel (exportData) {
| var text = this.exportFileName + '导出中...'
| this.loadingToload(text)
|
| require.ensure([], () => {
| const { export_json_to_excel } = require('../../util/Export2Excel.js') // Export2Excel.js路径
| const list = exportData // 数据源
| const data = this.formatJson(this.filterVal, list) // 数据为json格式
| export_json_to_excel(this.tHeader, data, this.exportFileName + '(' + getNowFormatDateForExport() + ')') // 导出表格名字
| this.$notify({
| title: '导出成功',
| message: this.exportFileName + '导出成功',
| type: 'success'
| })
| this.sonPrintDialogVisible = false
| this.curLoading.close()
| })
| },
| formatJson (filterVal, jsonData) {
| return jsonData.map(v => filterVal.map(j => v[j]))
| }
| }
| };
| </script>
|
|