jq002
authored
|
1
|
<template>
|
vben
authored
|
2
|
<PageWrapper title="excel数据导入示例">
|
vben
authored
|
3
|
<ImpExcel @success="loadDataSuccess">
|
vben
authored
|
4
|
<a-button class="m-3"> 导入Excel </a-button>
|
vben
authored
|
5
|
</ImpExcel>
|
jq002
authored
|
6
7
8
9
10
11
|
<BasicTable
v-for="(table, index) in tableListRef"
:key="index"
:title="table.title"
:columns="table.columns"
:dataSource="table.dataSource"
|
vben
authored
|
12
|
/>
|
vben
authored
|
13
|
</PageWrapper>
|
jq002
authored
|
14
15
16
17
|
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
|
vben
authored
|
18
|
import { ImpExcel, ExcelData } from '/@/components/Excel';
|
jq002
authored
|
19
|
import { BasicTable, BasicColumn } from '/@/components/Table';
|
vben
authored
|
20
|
import { PageWrapper } from '/@/components/Page';
|
jq002
authored
|
21
22
|
export default defineComponent({
|
vben
authored
|
23
|
components: { BasicTable, ImpExcel, PageWrapper },
|
jq002
authored
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
setup() {
const tableListRef = ref<
{
title: string;
columns?: any[];
dataSource?: any[];
}[]
>([]);
function loadDataSuccess(excelDataList: ExcelData[]) {
tableListRef.value = [];
console.log(excelDataList);
for (const excelData of excelDataList) {
const {
header,
results,
meta: { sheetName },
} = excelData;
const columns: BasicColumn[] = [];
for (const title of header) {
columns.push({ title, dataIndex: title });
}
tableListRef.value.push({ title: sheetName, dataSource: results, columns });
}
}
return {
loadDataSuccess,
tableListRef,
};
},
});
</script>
|