Browse Source

fix: 调整数据集、模型文件下载

dev-zw
zhaowei 10 months ago
parent
commit
fd34c3bd40
4 changed files with 45 additions and 3 deletions
  1. +9
    -3
      react-ui/src/pages/Dataset/components/ResourceVersion/index.tsx
  2. +5
    -0
      react-ui/src/pages/Dataset/config.tsx
  3. +16
    -0
      react-ui/src/services/dataset/index.js
  4. +15
    -0
      react-ui/src/utils/downloadfile.ts

+ 9
- 3
react-ui/src/pages/Dataset/components/ResourceVersion/index.tsx View File

@@ -11,7 +11,8 @@ import {
ResourceType,
resourceConfig,
} from '@/pages/Dataset/config';
import { downLoadZip } from '@/utils/downloadfile';
import { downLoadZip, downloadFileWithUrl } from '@/utils/downloadfile';
import { to } from '@/utils/promise';
import tableCellRender, { TableCellValueType } from '@/utils/table';
import { Button, Flex, Table, TableProps } from 'antd';
import styles from './index.less';
@@ -41,8 +42,13 @@ function ResourceVersion({ resourceType, info }: ResourceVersionProps) {

// 单个导出
const downloadAlone = async (record: ResourceFileData) => {
const url = config.downloadSingleAction;
downLoadZip(url, { url: record.url });
const request = config.getFileUrl;
const [res] = await to(request({ url: record.url }));
if (res && res.data) {
const url = res.data;
downloadFileWithUrl(url, record.file_name);
}
// downLoadZip(url, { url: record.url });
};

const columns: TableProps<ResourceFileData>['columns'] = [


+ 5
- 0
react-ui/src/pages/Dataset/config.tsx View File

@@ -11,10 +11,12 @@ import {
deleteModelVersion,
editDatasetVersion,
editModelVersion,
getDatasetFileUrlReq,
getDatasetInfo,
getDatasetList,
getDatasetNextVersionReq,
getDatasetVersionList,
getModelFileUrlReq,
getModelInfo,
getModelList,
getModelNextVersionReq,
@@ -48,6 +50,7 @@ type ResourceTypeInfo = {
compareVersion: (params: any) => Promise<any>; // 版本对比
getNextVersion: (params: any) => Promise<any>; // 获取下一个版本
publish: (params: any) => Promise<any>; // 发布
getFileUrl: (params: any) => Promise<any>; // 获取文件地址
name: string; // 名称
typeParamKey: 'data_type' | 'model_type'; // 类型参数名称,获取资源列表接口使用
tagParamKey: 'data_tag' | 'model_tag'; // 标签参数名称,获取资源列表接口使用
@@ -80,6 +83,7 @@ export const resourceConfig: Record<ResourceType, ResourceTypeInfo> = {
compareVersion: compareDatasetVersion,
getNextVersion: getDatasetNextVersionReq,
publish: publishDatasetReq,
getFileUrl: getDatasetFileUrlReq,
name: '数据集',
typeParamKey: 'data_type',
tagParamKey: 'data_tag',
@@ -121,6 +125,7 @@ export const resourceConfig: Record<ResourceType, ResourceTypeInfo> = {
compareVersion: compareModelVersion,
getNextVersion: getModelNextVersionReq,
publish: publishModelReq,
getFileUrl: getModelFileUrlReq,
name: '模型',
typeParamKey: 'model_type',
tagParamKey: 'model_tag',


+ 16
- 0
react-ui/src/services/dataset/index.js View File

@@ -106,6 +106,14 @@ export function publishDatasetReq(data) {
});
}

// 获取数据集版本单个文件下载地址
export function getDatasetFileUrlReq(params) {
return request(`/api/mmp/newdataset/downloadSingleFile`, {
method: 'GET',
params,
});
}


// ----------------------------模型---------------------------------

@@ -253,4 +261,12 @@ export function publishModelReq(data) {
});
}

// 获取模型版本单个文件下载地址
export function getModelFileUrlReq(params) {
return request(`/api/mmp/newmodel/downloadSingleFile`, {
method: 'GET',
params,
});
}



+ 15
- 0
react-ui/src/utils/downloadfile.ts View File

@@ -97,3 +97,18 @@ export function downloadCommonFile(
resolveBlob(res, type, fileName);
});
}

/**
* 下载链接文件
* @param url - url 地址
* @param fileName - 文件名
*/
export function downloadFileWithUrl(url: string, fileName: string) {
const aLink = document.createElement('a');
aLink.style.display = 'none';
aLink.href = url;
aLink.setAttribute('download', fileName); // 设置下载文件名称
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
}

Loading…
Cancel
Save