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

View File

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

View File

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

View File

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