Files
vxe-table/examples/views/table/advanced/Import.vue
xuliangzhan d708d31fda 内部优化
2020-01-15 19:07:19 +08:00

139 lines
3.9 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>
<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 }) {
let 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 }) {
let 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>