feat(缺陷管理): 关联文件接口对接

This commit is contained in:
RubyLiu 2024-02-04 20:52:11 +08:00 committed by Craftsman
parent 77015d2127
commit 6aa7112d16
4 changed files with 104 additions and 43 deletions

View File

@ -155,3 +155,7 @@ export function deleteFileOrCancelAssociation(data: OperationFile) {
export function getAttachmentList(bugId: string) { export function getAttachmentList(bugId: string) {
return MSR.get({ url: `${bugURL.getAttachmentListUrl}${bugId}` }); return MSR.get({ url: `${bugURL.getAttachmentListUrl}${bugId}` });
} }
// 富文本编辑器上传图片文件
export function editorUploadFile(data: { fileList: File[] }) {
return MSR.uploadFile({ url: bugURL.editorUploadFileUrl }, { fileList: data.fileList }, '', false);
}

View File

@ -38,3 +38,5 @@ export const getFileIsUpdateUrl = '/bug/attachment/update';
export const deleteFileOrCancelAssociationUrl = '/bug/attachment/delete'; export const deleteFileOrCancelAssociationUrl = '/bug/attachment/delete';
// 获取附件列表 // 获取附件列表
export const getAttachmentListUrl = '/bug/attachment/list/'; export const getAttachmentListUrl = '/bug/attachment/list/';
// 富文本编辑器上传图片
export const editorUploadFileUrl = '/bug/attachment/upload/editor';

View File

@ -33,7 +33,11 @@
<a-input v-model="form.title" :max-length="255" /> <a-input v-model="form.title" :max-length="255" />
</a-form-item> </a-form-item>
<a-form-item field="description" :label="t('bugManagement.edit.content')"> <a-form-item field="description" :label="t('bugManagement.edit.content')">
<MsRichText v-model:raw="form.description" /> <MsRichText
v-model:raw="form.description"
v-model:filed-ids="richTextFileIds"
:upload-image="handleUploadImage"
/>
</a-form-item> </a-form-item>
<a-form-item field="attachment" :label="t('bugManagement.edit.file')"> <a-form-item field="attachment" :label="t('bugManagement.edit.file')">
<div class="flex flex-col"> <div class="flex flex-col">
@ -145,13 +149,7 @@
</div> </div>
<a-divider class="ml-[16px]" direction="vertical" /> <a-divider class="ml-[16px]" direction="vertical" />
<div class="right mt-[16px] max-w-[433px] grow pr-[24px]"> <div class="right mt-[16px] max-w-[433px] grow pr-[24px]">
<MsFormCreate <MsFormCreate ref="formCreateRef" v-model:formItem="formItem" v-model:api="fApi" :form-rule="formRules" />
v-if="formRules.length"
ref="formCreateRef"
v-model:formItem="formItem"
v-model:api="fApi"
:form-rule="formRules"
/>
<a-form-item field="tag" :label="t('bugManagement.tag')"> <a-form-item field="tag" :label="t('bugManagement.tag')">
<MsTagsInput <MsTagsInput
v-model:model-value="form.tags" v-model:model-value="form.tags"
@ -209,6 +207,7 @@
checkFileIsUpdateRequest, checkFileIsUpdateRequest,
createOrUpdateBug, createOrUpdateBug,
downloadFileRequest, downloadFileRequest,
editorUploadFile,
getAssociatedFileList, getAssociatedFileList,
getBugDetail, getBugDetail,
getTemplateById, getTemplateById,
@ -230,7 +229,9 @@
import { SelectValue } from '@/models/projectManagement/menuManagement'; import { SelectValue } from '@/models/projectManagement/menuManagement';
import { BugManagementRouteEnum } from '@/enums/routeEnum'; import { BugManagementRouteEnum } from '@/enums/routeEnum';
import { convertToFile } from '../case-management/caseManagementFeature/components/utils'; import { convertToFileByBug } from './utils';
defineOptions({ name: 'BugEditPage' });
const { t } = useI18n(); const { t } = useI18n();
@ -240,8 +241,6 @@
} }
const appStore = useAppStore(); const appStore = useAppStore();
// const formCreateStore = useFormCreateStore();
const route = useRoute(); const route = useRoute();
const templateOption = ref<TemplateOption[]>([]); const templateOption = ref<TemplateOption[]>([]);
const form = ref<BugEditFormObject>({ const form = ref<BugEditFormObject>({
@ -250,6 +249,9 @@
description: '', description: '',
templateId: '', templateId: '',
tags: [], tags: [],
deleteLocalFileIds: [],
unLinkRefIds: [],
linkFileIds: [],
}); });
const getListFunParams = ref<TableQueryParams>({ const getListFunParams = ref<TableQueryParams>({
@ -271,8 +273,10 @@
const isEdit = computed(() => !!route.query.id && route.params.mode === 'edit'); const isEdit = computed(() => !!route.query.id && route.params.mode === 'edit');
const bugId = computed(() => route.query.id || ''); const bugId = computed(() => route.query.id || '');
const isEditOrCopy = computed(() => !!bugId.value);
const imageUrl = ref(''); const imageUrl = ref('');
const previewVisible = ref<boolean>(false); const previewVisible = ref<boolean>(false);
const richTextFileIds = ref<string[]>([]);
const title = computed(() => { const title = computed(() => {
return isEdit.value ? t('bugManagement.editBug') : t('bugManagement.createBug'); return isEdit.value ? t('bugManagement.editBug') : t('bugManagement.createBug');
@ -302,13 +306,6 @@
return attachmentsList.value.filter((item) => item.local).map((item: any) => item.uid); return attachmentsList.value.filter((item) => item.local).map((item: any) => item.uid);
}); });
// id
const deleteFileMetaIds = computed(() => {
return oldLocalFileList.value
.filter((item: any) => !currentOldLocalFileList.value.includes(item.id))
.map((item: any) => item.id);
});
// ID // ID
const newAssociateFileListIds = computed(() => { const newAssociateFileListIds = computed(() => {
return fileList.value return fileList.value
@ -328,6 +325,33 @@
(id: string) => !currentAlreadyAssociateFileList.value.includes(id) && !deleteAssociateFileIds.includes(id) (id: string) => !currentAlreadyAssociateFileList.value.includes(id) && !deleteAssociateFileIds.includes(id)
); );
}); });
// id
const deleteFileMetaIds = computed(() => {
return oldLocalFileList.value
.filter((item: any) => !currentOldLocalFileList.value.includes(item.id))
.map((item: any) => item.id);
});
//
function getFilesParams() {
form.value.deleteLocalFileIds = deleteFileMetaIds.value;
form.value.unLinkRefIds = unLinkFilesIds.value;
form.value.linkFileIds = newAssociateFileListIds.value;
}
//
watch(
() => fileList.value,
(val) => {
if (val) {
getListFunParams.value.combine.hiddenIds = fileList.value.filter((item) => !item.local).map((item) => item.uid);
getFilesParams();
}
},
{ deep: true }
);
const transferVisible = ref<boolean>(false); const transferVisible = ref<boolean>(false);
// //
function transferFile() { function transferFile() {
@ -460,7 +484,7 @@
// //
function saveSelectAssociatedFile(fileData: AssociatedList[]) { function saveSelectAssociatedFile(fileData: AssociatedList[]) {
const fileResultList = fileData.map((fileInfo) => convertToFile(fileInfo)); const fileResultList = fileData.map((fileInfo) => convertToFileByBug(fileInfo));
fileList.value.push(...fileResultList); fileList.value.push(...fileResultList);
} }
@ -532,31 +556,32 @@
}); });
scrollIntoView(document.querySelector('.arco-form-item-message'), { block: 'center' }); scrollIntoView(document.querySelector('.arco-form-item-message'), { block: 'center' });
}; };
//
const getDetailInfo = async () => { const getDetailInfo = async () => {
const id = route.query.id as string; const id = route.query.id as string;
if (!id) return; if (!id) return;
const res = await getBugDetail(id); const res = await getBugDetail(id);
const { customFields, templateId, attachments } = res; const { customFields, templateId, attachments } = res;
// ID
await templateChange(templateId);
if (attachments && attachments.length) { if (attachments && attachments.length) {
attachmentsList.value = attachments; attachmentsList.value = attachments;
// //
const checkUpdateFileIds = await checkFileIsUpdateRequest(attachments.value.map((item: any) => item.id)); const checkUpdateFileIds = await checkFileIsUpdateRequest(attachments.map((item: any) => item.fileId));
// //
fileList.value = attachments fileList.value = attachments
.map((fileInfo: any) => { .map((fileInfo: any) => {
return { return {
...fileInfo, ...fileInfo,
name: fileInfo.fileName, name: fileInfo.fileName,
isUpdateFlag: checkUpdateFileIds.value.includes(fileInfo.id), isUpdateFlag: checkUpdateFileIds.includes(fileInfo.id),
}; };
}) })
.map((fileInfo: any) => { .map((fileInfo: any) => {
return convertToFile(fileInfo); return convertToFileByBug(fileInfo);
}); });
} }
// ID
await templateChange(templateId);
const tmpObj = {}; const tmpObj = {};
if (customFields && Array.isArray(customFields)) { if (customFields && Array.isArray(customFields)) {
customFields.forEach((item) => { customFields.forEach((item) => {
@ -576,17 +601,10 @@
}; };
}; };
const initDefaultFields = () => { const initDefaultFields = async () => {
getTemplateOptions(); await getTemplateOptions();
}; };
//
function getFilesParams() {
form.value.deleteFileMetaIds = deleteFileMetaIds.value;
form.value.unLinkFilesIds = unLinkFilesIds.value;
form.value.relateFileMetaIds = newAssociateFileListIds.value;
}
// //
watch( watch(
() => fileList.value, () => fileList.value,
@ -601,16 +619,18 @@
{ deep: true } { deep: true }
); );
onBeforeMount(() => { async function handleUploadImage(file: File) {
const { mode } = route.params; const { data } = await editorUploadFile({
if (mode === 'edit') { fileList: [file],
});
return data;
}
onMounted(async () => {
await initDefaultFields();
if (isEditOrCopy.value) {
// //
getDetailInfo(); await getDetailInfo();
} else if (mode === 'copy') {
getDetailInfo();
initDefaultFields();
} else {
initDefaultFields();
} }
}); });
</script> </script>

View File

@ -0,0 +1,35 @@
/** *
*
* @description
* @param {stafileInfotus} file
*/
import { MsFileItem } from '@/components/pure/ms-upload/types';
import { AssociatedList } from '@/models/caseManagement/featureCase';
export function convertToFileByBug(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.fileSize });
const { fileId, associated, isUpdateFlag, refId } = fileInfo;
return {
enable: fileInfo.enable || false,
file,
name: fileName,
percent: 0,
status: 'done',
uid: fileId,
url: `${gatewayAddress}/${fileInfo.filePath || ''}`,
local: !associated,
deleteContent: associated ? 'caseManagement.featureCase.cancelLink' : '',
isUpdateFlag,
associateId: refId,
};
}
export default {};