feat(缺陷管理): 导出接口对接

This commit is contained in:
RubyLiu 2024-02-07 17:52:59 +08:00 committed by Craftsman
parent ac9a0e5c78
commit a739d09cf9
4 changed files with 52 additions and 23 deletions

View File

@ -76,8 +76,11 @@ export function syncBugOpenSource(params: { projectId: string }) {
} }
// 导出缺陷 // 导出缺陷
export function exportBug(data: BugExportParams) { export function exportBug(data: TableQueryParams) {
return MSR.post({ url: bugURL.postExportBugUrl, data }); return MSR.post<BlobPart>(
{ url: bugURL.postExportBugUrl, data, responseType: 'blob' },
{ isTransformResponse: false }
);
} }
// 获取关联文件列表 // 获取关联文件列表
export function getAssociatedFileList(data: TableQueryParams) { export function getAssociatedFileList(data: TableQueryParams) {

View File

@ -72,7 +72,7 @@
:show-delete="props.allowEdit" :show-delete="props.allowEdit"
> >
<template #actions="{ item }"> <template #actions="{ item }">
<div v-if="props.allowEdit"> <div>
<!-- 本地文件 --> <!-- 本地文件 -->
<div v-if="item.local || item.status === 'init'" class="flex flex-nowrap"> <div v-if="item.local || item.status === 'init'" class="flex flex-nowrap">
<MsButton <MsButton
@ -191,8 +191,7 @@
import { AssociatedList, AttachFileInfo } from '@/models/caseManagement/featureCase'; import { AssociatedList, AttachFileInfo } from '@/models/caseManagement/featureCase';
import { TableQueryParams } from '@/models/common'; import { TableQueryParams } from '@/models/common';
import { convertToFileByBug } from '@/views/bug-management/utils'; import { convertToFileByBug, convertToFileByDetail } from '@/views/bug-management/utils';
import { convertToFile } from '@/views/case-management/caseManagementFeature/components/utils';
defineOptions({ defineOptions({
name: 'BugDetailTab', name: 'BugDetailTab',
@ -340,12 +339,6 @@
associatedDrawer.value = true; associatedDrawer.value = true;
} }
//
function saveSelectAssociatedFile(fileData: AssociatedList[]) {
const fileResultList = fileData.map((fileInfo) => convertToFile(fileInfo));
fileList.value.push(...fileResultList);
}
// localitem // localitem
const oldLocalFileList = computed(() => { const oldLocalFileList = computed(() => {
return attachmentsList.value.filter((item) => item.local).map((item: any) => item.uid); return attachmentsList.value.filter((item) => item.local).map((item: any) => item.uid);
@ -412,7 +405,7 @@
watch( watch(
() => fileList.value, () => fileList.value,
async (val) => { async (val) => {
const isNewFiles = val.filter((item) => item.status === 'init' || (!item.local && !item.associateId)).length; const isNewFiles = val.filter((item) => item.status === 'init').length;
if (val && isNewFiles) { if (val && isNewFiles) {
startUpload(); startUpload();
} }
@ -486,6 +479,13 @@
} }
} }
//
function saveSelectAssociatedFile(fileData: AssociatedList[]) {
const fileResultList = fileData.map(convertToFileByDetail);
fileList.value.push(...fileResultList);
handleSave();
}
watchEffect(() => { watchEffect(() => {
initCurrentDetail(props.detailInfo); initCurrentDetail(props.detailInfo);
}); });

View File

@ -157,7 +157,7 @@
import router from '@/router'; import router from '@/router';
import { useAppStore, useTableStore } from '@/store'; import { useAppStore, useTableStore } from '@/store';
import useLicenseStore from '@/store/modules/setting/license'; import useLicenseStore from '@/store/modules/setting/license';
import { customFieldToColumns, tableParamsToRequestParams } from '@/utils'; import { customFieldToColumns, downloadByteFile, tableParamsToRequestParams } from '@/utils';
import { BugEditCustomField, BugListItem } from '@/models/bug-management'; import { BugEditCustomField, BugListItem } from '@/models/bug-management';
import { RouteEnum } from '@/enums/routeEnum'; import { RouteEnum } from '@/enums/routeEnum';
@ -379,19 +379,18 @@
const exportConfirm = async (option: MsExportDrawerOption[]) => { const exportConfirm = async (option: MsExportDrawerOption[]) => {
try { try {
const { selectedIds, selectAll, excludeIds } = currentSelectParams.value; const params = tableParamsToRequestParams(currentSelectParams.value);
await exportBug({ const blob = await exportBug({
selectIds: selectedIds || [], ...params,
selectAll, exportColumns: option.map((item) => item),
excludeIds, projectId: appStore.currentProjectId,
condition: { keyword: keyword.value },
bugExportColumns: option.map((item) => item),
}); });
Message.success(t('common.exportSuccess')); downloadByteFile(blob, `${t('bugManagement.exportBug')}.zip`);
exportVisible.value = false; exportVisible.value = false;
resetSelector(); resetSelector();
} catch (error) { } catch (error) {
Message.error(t('common.exportFail')); // eslint-disable-next-line no-console
console.log(error);
} }
}; };

View File

@ -31,5 +31,32 @@ export function convertToFileByBug(fileInfo: AssociatedList): MsFileItem {
associateId: refId, associateId: refId,
}; };
} }
/** *
*
* @description
* @param {stafileInfotus} file
*/
export default {}; export function convertToFileByDetail(fileInfo: AssociatedList): MsFileItem {
const gatewayAddress = `${window.location.protocol}//${window.location.hostname}:${window.location.port}`;
const fileName = fileInfo.fileType ? `${fileInfo.name}.${fileInfo.fileType || ''}` : `${fileInfo.name}`;
const type = fileName.split('.')[1];
const file = new File([new Blob()], `${fileName}`, {
type: `application/${type}`,
});
Object.defineProperty(file, 'size', { value: fileInfo.size });
const { id, local, isUpdateFlag, associateId } = fileInfo;
return {
enable: fileInfo.enable || false,
file,
name: fileName,
percent: 0,
status: 'done',
uid: id,
url: `${gatewayAddress}/${fileInfo.filePath || ''}`,
local,
deleteContent: local ? '' : 'caseManagement.featureCase.cancelLink',
isUpdateFlag,
associateId,
};
}