2018-02-15 15:06:39 +08:00
|
|
|
<template>
|
|
|
|
|
<Container>
|
|
|
|
|
<PageHeader
|
|
|
|
|
slot="header"
|
|
|
|
|
title="导入 xlsx"
|
2018-02-15 15:10:28 +08:00
|
|
|
url="https://github.com/SheetJS/js-xlsx">
|
2018-02-15 15:06:39 +08:00
|
|
|
</PageHeader>
|
2018-02-15 15:21:57 +08:00
|
|
|
<div class="dd-mb">
|
2018-02-15 15:06:39 +08:00
|
|
|
<el-button @click="download">
|
|
|
|
|
<Icon name="download"></Icon>
|
2018-02-15 15:21:57 +08:00
|
|
|
下载演示 .xlsx 表格
|
2018-02-15 15:06:39 +08:00
|
|
|
</el-button>
|
2018-02-15 15:21:57 +08:00
|
|
|
</div>
|
2018-02-15 15:06:39 +08:00
|
|
|
<div class="dd-mb">
|
|
|
|
|
<el-upload :before-upload="handleUpload" action="default">
|
|
|
|
|
<el-button type="success">
|
|
|
|
|
<Icon name="file-o"></Icon>
|
2018-02-15 15:21:57 +08:00
|
|
|
选择要导入的 .xlsx 表格
|
2018-02-15 15:06:39 +08:00
|
|
|
</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>
|
2018-03-21 20:29:50 +08:00
|
|
|
<Markdown url="/static/md/插件 - 导入.md"></Markdown>
|
2018-02-15 15:06:39 +08:00
|
|
|
</Container>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
2018-02-15 15:38:07 +08:00
|
|
|
data () {
|
2018-02-15 15:06:39 +08:00
|
|
|
return {
|
|
|
|
|
table: {
|
|
|
|
|
columns: [],
|
|
|
|
|
data: [],
|
|
|
|
|
size: 'mini',
|
|
|
|
|
stripe: true,
|
|
|
|
|
border: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2018-02-15 15:38:07 +08:00
|
|
|
handleUpload (file) {
|
2018-02-15 23:24:31 +08:00
|
|
|
this.$import.xlsx(file)
|
2018-02-15 15:38:07 +08:00
|
|
|
.then(({header, results}) => {
|
|
|
|
|
this.table.columns = header.map(e => {
|
|
|
|
|
return {
|
|
|
|
|
label: e,
|
|
|
|
|
prop: e
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
this.table.data = results
|
|
|
|
|
})
|
2018-02-15 15:06:39 +08:00
|
|
|
return false
|
|
|
|
|
},
|
2018-02-15 15:21:57 +08:00
|
|
|
download () {
|
|
|
|
|
window.location.href = 'http://fairyever.qiniudn.com/d2-admin-import-xlsx-demo.xlsx'
|
2018-02-15 15:06:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|