no message
Former-commit-id: f3c11b2f64cc627044be20129050e193a8eec631 Former-commit-id: 49657d956a264020cda5ee3230870cf736197400 Former-commit-id: c3796afffe32e911c917133f2dc804cfe664acd7
This commit is contained in:
65
src/pages/demo/plugins/import/csv.vue
Normal file
65
src/pages/demo/plugins/import/csv.vue
Normal file
@@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<Container>
|
||||
<PageHeader
|
||||
slot="header"
|
||||
title="导入 csv"
|
||||
url="https://github.com/mholt/PapaParse">
|
||||
</PageHeader>
|
||||
<div class="dd-mb">
|
||||
<el-button @click="download">
|
||||
<Icon name="download"></Icon>
|
||||
下载演示 .csv 表格
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="dd-mb">
|
||||
<el-upload :before-upload="handleUpload" action="default">
|
||||
<el-button type="success">
|
||||
<Icon name="file-o"></Icon>
|
||||
选择要导入的 .csv 表格
|
||||
</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.csv(file)
|
||||
.then(res => {
|
||||
this.table.columns = Object.keys(res.data[0]).map(e => ({
|
||||
label: e,
|
||||
prop: e
|
||||
}))
|
||||
this.table.data = res.data
|
||||
})
|
||||
return false
|
||||
},
|
||||
download () {
|
||||
window.location.href = 'http://fairyever.qiniudn.com/d2-admin-import-csv-demo.csv'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user