perf: use import replace require.ensure

This commit is contained in:
Pan 2017-12-21 13:25:29 +08:00
parent 0dfa56c73e
commit 7fef8568c2
4 changed files with 20 additions and 21 deletions

View File

@ -17,7 +17,7 @@
</el-select> </el-select>
<el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button> <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
<el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="el-icon-edit">添加</el-button> <el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="el-icon-edit">添加</el-button>
<el-button class="filter-item" type="primary" v-waves icon="el-icon-download" @click="handleDownload">导出</el-button> <el-button class="filter-item" type="primary" :loading="downloadLoading" v-waves icon="el-icon-download" @click="handleDownload">导出</el-button>
<el-checkbox class="filter-item" style='margin-left:15px;' @change='tableKey=tableKey+1' v-model="showAuditor">显示审核人</el-checkbox> <el-checkbox class="filter-item" style='margin-left:15px;' @change='tableKey=tableKey+1' v-model="showAuditor">显示审核人</el-checkbox>
</div> </div>
@ -196,7 +196,8 @@ export default {
type: [{ required: true, message: 'type is required', trigger: 'change' }], type: [{ required: true, message: 'type is required', trigger: 'change' }],
timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }], timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
title: [{ required: true, message: 'title is required', trigger: 'blur' }] title: [{ required: true, message: 'title is required', trigger: 'blur' }]
} },
downloadLoading: false
} }
}, },
filters: { filters: {
@ -330,12 +331,13 @@ export default {
}) })
}, },
handleDownload() { handleDownload() {
require.ensure([], () => { this.downloadLoading = true
const { export_json_to_excel } = require('@/vendor/Export2Excel') import('@/vendor/Export2Excel').then(excel => {
const tHeader = ['时间', '地区', '类型', '标题', '重要性'] const tHeader = ['时间', '地区', '类型', '标题', '重要性']
const filterVal = ['timestamp', 'province', 'type', 'title', 'importance'] const filterVal = ['timestamp', 'province', 'type', 'title', 'importance']
const data = this.formatJson(filterVal, this.list) const data = this.formatJson(filterVal, this.list)
export_json_to_excel(tHeader, data, 'table数据') excel.export_json_to_excel(tHeader, data, 'table数据')
this.downloadLoading = false
}) })
}, },
formatJson(filterVal, jsonData) { formatJson(filterVal, jsonData) {

View File

@ -60,13 +60,12 @@ export default {
}, },
handleDownload() { handleDownload() {
this.downloadLoading = true this.downloadLoading = true
require.ensure([], () => { import('@/vendor/Export2Excel').then(excel => {
const { export_json_to_excel } = require('@/vendor/Export2Excel')
const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间'] const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间']
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)
export_json_to_excel(tHeader, data, this.filename) excel.export_json_to_excel(tHeader, data, this.filename)
this.downloadLoading = false this.downloadLoading = false
}) })
}, },

View File

@ -66,16 +66,15 @@ export default {
handleDownload() { handleDownload() {
if (this.multipleSelection.length) { if (this.multipleSelection.length) {
this.downloadLoading = true this.downloadLoading = true
require.ensure([], () => { import('@/vendor/Export2Excel').then(excel => {
const { export_json_to_excel } = require('@/vendor/Export2Excel') const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间']
const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间'] const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']
const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time'] const list = this.multipleSelection
const list = this.multipleSelection const data = this.formatJson(filterVal, list)
const data = this.formatJson(filterVal, list) excel.export_json_to_excel(tHeader, data, this.filename)
export_json_to_excel(tHeader, data, this.filename) this.$refs.multipleTable.clearSelection()
this.$refs.multipleTable.clearSelection() this.downloadLoading = false
this.downloadLoading = false })
})
} else { } else {
this.$message({ this.$message({
message: '请至少选择一条记录', message: '请至少选择一条记录',

View File

@ -59,13 +59,12 @@ export default {
}, },
handleDownload() { handleDownload() {
this.downloadLoading = true this.downloadLoading = true
require.ensure([], () => { import('@/vendor/Export2Zip').then(zip => {
const { export_txt_to_zip } = require('@/vendor/Export2Zip')
const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间'] const tHeader = ['序号', '文章标题', '作者', '阅读数', '发布时间']
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)
export_txt_to_zip(tHeader, data, this.filename, this.filename) zip.export_txt_to_zip(tHeader, data, this.filename, this.filename)
this.downloadLoading = false this.downloadLoading = false
}) })
}, },