fix(接口测试&测试计划): 下拉多选协议改成不共用&初始化数据有问题

This commit is contained in:
teukkk 2024-07-15 16:52:29 +08:00 committed by 刘瑞斌
parent 9aad009052
commit 8b04d9cb9a
5 changed files with 33 additions and 13 deletions

View File

@ -1,6 +1,7 @@
<template>
<TreeFolderAll
v-model:selectedProtocols="selectedProtocols"
ref="treeFolderAllRef"
:protocol-key="ProtocolKeyEnum.ASSOCIATE_CASE_PROTOCOL"
:active-folder="activeFolder"
:folder-name="props.folderName"
:all-count="allCount"
@ -88,6 +89,7 @@
import { mapTree } from '@/utils';
import { ModuleTreeNode } from '@/models/common';
import { ProtocolKeyEnum } from '@/enums/apiEnum';
import { CaseModulesApiTypeEnum } from '@/enums/associateCaseEnum';
import { CaseLinkEnum } from '@/enums/caseEnum';
@ -158,7 +160,8 @@
emit('folderNodeSelect', _selectedKeys as string[], offspringIds, node.name);
}
const selectedProtocols = ref<string[]>([]);
const treeFolderAllRef = ref<InstanceType<typeof TreeFolderAll>>();
const selectedProtocols = computed<string[]>(() => treeFolderAllRef.value?.selectedProtocols ?? []);
// count
function processTreeData(nodes: MsTreeNodeData[]): MsTreeNodeData[] {
const traverse = (node: MsTreeNodeData): number => {

View File

@ -343,3 +343,9 @@ export enum ReportExecStatus {
STOPPED = 'STOPPED',
COMPLETED = 'COMPLETED',
}
export enum ProtocolKeyEnum {
API_PROTOCOL = 'API_PROTOCOL',
TEST_PLAN_API_CASE_PROTOCOL = 'TEST_PLAN_API_CASE_PROTOCOL',
ASSOCIATE_CASE_PROTOCOL = 'ASSOCIATE_CASE_PROTOCOL',
}

View File

@ -63,12 +63,15 @@
import useAppStore from '@/store/modules/app';
import { getLocalStorage, setLocalStorage } from '@/utils/local-storage';
import { ProtocolKeyEnum } from '@/enums/apiEnum';
const props = defineProps<{
activeFolder?: string; //
folderName: string; //
allCount: number; //
showExpandApi?: boolean; //
notShowOperation?: boolean; //
protocolKey: ProtocolKeyEnum;
}>();
const emit = defineEmits<{
(e: 'setActiveFolder', val: string): void;
@ -84,9 +87,7 @@
required: false,
default: undefined,
});
const selectedProtocols = defineModel<string[]>('selectedProtocols', {
required: true,
});
const selectedProtocols = ref<string[]>([]);
const { t } = useI18n();
const appStore = useAppStore();
@ -123,7 +124,7 @@
function changeApiExpand() {
isExpandApi.value = !isExpandApi.value;
nextTick(() => {
setLocalStorage('isExpandApi', isExpandApi.value);
setLocalStorage(`${props.protocolKey}_EXPAND_API`, isExpandApi.value);
emit('changeApiExpand');
});
}
@ -131,7 +132,7 @@
watch(
() => selectedProtocols.value,
(val) => {
setLocalStorage('selectedProtocols', val);
setLocalStorage(props.protocolKey, val);
emit('selectedProtocolsChange');
}
);
@ -149,14 +150,18 @@
onBeforeMount(async () => {
await initProtocolList();
isExpandApi.value = getLocalStorage('isExpandApi') === 'true';
const protocols = getLocalStorage<string[]>('selectedProtocols');
isExpandApi.value = getLocalStorage(`${props.protocolKey}_EXPAND_API`) === 'true';
const protocols = getLocalStorage<string[]>(props.protocolKey);
if (!protocols) {
selectedProtocols.value = allProtocolList.value;
} else {
selectedProtocols.value = allProtocolList.value.filter((item) => protocols.includes(item as string));
}
});
defineExpose({
selectedProtocols,
});
</script>
<style lang="less" scoped>

View File

@ -45,9 +45,10 @@
</div>
<TreeFolderAll
v-if="!props.readOnly"
ref="treeFolderAllRef"
v-model:isExpandApi="isExpandApi"
v-model:isExpandAll="isExpandAll"
v-model:selectedProtocols="selectedProtocols"
:protocol-key="ProtocolKeyEnum.API_PROTOCOL"
:folder-name="t('apiTestManagement.allApi')"
:all-count="allFileCount"
:active-folder="selectedKeys[0] as string"
@ -197,6 +198,7 @@
import { ApiDefinitionGetModuleParams } from '@/models/apiTest/management';
import { ModuleTreeNode } from '@/models/common';
import { ProtocolKeyEnum } from '@/enums/apiEnum';
const props = withDefaults(
defineProps<{
@ -231,7 +233,8 @@
const { openModal } = useModal();
const { copy, isSupported } = useClipboard({ legacy: true });
const selectedProtocols = ref<string[]>([]);
const treeFolderAllRef = ref<InstanceType<typeof TreeFolderAll>>();
const selectedProtocols = computed<string[]>(() => treeFolderAllRef.value?.selectedProtocols ?? []);
const moduleProtocolOptions = ref<SelectOptionData[]>([]);
const protocolLoading = ref(false);

View File

@ -12,8 +12,9 @@
:max-length="255"
/>
<TreeFolderAll
ref="treeFolderAllRef"
v-model:isExpandAll="isExpandAll"
v-model:selectedProtocols="selectedProtocols"
:protocol-key="ProtocolKeyEnum.TEST_PLAN_API_CASE_PROTOCOL"
:active-folder="activeFolder"
:folder-name="t('testPlan.testPlanIndex.apiCase')"
:all-count="allCount"
@ -67,6 +68,7 @@
import { getNodeParentId } from '@/utils/tree';
import { ModuleTreeNode } from '@/models/common';
import { ProtocolKeyEnum } from '@/enums/apiEnum';
const props = defineProps<{
modulesCount?: Record<string, number>; //
@ -117,7 +119,8 @@
const folderTree = ref<ModuleTreeNode[]>([]);
const loading = ref(false);
const selectedKeys = useVModel(props, 'selectedKeys', emit);
const selectedProtocols = ref<string[]>([]);
const treeFolderAllRef = ref<InstanceType<typeof TreeFolderAll>>();
const selectedProtocols = computed<string[]>(() => treeFolderAllRef.value?.selectedProtocols ?? []);
//
async function initModules() {