Files
vxe-table/examples/views/table/advanced/Import.vue
xuliangzhan fe76af21ff 优化重构
2020-02-22 21:39:19 +08:00

140 lines
4.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div>
<p class="tip">
导入数据通过 <table-api-link prop="importData"/> 函数可以直接将数据导入表格中<br>
如果是服务端导出通过设置 <table-api-link prop="remote"/> <table-api-link prop="importMethod"/> 开启服务端自定义导入<br>
<span class="red">附件中的字段名必须和表格一致数据格式不正确将无法导入</span>
</p>
<vxe-toolbar>
<template v-slot:buttons>
<vxe-button @click="clearDataEvent">清空数据</vxe-button>
<vxe-button @click="exportDataEvent">导出数据</vxe-button>
<vxe-button @click="importDataEvent">导入数据</vxe-button>
</template>
</vxe-toolbar>
<vxe-table
export-config
highlight-hover-row
ref="xTable"
height="400"
:data="tableData">
<vxe-table-column type="seq" width="60"></vxe-table-column>
<vxe-table-column field="name" title="Name"></vxe-table-column>
<vxe-table-column field="sex" title="Sex" :formatter="formatterSex"></vxe-table-column>
<vxe-table-column field="age" title="Age" sortable></vxe-table-column>
<vxe-table-column field="address" title="Address" show-overflow></vxe-table-column>
</vxe-table>
<p class="demo-code">{{ $t('app.body.button.showCode') }}</p>
<pre>
<code class="xml">{{ demoCodes[0] }}</code>
<code class="javascript">{{ demoCodes[1] }}</code>
</pre>
</div>
</template>
<script>
import hljs from 'highlight.js'
export default {
data () {
return {
tableData: [],
sexList: [
{
label: '女',
value: '0'
},
{
label: '男',
value: '1'
}
],
demoCodes: [
`
<vxe-toolbar>
<template v-slot:buttons>
<vxe-button @click="clearDataEvent">清空数据</vxe-button>
<vxe-button @click="exportDataEvent">导出数据</vxe-button>
<vxe-button @click="importDataEvent">导入数据</vxe-button>
</template>
</vxe-toolbar>
<vxe-table
export-config
highlight-hover-row
ref="xTable"
height="400"
:data="tableData">
<vxe-table-column type="seq" width="60"></vxe-table-column>
<vxe-table-column field="name" title="Name"></vxe-table-column>
<vxe-table-column field="sex" title="Sex" :formatter="formatterSex"></vxe-table-column>
<vxe-table-column field="age" title="Age" sortable></vxe-table-column>
<vxe-table-column field="address" title="Address" show-overflow></vxe-table-column>
</vxe-table>
`,
`
export default {
data () {
return {
tableData: []
}
},
created () {
this.tableData = window.MOCK_DATA_LIST.slice(0, 10)
},
methods: {
formatterSex ({ cellValue }) {
const item = this.sexList.find(item => item.value === cellValue)
return item ? item.label : ''
},
clearDataEvent () {
this.tableData = []
},
exportDataEvent () {
this.$refs.xTable.openExport({
// 默认勾选源
original: true
})
},
importDataEvent () {
this.$refs.xTable.importData()
}
}
}
`
]
}
},
created () {
this.tableData = window.MOCK_DATA_LIST.slice(0, 10)
},
mounted () {
Array.from(this.$el.querySelectorAll('pre code')).forEach((block) => {
hljs.highlightBlock(block)
})
},
methods: {
formatterSex ({ cellValue }) {
const item = this.sexList.find(item => item.value === cellValue)
return item ? item.label : ''
},
clearDataEvent () {
this.tableData = []
},
exportDataEvent () {
this.$refs.xTable.openExport({
// 默认勾选源
original: true
})
},
importDataEvent () {
this.$refs.xTable.importData()
}
}
}
</script>