mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2026-02-13 17:30:27 +08:00
52
src/views/table/high/excel/columns.tsx
Normal file
52
src/views/table/high/excel/columns.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import { ref } from "vue";
|
||||
import { utils, writeFile } from "xlsx";
|
||||
import { tableDataDrag } from "../data";
|
||||
import { clone } from "@pureadmin/utils";
|
||||
import { message } from "@/utils/message";
|
||||
|
||||
export function useColumns() {
|
||||
const dataList = ref(clone(tableDataDrag, true));
|
||||
|
||||
const columns: TableColumnList = [
|
||||
{
|
||||
label: "ID",
|
||||
prop: "id"
|
||||
},
|
||||
{
|
||||
label: "日期",
|
||||
prop: "date"
|
||||
},
|
||||
{
|
||||
label: "姓名",
|
||||
prop: "name"
|
||||
}
|
||||
];
|
||||
|
||||
const exportExcel = () => {
|
||||
const res = dataList.value.map(item => {
|
||||
const arr = [];
|
||||
columns.forEach(column => {
|
||||
arr.push(item[column.prop as string]);
|
||||
});
|
||||
return arr;
|
||||
});
|
||||
const titleList = [];
|
||||
columns.forEach(column => {
|
||||
titleList.push(column.label);
|
||||
});
|
||||
res.unshift(titleList);
|
||||
const workSheet = utils.aoa_to_sheet(res);
|
||||
const workBook = utils.book_new();
|
||||
utils.book_append_sheet(workBook, workSheet, "数据报表");
|
||||
writeFile(workBook, "pure-admin-table.xlsx");
|
||||
message("导出成功", {
|
||||
type: "success"
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
columns,
|
||||
dataList,
|
||||
exportExcel
|
||||
};
|
||||
}
|
||||
18
src/views/table/high/excel/index.vue
Normal file
18
src/views/table/high/excel/index.vue
Normal file
@@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { useColumns } from "./columns";
|
||||
|
||||
const { columns, dataList, exportExcel } = useColumns();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<el-button
|
||||
type="primary"
|
||||
class="mb-[20px] float-right"
|
||||
@click="exportExcel"
|
||||
>
|
||||
导出
|
||||
</el-button>
|
||||
<pure-table row-key="id" border :data="dataList" :columns="columns" />
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user