chore: 导出excel demo
This commit is contained in:
parent
095eab6db4
commit
a623f81fec
@ -49,7 +49,8 @@
|
|||||||
"download": "Download",
|
"download": "Download",
|
||||||
"sync": "Sync",
|
"sync": "Sync",
|
||||||
"refresh": "Refresh",
|
"refresh": "Refresh",
|
||||||
"generate": "Generate"
|
"generate": "Generate",
|
||||||
|
"downloadLoading": "Downloading... Please wait."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,8 @@
|
|||||||
"download": "下载",
|
"download": "下载",
|
||||||
"sync": "同步",
|
"sync": "同步",
|
||||||
"refresh": "刷新",
|
"refresh": "刷新",
|
||||||
"generate": "生成"
|
"generate": "生成",
|
||||||
|
"downloadLoading": "下载中, 请稍后..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,35 @@
|
|||||||
import { openWindow } from '..';
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { dataURLtoBlob, urlToBase64 } from './base64Conver';
|
import { dataURLtoBlob, urlToBase64 } from './base64Conver';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载excel文件
|
||||||
|
* @param [func] axios函数
|
||||||
|
* @param [fileName] 文件名称 不需要带xlsx后缀
|
||||||
|
* @param [requestData] 请求参数
|
||||||
|
* @param [withRandomName] 是否带随机文件名
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
export async function downloadExcel(
|
||||||
|
func: (data?: any) => Promise<Blob>,
|
||||||
|
fileName: string,
|
||||||
|
requestData: any = {},
|
||||||
|
withRandomName = true,
|
||||||
|
) {
|
||||||
|
const hideLoading = message.loading($t('pages.common.downloadLoading'), 0);
|
||||||
|
try {
|
||||||
|
const data = await func(requestData);
|
||||||
|
downloadExcelFile(data, fileName, withRandomName);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function downloadExcelFile(
|
export function downloadExcelFile(
|
||||||
data: BlobPart,
|
data: BlobPart,
|
||||||
filename: string,
|
filename: string,
|
||||||
@ -78,6 +107,23 @@ export function downloadByData(
|
|||||||
window.URL.revokeObjectURL(blobURL);
|
window.URL.revokeObjectURL(blobURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function openWindow(
|
||||||
|
url: string,
|
||||||
|
opt?: {
|
||||||
|
noopener?: boolean;
|
||||||
|
noreferrer?: boolean;
|
||||||
|
target?: '_blank' | '_self' | string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const { noopener = true, noreferrer = true, target = '__blank' } = opt || {};
|
||||||
|
const feature: string[] = [];
|
||||||
|
|
||||||
|
noopener && feature.push('noopener=yes');
|
||||||
|
noreferrer && feature.push('noreferrer=yes');
|
||||||
|
|
||||||
|
window.open(url, target, feature.join(','));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download file according to file address
|
* Download file according to file address
|
||||||
* @param {*} sUrl
|
* @param {*} sUrl
|
||||||
|
@ -11,7 +11,8 @@ import { DictEnum } from '@vben/constants';
|
|||||||
|
|
||||||
import { Space, Table } from 'ant-design-vue';
|
import { Space, Table } from 'ant-design-vue';
|
||||||
|
|
||||||
import { configList } from '#/api/system/config';
|
import { configExport, configList } from '#/api/system/config';
|
||||||
|
import { downloadExcel } from '#/utils/file/download';
|
||||||
import { renderDict } from '#/utils/render';
|
import { renderDict } from '#/utils/render';
|
||||||
|
|
||||||
import configModal from './config-modal.vue';
|
import configModal from './config-modal.vue';
|
||||||
@ -83,7 +84,10 @@ const columns: ColumnsType = [
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page>
|
<Page>
|
||||||
<div class="mb-[16px] flex justify-end">
|
<div class="mb-[16px] flex justify-end gap-[8px]">
|
||||||
|
<a-button @click="downloadExcel(configExport, '参数配置', {})">
|
||||||
|
{{ $t('pages.common.export') }}
|
||||||
|
</a-button>
|
||||||
<a-button type="primary" @click="handleAdd">
|
<a-button type="primary" @click="handleAdd">
|
||||||
{{ $t('pages.common.add') }}
|
{{ $t('pages.common.add') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
|
Loading…
Reference in New Issue
Block a user