feat(缺陷管理): 优化附件关联逻辑

This commit is contained in:
rubyliu 2024-02-16 23:16:13 +08:00 committed by Craftsman
parent 8f7f3b2b08
commit 81e6bb00d0
4 changed files with 43 additions and 114 deletions

View File

@ -1,9 +1,9 @@
{
"typescript.tsdk": "/frontend/node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"eslint.autoFixOnSave": true,
"source.fixAll.stylelint": true, // stylelint
"source.fixAll.eslint": true, // eslint
"eslint.autoFixOnSave": "explicit",
"source.fixAll.stylelint": "explicit",
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"eslint.validate": [

View File

@ -245,8 +245,7 @@
</template>
<script lang="ts" setup>
import { computed, nextTick, onMounted, ref, useAttrs, watch } from 'vue';
import { useVModel } from '@vueuse/core';
import { computed, defineModel, nextTick, onMounted, ref, useAttrs, watch } from 'vue';
import MsIcon from '@/components/pure/ms-icon-font/index.vue';
import MsPagination from '@/components/pure/ms-pagination/index';

View File

@ -220,8 +220,10 @@
//
const contentEditAble = ref(false);
const currentProjectId = computed(() => appStore.currentProjectId);
// fileList
const fileList = ref<MsFileItem[]>([]);
const bugId = computed(() => props.detailInfo.id);
// list
const attachmentsList = ref<AttachFileInfo[]>([]);
const getListFunParams = ref<TableQueryParams>({
combine: {
@ -339,60 +341,24 @@
associatedDrawer.value = true;
}
// localitem
const oldLocalFileList = computed(() => {
return attachmentsList.value.filter((item) => item.local).map((item: any) => item.uid);
});
// id
const associateFileIds = computed(() => {
return attachmentsList.value.filter((item: any) => !item.local).map((item: any) => item.id);
});
// list
const currentAlreadyAssociateFileList = computed(() => {
return fileList.value
.filter((item) => !item.local && !associateFileIds.value.includes(item.uid))
.map((item: any) => item.uid);
});
// item
const currentOldLocalFileList = computed(() => {
return fileList.value.filter((item) => item.local && item.status !== 'init').map((item: any) => item.uid);
});
// ID
const newAssociateFileListIds = computed(() => {
return fileList.value
.filter((item: any) => !item.local && !associateFileIds.value.includes(item.uid))
.map((item: any) => item.uid);
});
// id TODO
const unLinkFilesIds = computed(() => {
const deleteAssociateFileIds = fileList.value
.filter(
(item: any) =>
!currentAlreadyAssociateFileList.value.includes(item.uid) && associateFileIds.value.includes(item.uid)
)
.map((item) => item.uid);
return associateFileIds.value.filter(
(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;
const associateFileIds = attachmentsList.value.filter((item) => !item.local).map((item) => item.id);
const newAssociateFileListIds = fileList.value
.filter((item) => !item.local && !associateFileIds.includes(item.uid))
.map((item) => item.uid);
const currentOldLocalFileList = fileList.value
.filter((item) => item.local && item.status !== 'init')
.map((item) => item.uid);
// form
form.value.deleteLocalFileIds = attachmentsList.value
.filter((item) => item.local && !currentOldLocalFileList.includes(item.uid))
.map((item) => item.uid);
form.value.unLinkRefIds = associateFileIds.filter((id) => !newAssociateFileListIds.includes(id));
form.value.linkFileIds = newAssociateFileListIds;
}
async function startUpload() {

View File

@ -263,7 +263,9 @@
});
const formRef = ref();
const formCreateRef = ref();
// ()
const attachmentsList = ref<AttachFileInfo[]>([]);
// ()
const fileList = ref<MsFileItem[]>([]);
const formRules = ref<FormItem[]>([]);
const formItem = ref<FormRuleItem[]>([]);
@ -287,62 +289,24 @@
return isEdit.value ? t('bugManagement.editBug') : t('bugManagement.createBug');
});
const attachmentsList = ref<AttachFileInfo[]>([]);
// id
const associateFileIds = computed(() => {
return attachmentsList.value.filter((item: any) => !item.local).map((item: any) => item.id);
});
// list
const currentAlreadyAssociateFileList = computed(() => {
return fileList.value
.filter((item) => !item.local && !associateFileIds.value.includes(item.uid))
.map((item: any) => item.uid);
});
// item
const currentOldLocalFileList = computed(() => {
return fileList.value.filter((item) => item.local && item.status !== 'init').map((item: any) => item.uid);
});
// localitem
const oldLocalFileList = computed(() => {
return attachmentsList.value.filter((item) => item.local).map((item: any) => item.uid);
});
// ID
const newAssociateFileListIds = computed(() => {
return fileList.value
.filter((item: any) => !item.local && !associateFileIds.value.includes(item.uid))
.map((item: any) => item.uid);
});
// id TODO
const unLinkFilesIds = computed(() => {
const deleteAssociateFileIds = fileList.value
.filter(
(item: any) =>
!currentAlreadyAssociateFileList.value.includes(item.uid) && associateFileIds.value.includes(item.uid)
)
.map((item) => item.uid);
return associateFileIds.value.filter(
(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;
const associateFileIds = attachmentsList.value.filter((item) => !item.local).map((item) => item.id);
const newAssociateFileListIds = fileList.value
.filter((item) => !item.local && !associateFileIds.includes(item.uid))
.map((item) => item.uid);
const currentOldLocalFileList = fileList.value
.filter((item) => item.local && item.status !== 'init')
.map((item) => item.uid);
// form
form.value.deleteLocalFileIds = attachmentsList.value
.filter((item) => item.local && !currentOldLocalFileList.includes(item.uid))
.map((item) => item.uid);
form.value.unLinkRefIds = associateFileIds.filter((id) => !newAssociateFileListIds.includes(id));
form.value.linkFileIds = newAssociateFileListIds;
}
//