feat(接口测试): 下拉单选协议存上次值且分开存

This commit is contained in:
teukkk 2024-07-16 15:06:43 +08:00 committed by 刘瑞斌
parent 5bd094d3a8
commit 72542e9cc7
7 changed files with 58 additions and 26 deletions

View File

@ -345,7 +345,11 @@ export enum ReportExecStatus {
} }
export enum ProtocolKeyEnum { export enum ProtocolKeyEnum {
API_PROTOCOL = 'API_PROTOCOL', API_MODULE_TREE_PROTOCOL = 'API_MODULE_TREE_PROTOCOL',
TEST_PLAN_API_CASE_PROTOCOL = 'TEST_PLAN_API_CASE_PROTOCOL', TEST_PLAN_API_CASE_PROTOCOL = 'TEST_PLAN_API_CASE_PROTOCOL',
ASSOCIATE_CASE_PROTOCOL = 'ASSOCIATE_CASE_PROTOCOL', ASSOCIATE_CASE_PROTOCOL = 'ASSOCIATE_CASE_PROTOCOL',
API_SCENARIO_IMPORT_PROTOCOL = 'API_SCENARIO_IMPORT_PROTOCOL',
API_SCENARIO_CUSTOM_PROTOCOL = 'API_SCENARIO_CUSTOM_PROTOCOL',
API_NEW_PROTOCOL = 'API_NEW_PROTOCOL',
API_DEBUG_NEW_PROTOCOL = 'API_DEBUG_NEW_PROTOCOL',
} }

View File

@ -479,6 +479,7 @@
import { AddApiCaseParams } from '@/models/apiTest/management'; import { AddApiCaseParams } from '@/models/apiTest/management';
import { ModuleTreeNode, TransferFileParams } from '@/models/common'; import { ModuleTreeNode, TransferFileParams } from '@/models/common';
import { import {
ProtocolKeyEnum,
RequestAuthType, RequestAuthType,
RequestBodyFormat, RequestBodyFormat,
RequestCaseStatus, RequestCaseStatus,
@ -536,6 +537,7 @@
const props = defineProps<{ const props = defineProps<{
request: RequestParam; // request: RequestParam; //
protocolKey?: ProtocolKeyEnum; //
moduleTree?: ModuleTreeNode[]; // moduleTree?: ModuleTreeNode[]; //
isCase?: boolean; // ,, isCase?: boolean; // ,,
apiDetail?: RequestParam; // apiDetail?: RequestParam; //
@ -868,7 +870,9 @@
requestVModel.value.method = RequestMethods.GET; requestVModel.value.method = RequestMethods.GET;
} }
} }
localStorage.setItem('currentProtocol', requestVModel.value.protocol); if (props.protocolKey) {
localStorage.setItem(props.protocolKey, requestVModel.value.protocol);
}
handleActiveDebugChange(); handleActiveDebugChange();
} }

View File

