Commit e6d3866d by lijiabin

【需求 20331】 feat: 加入导入excel和导出excel 相关的按钮组件,用于后台

parent e8385acb
<!-- 导出excel按钮组件 后端直接返回纯数据 前端根据数据处理生成excel -->
<script setup lang="tsx" generic="T, K">
import { exportExcel, type ExportColumn } from '@/utils'
import type { BackendServiceResult } from '@/utils/request/types'
const {
api,
searchParams,
fileName = '导出数据',
columns,
} = defineProps<{
api: (params: T) => Promise<BackendServiceResult<K[]>>
searchParams: T
columns: ExportColumn<K>[]
fileName: string
}>()
const loading = ref(false)
const handleExport = async () => {
loading.value = true
try {
const { data } = await api(searchParams)
loading.value = false
exportExcel({
data,
columns,
fileName,
})
} catch (error) {
console.log(error)
} finally {
loading.value = false
}
}
</script>
<template>
<el-button :loading="loading" type="primary" @click="handleExport">
<el-icon v-show="!loading"><IEpDownload /></el-icon>
导出
</el-button>
</template>
// 导入excel相关 <!-- 导入excel按钮组件 前端传二进制文件 -->
<script setup lang="tsx" generic="T"> <script setup lang="tsx" generic="T">
import type { BackendServiceResult } from '@/utils/request/types' import type { BackendServiceResult } from '@/utils/request/types'
const props = defineProps<{ const props = defineProps<{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment