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", "typescript.tsdk": "/frontend/node_modules/typescript/lib",
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"eslint.autoFixOnSave": true, "eslint.autoFixOnSave": "explicit",
"source.fixAll.stylelint": true, // stylelint "source.fixAll.stylelint": "explicit",
"source.fixAll.eslint": true, // eslint "source.fixAll.eslint": "explicit"
}, },
"editor.formatOnSave": true, "editor.formatOnSave": true,
"eslint.validate": [ "eslint.validate": [

View File

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

View File

@ -220,8 +220,10 @@
// //
const contentEditAble = ref(false); const contentEditAble = ref(false);
const currentProjectId = computed(() => appStore.currentProjectId); const currentProjectId = computed(() => appStore.currentProjectId);
// fileList
const fileList = ref<MsFileItem[]>([]); const fileList = ref<MsFileItem[]>([]);
const bugId = computed(() => props.detailInfo.id); const bugId = computed(() => props.detailInfo.id);
// list
const attachmentsList = ref<AttachFileInfo[]>([]); const attachmentsList = ref<AttachFileInfo[]>([]);
const getListFunParams = ref<TableQueryParams>({ const getListFunParams = ref<TableQueryParams>({
combine: { combine: {
@ -339,60 +341,24 @@
associatedDrawer.value = true; 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() { function getFilesParams() {
form.value.deleteLocalFileIds = deleteFileMetaIds.value; const associateFileIds = attachmentsList.value.filter((item) => !item.local).map((item) => item.id);
form.value.unLinkRefIds = unLinkFilesIds.value; const newAssociateFileListIds = fileList.value
form.value.linkFileIds = newAssociateFileListIds.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() { async function startUpload() {

View File

@ -263,7 +263,9 @@
}); });
const formRef = ref(); const formRef = ref();
const formCreateRef = ref(); const formCreateRef = ref();
// ()
const attachmentsList = ref<AttachFileInfo[]>([]);
// ()
const fileList = ref<MsFileItem[]>([]); const fileList = ref<MsFileItem[]>([]);
const formRules = ref<FormItem[]>([]); const formRules = ref<FormItem[]>([]);
const formItem = ref<FormRuleItem[]>([]); const formItem = ref<FormRuleItem[]>([]);
@ -287,62 +289,24 @@
return isEdit.value ? t('bugManagement.editBug') : t('bugManagement.createBug'); 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() { function getFilesParams() {
form.value.deleteLocalFileIds = deleteFileMetaIds.value; const associateFileIds = attachmentsList.value.filter((item) => !item.local).map((item) => item.id);
form.value.unLinkRefIds = unLinkFilesIds.value; const newAssociateFileListIds = fileList.value
form.value.linkFileIds = newAssociateFileListIds.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;
} }
// //