@ -40,6 +40,7 @@
v-model:detail-loading="loading" v-model:detail-loading="loading"
v-model:request="activeDebug" v-model:request="activeDebug"
:module-tree="folderTree" :module-tree="folderTree"
:protocol-key="ProtocolKeyEnum.API_DEBUG_NEW_PROTOCOL"
:create-api="addDebug" :create-api="addDebug"
:update-api="updateDebug" :update-api="updateDebug"
:execute-api="executeDebug" :execute-api="executeDebug"
@ -131,6 +132,7 @@
import { ModuleTreeNode } from '@/models/common'; import { ModuleTreeNode } from '@/models/common';
import { import {
ProtocolKeyEnum,
RequestAuthType, RequestAuthType,
RequestComposition, RequestComposition,
RequestContentTypeEnum, RequestContentTypeEnum,
@ -158,7 +160,7 @@
} }
const initDefaultId = `debug-${Date.now()}`; const initDefaultId = `debug-${Date.now()}`;
const localProtocol = localStorage.getItem('currentProtocol'); const localProtocol = localStorage.getItem(ProtocolKeyEnum.API_DEBUG_NEW_PROTOCOL);
const defaultDebugParams: RequestParam = { const defaultDebugParams: RequestParam = {
type: 'api', type: 'api',
id: initDefaultId, id: initDefaultId,
@ -233,7 +235,7 @@
function addDebugTab(defaultProps?: Partial<TabItem>) { function addDebugTab(defaultProps?: Partial<TabItem>) {
const id = `debug-${Date.now()}`; const id = `debug-${Date.now()}`;
const protocol = localStorage.getItem('currentProtocol'); const protocol = localStorage.getItem(ProtocolKeyEnum.API_DEBUG_NEW_PROTOCOL);
debugTabs.value.push({ debugTabs.value.push({
...cloneDeep(defaultDebugParams), ...cloneDeep(defaultDebugParams),
id, id,

View File

@ -71,6 +71,7 @@
ref="requestCompositionRef" ref="requestCompositionRef"
v-model:detail-loading="loading" v-model:detail-loading="loading"
v-model:request="activeApiTab" v-model:request="activeApiTab"
:protocol-key="ProtocolKeyEnum.API_NEW_PROTOCOL"
:module-tree="props.moduleTree" :module-tree="props.moduleTree"
:create-api="addDefinition" :create-api="addDefinition"
:update-api="updateDefinition" :update-api="updateDefinition"
@ -157,6 +158,7 @@
import { MockDetail } from '@/models/apiTest/mock'; import { MockDetail } from '@/models/apiTest/mock';
import { ModuleTreeNode } from '@/models/common'; import { ModuleTreeNode } from '@/models/common';
import { import {
ProtocolKeyEnum,
RequestAuthType, RequestAuthType,
RequestBodyFormat, RequestBodyFormat,
RequestComposition, RequestComposition,
@ -226,7 +228,7 @@
}); });
const initDefaultId = `definition-${Date.now()}`; const initDefaultId = `definition-${Date.now()}`;
const localProtocol = localStorage.getItem('currentProtocol'); const localProtocol = localStorage.getItem(ProtocolKeyEnum.API_NEW_PROTOCOL);
const defaultDefinitionParams: RequestParam = { const defaultDefinitionParams: RequestParam = {
type: 'api', type: 'api',
definitionActiveKey: 'definition', definitionActiveKey: 'definition',
@ -300,7 +302,7 @@
function addApiTab(defaultProps?: Partial<TabItem>) { function addApiTab(defaultProps?: Partial<TabItem>) {
const id = `definition-${Date.now()}`; const id = `definition-${Date.now()}`;
const protocol = localStorage.getItem('currentProtocol'); const protocol = localStorage.getItem(ProtocolKeyEnum.API_NEW_PROTOCOL);
apiTabs.value.push({ apiTabs.value.push({
...cloneDeep(defaultDefinitionParams), ...cloneDeep(defaultDefinitionParams),
moduleId: props.activeModule === 'all' ? 'root' : props.activeModule, moduleId: props.activeModule === 'all' ? 'root' : props.activeModule,

View File

@ -48,7 +48,7 @@
ref="treeFolderAllRef" ref="treeFolderAllRef"
v-model:isExpandApi="isExpandApi" v-model:isExpandApi="isExpandApi"
v-model:isExpandAll="isExpandAll" v-model:isExpandAll="isExpandAll"
:protocol-key="ProtocolKeyEnum.API_PROTOCOL" :protocol-key="ProtocolKeyEnum.API_MODULE_TREE_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"

View File

@ -110,7 +110,6 @@
:loading="protocolLoading" :loading="protocolLoading"
:disabled="_stepType.isQuoteApi || props.step?.isQuoteScenarioStep" :disabled="_stepType.isQuoteApi || props.step?.isQuoteScenarioStep"
class="w-[90px]" class="w-[90px]"
@change="(val) => handleActiveDebugProtocolChange(val as string)"
> >
<a-tooltip <a-tooltip
v-for="item of protocolOptions" v-for="item of protocolOptions"
@ -370,6 +369,7 @@
import { useAppStore } from '@/store'; import { useAppStore } from '@/store';
import { getGenerateId, parseQueryParams } from '@/utils'; import { getGenerateId, parseQueryParams } from '@/utils';
import { scrollIntoView } from '@/utils/dom'; import { scrollIntoView } from '@/utils/dom';
import { getLocalStorage, setLocalStorage } from '@/utils/local-storage';
import { import {
EnableKeyValueParam, EnableKeyValueParam,
@ -385,6 +385,7 @@
import { ScenarioStepFileParams, ScenarioStepItem } from '@/models/apiTest/scenario'; import { ScenarioStepFileParams, ScenarioStepItem } from '@/models/apiTest/scenario';
import type { EnvConfig } from '@/models/projectManagement/environmental'; import type { EnvConfig } from '@/models/projectManagement/environmental';
import { import {
ProtocolKeyEnum,
RequestAuthType, RequestAuthType,
RequestBodyFormat, RequestBodyFormat,
RequestComposition, RequestComposition,
@ -1272,6 +1273,16 @@
} }
); );
watch(
() => requestVModel.value.protocol,
(val) => {
if (requestVModel.value.isNew) {
setLocalStorage(ProtocolKeyEnum.API_SCENARIO_CUSTOM_PROTOCOL, val);
}
handleActiveDebugProtocolChange(val);
}
);
watch( watch(
() => visible.value, () => visible.value,
async (val) => { async (val) => {
@ -1304,11 +1315,16 @@
handleActiveDebugProtocolChange(requestVModel.value.protocol); handleActiveDebugProtocolChange(requestVModel.value.protocol);
} else { } else {
// //
const localProtocol = getLocalStorage<string>(ProtocolKeyEnum.API_SCENARIO_CUSTOM_PROTOCOL);
const id = getGenerateId(); const id = getGenerateId();
requestVModel.value = cloneDeep({ requestVModel.value = cloneDeep({
...defaultApiParams, ...defaultApiParams,
stepId: id, stepId: id,
uniqueId: id, uniqueId: id,
protocol:
localProtocol?.length && protocolOptions.value.some((item) => item.value === localProtocol)
? localProtocol
: 'HTTP',
}); });
} }
requestVModel.value.activeTab = contentTabList.value[0].value; requestVModel.value.activeTab = contentTabList.value[0].value;

View File

@ -18,12 +18,7 @@
<div class="flex flex-col"> <div class="flex flex-col">
<div class="mb-[12px] flex items-center gap-[8px]"> <div class="mb-[12px] flex items-center gap-[8px]">
<MsProjectSelect v-model:project="currentProject" @change="resetModule" /> <MsProjectSelect v-model:project="currentProject" @change="resetModule" />
<a-select <a-select v-if="activeKey !== 'scenario'" v-model:model-value="protocol" class="w-[90px]">
v-if="activeKey !== 'scenario'"
v-model:model-value="protocol"
class="w-[90px]"
@change="resetModule"
>
<a-tooltip <a-tooltip
v-for="item of protocolOptions" v-for="item of protocolOptions"
:key="item.value as string" :key="item.value as string"
@ -123,10 +118,11 @@
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useAppStore from '@/store/modules/app'; import useAppStore from '@/store/modules/app';
import { getGenerateId, mapTree } from '@/utils'; import { getGenerateId, mapTree } from '@/utils';
import { getLocalStorage, setLocalStorage } from '@/utils/local-storage';
import type { ApiCaseDetail, ApiDefinitionDetail } from '@/models/apiTest/management'; import type { ApiCaseDetail, ApiDefinitionDetail } from '@/models/apiTest/management';
import type { ApiScenarioTableItem } from '@/models/apiTest/scenario'; import type { ApiScenarioTableItem } from '@/models/apiTest/scenario';
import { ScenarioStepRefType, ScenarioStepType } from '@/enums/apiEnum'; import { ProtocolKeyEnum, ScenarioStepRefType, ScenarioStepType } from '@/enums/apiEnum';
export interface ImportData { export interface ImportData {
api: MsTableDataItem<ApiDefinitionDetail>[]; api: MsTableDataItem<ApiDefinitionDetail>[];
@ -178,7 +174,7 @@
const activeModule = ref<MsTreeNodeData>({}); const activeModule = ref<MsTreeNodeData>({});
const currentProject = ref(appStore.currentProjectId); const currentProject = ref(appStore.currentProjectId);
const protocol = ref('HTTP'); const protocol = ref('');
const protocolOptions = ref<SelectOptionData[]>([]); const protocolOptions = ref<SelectOptionData[]>([]);
const protocolLoading = ref(false); const protocolLoading = ref(false);
@ -204,6 +200,16 @@
const apiTableRef = ref<InstanceType<typeof apiTable>>(); const apiTableRef = ref<InstanceType<typeof apiTable>>();
const moduleIds = ref<(string | number)[]>([]); const moduleIds = ref<(string | number)[]>([]);
watch(
() => protocol.value,
(val) => {
setLocalStorage(ProtocolKeyEnum.API_SCENARIO_IMPORT_PROTOCOL, val);
nextTick(() => {
moduleTreeRef.value?.init(activeKey.value);
});
}
);
function resetModule() { function resetModule() {
nextTick(() => { nextTick(() => {
moduleTreeRef.value?.init(activeKey.value); moduleTreeRef.value?.init(activeKey.value);
@ -398,16 +404,14 @@
} }
} }
onBeforeMount(() => { onBeforeMount(async () => {
initProtocolList(); await initProtocolList();
}); const localProtocol = getLocalStorage<string>(ProtocolKeyEnum.API_SCENARIO_IMPORT_PROTOCOL);
if (localProtocol?.length && protocolOptions.value.some((item) => item.value === localProtocol)) {
// 使 v-if protocol.value = localProtocol;
onMounted(() => { } else {
nextTick(() => { protocol.value = 'HTTP';
// 使 v-if nextTick ref }
moduleTreeRef.value?.init(activeKey.value);
});
}); });
</script> </script>