Skip to content

Commit 7fef856

Browse files
committed
perf: use import replace require.ensure
1 parent 0dfa56c commit 7fef856

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

src/views/example/table/complexTable.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</el-select>
1818
<el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
1919
<el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="el-icon-edit">添加</el-button>
20-
<el-button class="filter-item" type="primary" v-waves icon="el-icon-download" @click="handleDownload">导出</el-button>
20+
<el-button class="filter-item" type="primary" :loading="downloadLoading" v-waves icon="el-icon-download" @click="handleDownload">导出</el-button>
2121
<el-checkbox class="filter-item" style='margin-left:15px;' @change='tableKey=tableKey+1' v-model="showAuditor">显示审核人</el-checkbox>
2222
</div>
2323

@@ -196,7 +196,8 @@ export default {
196196
type: [{ required: true, message: 'type is required', trigger: 'change' }],
197197
timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
198198
title: [{ required: true, message: 'title is required', trigger: 'blur' }]
199-
}
199+
},
200+
downloadLoading: false
200201
}
201202
},
202203
filters: {
@@ -330,12 +331,13 @@ export default {
330331
})
331332
},
332333
handleDownload() {
333-
require.ensure([], () => {
334-
const { export_json_to_excel } = require('@/vendor/Export2Excel')
334+
this.downloadLoading = true
335+
import('@/vendor/Export2Excel').then(excel => {
335336
const tHeader = ['时间', '地区', '类型', '标题', '重要性']
336337
const filterVal = ['timestamp', 'province', 'type', 'title', 'importance']
337338
const data = this.formatJson(filterVal, this.list)
338-
export_json_to_excel(tHeader, data, 'table数据')
339+
excel.export_json_to_excel(tHeader, data, 'table数据')
340+
this.downloadLoading = false
339341
})
340342
},
341343
formatJson(filterVal, jsonData) {

src/views/excel/exportExcel.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ export default {
6060
},
6161
handleDownload() {
6262
this.downloadLoading = true
63-
require.ensure([], () => {
64-
const { export_json_to_excel } = require('@/vendor/Export2Excel')
63+
import('@/vendor/Export2Excel').then(excel => {
6564
const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间']
6665
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
6766
const list = this.list
6867
const data = this.formatJson(filterVal, list)
69-
export_json_to_excel(tHeader, data, this.filename)
68+
excel.export_json_to_excel(tHeader, data, this.filename)
7069
this.downloadLoading = false
7170
})
7271
},

src/views/excel/selectExcel.vue

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,15 @@ export default {
6666
handleDownload() {
6767
if (this.multipleSelection.length) {
6868
this.downloadLoading = true
69-
require.ensure([], () => {
70-
const { export_json_to_excel } = require('@/vendor/Export2Excel')
71-
const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间']
72-
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
73-
const list = this.multipleSelection
74-
const data = this.formatJson(filterVal, list)
75-
export_json_to_excel(tHeader, data, this.filename)
76-
this.$refs.multipleTable.clearSelection()
77-
this.downloadLoading = false
78-
})
69+
import('@/vendor/Export2Excel').then(excel => {
70+
const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间']
71+
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
72+
const list = this.multipleSelection
73+
const data = this.formatJson(filterVal, list)
74+
excel.export_json_to_excel(tHeader, data, this.filename)
75+
this.$refs.multipleTable.clearSelection()
76+
this.downloadLoading = false
77+
})
7978
} else {
8079
this.$message({
8180
message: '请至少选择一条记录',

src/views/zip/index.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ export default {
5959
},
6060
handleDownload() {
6161
this.downloadLoading = true
62-
require.ensure([], () => {
63-
const { export_txt_to_zip } = require('@/vendor/Export2Zip')
62+
import('@/vendor/Export2Zip').then(zip => {
6463
const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间']
6564
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
6665
const list = this.list
6766
const data = this.formatJson(filterVal, list)
68-
export_txt_to_zip(tHeader, data, this.filename, this.filename)
67+
zip.export_txt_to_zip(tHeader, data, this.filename, this.filename)
6968
this.downloadLoading = false
7069
})
7170
},

0 commit comments

Comments
 (0)