feat(报表): 重构报表模块并添加下载功能
重构各报表页面,提取公共逻辑到useMonthReport和MonthReportView组件 添加报表下载功能,支持单月下载和全年下载 统一各报表的API调用方式和数据处理逻辑 优化代码结构,减少重复代码
This commit is contained in:
@@ -55,10 +55,7 @@ export function downloadFileFromBase64({ fileName, source }: DownloadOptions) {
|
||||
/**
|
||||
* 通过图片 URL 下载图片文件
|
||||
*/
|
||||
export async function downloadFileFromImageUrl({
|
||||
fileName,
|
||||
source,
|
||||
}: DownloadOptions) {
|
||||
export async function downloadFileFromImageUrl({ fileName, source }: DownloadOptions) {
|
||||
const base64 = await urlToBase64(source);
|
||||
downloadFileFromBase64({ fileName, source: base64 });
|
||||
}
|
||||
@@ -87,9 +84,7 @@ export function downloadFileFromBlobPart({
|
||||
}: DownloadOptions<BlobPart>): void {
|
||||
// 如果 data 不是 Blob,则转换为 Blob
|
||||
const blob =
|
||||
source instanceof Blob
|
||||
? source
|
||||
: new Blob([source], { type: 'application/octet-stream' });
|
||||
source instanceof Blob ? source : new Blob([source], { type: 'application/octet-stream' });
|
||||
|
||||
// 创建对象 URL 并触发下载
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
@@ -22,13 +22,10 @@ class FileDownloader {
|
||||
* @param config 配置信息,可选。
|
||||
* @returns 如果config.responseReturn为'body',则返回Blob(默认),否则返回RequestResponse<Blob>
|
||||
*/
|
||||
public async download<T = Blob>(
|
||||
url: string,
|
||||
config?: DownloadRequestConfig,
|
||||
): Promise<T> {
|
||||
public async download<T = Blob>(url: string, config?: DownloadRequestConfig): Promise<T> {
|
||||
const finalConfig: DownloadRequestConfig = {
|
||||
responseReturn: 'body',
|
||||
method: 'GET',
|
||||
method: 'post',
|
||||
...config,
|
||||
responseType: 'blob',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user