Former-commit-id: 9d931bf8ee17498b3cb6a4e8747a35379053d292 Former-commit-id: 839c0a8471016d910c9504e5a1e6cbd22a95479a Former-commit-id: 7ffc8041a93f682c2b0cc6bed1c400437dff29fb
68 lines
1.5 KiB
Vue
68 lines
1.5 KiB
Vue
<template>
|
|
<Container>
|
|
<PageHeader
|
|
slot="header"
|
|
title="导入 xlsx"
|
|
url="https://github.com/SheetJS/js-xlsx">
|
|
</PageHeader>
|
|
<div class="dd-mb">
|
|
<el-button @click="download">
|
|
<Icon name="download"></Icon>
|
|
下载演示 .xlsx 表格
|
|
</el-button>
|
|
</div>
|
|
<div class="dd-mb">
|
|
<el-upload :before-upload="handleUpload" action="default">
|
|
<el-button type="success">
|
|
<Icon name="file-o"></Icon>
|
|
选择要导入的 .xlsx 表格
|
|
</el-button>
|
|
</el-upload>
|
|
</div>
|
|
<el-table v-bind="table" class="dd-mb">
|
|
<el-table-column
|
|
v-for="(item, index) in table.columns"
|
|
:key="index"
|
|
:prop="item.prop"
|
|
:label="item.label">
|
|
</el-table-column>
|
|
</el-table>
|
|
<Markdown url="/static/md/插件 - 导入.md"></Markdown>
|
|
</Container>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data () {
|
|
return {
|
|
table: {
|
|
columns: [],
|
|
data: [],
|
|
size: 'mini',
|
|
stripe: true,
|
|
border: true
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
handleUpload (file) {
|
|
this.$import.xlsx(file)
|
|
.then(({header, results}) => {
|
|
this.table.columns = header.map(e => {
|
|
return {
|
|
label: e,
|
|
prop: e
|
|
}
|
|
})
|
|
this.table.data = results
|
|
})
|
|
return false
|
|
},
|
|
download () {
|
|
window.location.href = 'http://fairyever.qiniudn.com/d2-admin-import-xlsx-demo.xlsx'
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|