From 72542e9cc711b2149cba7ce48a996b0e3064487b Mon Sep 17 00:00:00 2001 From: teukkk Date: Tue, 16 Jul 2024 15:06:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E5=8D=95=E9=80=89=E5=8D=8F=E8=AE=AE=E5=AD=98?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E5=80=BC=E4=B8=94=E5=88=86=E5=BC=80=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/enums/apiEnum.ts | 6 ++- .../components/requestComposition/index.vue | 6 ++- frontend/src/views/api-test/debug/index.vue | 6 ++- .../components/management/api/index.vue | 6 ++- .../management/components/moduleTree.vue | 2 +- .../components/common/customApiDrawer.vue | 18 ++++++++- .../common/importApiDrawer/index.vue | 40 ++++++++++--------- 7 files changed, 58 insertions(+), 26 deletions(-) diff --git a/frontend/src/enums/apiEnum.ts b/frontend/src/enums/apiEnum.ts index 7728616210..0b03656c07 100644 --- a/frontend/src/enums/apiEnum.ts +++ b/frontend/src/enums/apiEnum.ts @@ -345,7 +345,11 @@ export enum ReportExecStatus { } 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', 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', } diff --git a/frontend/src/views/api-test/components/requestComposition/index.vue b/frontend/src/views/api-test/components/requestComposition/index.vue index dfcfafc46b..5f233e2740 100644 --- a/frontend/src/views/api-test/components/requestComposition/index.vue +++ b/frontend/src/views/api-test/components/requestComposition/index.vue @@ -479,6 +479,7 @@ import { AddApiCaseParams } from '@/models/apiTest/management'; import { ModuleTreeNode, TransferFileParams } from '@/models/common'; import { + ProtocolKeyEnum, RequestAuthType, RequestBodyFormat, RequestCaseStatus, @@ -536,6 +537,7 @@ const props = defineProps<{ request: RequestParam; // 请求参数集合 + protocolKey?: ProtocolKeyEnum; // 用于记住协议下拉值 moduleTree?: ModuleTreeNode[]; // 模块树 isCase?: boolean; // 是否是用例引用的组件,只显示请求参数和响应内容,响应内容默认为空且折叠 apiDetail?: RequestParam; // 用例引用的时候需要接口定义的数据 @@ -868,7 +870,9 @@ requestVModel.value.method = RequestMethods.GET; } } - localStorage.setItem('currentProtocol', requestVModel.value.protocol); + if (props.protocolKey) { + localStorage.setItem(props.protocolKey, requestVModel.value.protocol); + } handleActiveDebugChange(); } diff --git a/frontend/src/views/api-test/debug/index.vue b/frontend/src/views/api-test/debug/index.vue index 7408a68cd8..cf59a299f4 100644 --- a/frontend/src/views/api-test/debug/index.vue +++ b/frontend/src/views/api-test/debug/index.vue @@ -40,6 +40,7 @@ v-model:detail-loading="loading" v-model:request="activeDebug" :module-tree="folderTree" + :protocol-key="ProtocolKeyEnum.API_DEBUG_NEW_PROTOCOL" :create-api="addDebug" :update-api="updateDebug" :execute-api="executeDebug" @@ -131,6 +132,7 @@ import { ModuleTreeNode } from '@/models/common'; import { + ProtocolKeyEnum, RequestAuthType, RequestComposition, RequestContentTypeEnum, @@ -158,7 +160,7 @@ } const initDefaultId = `debug-${Date.now()}`; - const localProtocol = localStorage.getItem('currentProtocol'); + const localProtocol = localStorage.getItem(ProtocolKeyEnum.API_DEBUG_NEW_PROTOCOL); const defaultDebugParams: RequestParam = { type: 'api', id: initDefaultId, @@ -233,7 +235,7 @@ function addDebugTab(defaultProps?: Partial) { const id = `debug-${Date.now()}`; - const protocol = localStorage.getItem('currentProtocol'); + const protocol = localStorage.getItem(ProtocolKeyEnum.API_DEBUG_NEW_PROTOCOL); debugTabs.value.push({ ...cloneDeep(defaultDebugParams), id, diff --git a/frontend/src/views/api-test/management/components/management/api/index.vue b/frontend/src/views/api-test/management/components/management/api/index.vue index 330dc91f11..cd7ae2face 100644 --- a/frontend/src/views/api-test/management/components/management/api/index.vue +++ b/frontend/src/views/api-test/management/components/management/api/index.vue @@ -71,6 +71,7 @@ ref="requestCompositionRef" v-model:detail-loading="loading" v-model:request="activeApiTab" + :protocol-key="ProtocolKeyEnum.API_NEW_PROTOCOL" :module-tree="props.moduleTree" :create-api="addDefinition" :update-api="updateDefinition" @@ -157,6 +158,7 @@ import { MockDetail } from '@/models/apiTest/mock'; import { ModuleTreeNode } from '@/models/common'; import { + ProtocolKeyEnum, RequestAuthType, RequestBodyFormat, RequestComposition, @@ -226,7 +228,7 @@ }); const initDefaultId = `definition-${Date.now()}`; - const localProtocol = localStorage.getItem('currentProtocol'); + const localProtocol = localStorage.getItem(ProtocolKeyEnum.API_NEW_PROTOCOL); const defaultDefinitionParams: RequestParam = { type: 'api', definitionActiveKey: 'definition', @@ -300,7 +302,7 @@ function addApiTab(defaultProps?: Partial) { const id = `definition-${Date.now()}`; - const protocol = localStorage.getItem('currentProtocol'); + const protocol = localStorage.getItem(ProtocolKeyEnum.API_NEW_PROTOCOL); apiTabs.value.push({ ...cloneDeep(defaultDefinitionParams), moduleId: props.activeModule === 'all' ? 'root' : props.activeModule, diff --git a/frontend/src/views/api-test/management/components/moduleTree.vue b/frontend/src/views/api-test/management/components/moduleTree.vue index 38784ca9ec..2f35a949ba 100644 --- a/frontend/src/views/api-test/management/components/moduleTree.vue +++ b/frontend/src/views/api-test/management/components/moduleTree.vue @@ -48,7 +48,7 @@ ref="treeFolderAllRef" v-model:isExpandApi="isExpandApi" v-model:isExpandAll="isExpandAll" - :protocol-key="ProtocolKeyEnum.API_PROTOCOL" + :protocol-key="ProtocolKeyEnum.API_MODULE_TREE_PROTOCOL" :folder-name="t('apiTestManagement.allApi')" :all-count="allFileCount" :active-folder="selectedKeys[0] as string" diff --git a/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue b/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue index 9db392badd..0c1571dead 100644 --- a/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue +++ b/frontend/src/views/api-test/scenario/components/common/customApiDrawer.vue @@ -110,7 +110,6 @@ :loading="protocolLoading" :disabled="_stepType.isQuoteApi || props.step?.isQuoteScenarioStep" class="w-[90px]" - @change="(val) => handleActiveDebugProtocolChange(val as string)" > requestVModel.value.protocol, + (val) => { + if (requestVModel.value.isNew) { + setLocalStorage(ProtocolKeyEnum.API_SCENARIO_CUSTOM_PROTOCOL, val); + } + handleActiveDebugProtocolChange(val); + } + ); + watch( () => visible.value, async (val) => { @@ -1304,11 +1315,16 @@ handleActiveDebugProtocolChange(requestVModel.value.protocol); } else { // 新建自定义请求 + const localProtocol = getLocalStorage(ProtocolKeyEnum.API_SCENARIO_CUSTOM_PROTOCOL); const id = getGenerateId(); requestVModel.value = cloneDeep({ ...defaultApiParams, stepId: id, uniqueId: id, + protocol: + localProtocol?.length && protocolOptions.value.some((item) => item.value === localProtocol) + ? localProtocol + : 'HTTP', }); } requestVModel.value.activeTab = contentTabList.value[0].value; diff --git a/frontend/src/views/api-test/scenario/components/common/importApiDrawer/index.vue b/frontend/src/views/api-test/scenario/components/common/importApiDrawer/index.vue index 60a00d15ee..3b61c70481 100644 --- a/frontend/src/views/api-test/scenario/components/common/importApiDrawer/index.vue +++ b/frontend/src/views/api-test/scenario/components/common/importApiDrawer/index.vue @@ -18,12 +18,7 @@
- + []; @@ -178,7 +174,7 @@ const activeModule = ref({}); const currentProject = ref(appStore.currentProjectId); - const protocol = ref('HTTP'); + const protocol = ref(''); const protocolOptions = ref([]); const protocolLoading = ref(false); @@ -204,6 +200,16 @@ const apiTableRef = ref>(); const moduleIds = ref<(string | number)[]>([]); + watch( + () => protocol.value, + (val) => { + setLocalStorage(ProtocolKeyEnum.API_SCENARIO_IMPORT_PROTOCOL, val); + nextTick(() => { + moduleTreeRef.value?.init(activeKey.value); + }); + } + ); + function resetModule() { nextTick(() => { moduleTreeRef.value?.init(activeKey.value); @@ -398,16 +404,14 @@ } } - onBeforeMount(() => { - initProtocolList(); - }); - - // 外面需要使用 v-if 动态渲染 - onMounted(() => { - nextTick(() => { - // 外面使用 v-if 动态渲染时,需要在 nextTick 中执行初始化数据,因为子组件 ref 引用需要在渲染后才能获取到 - moduleTreeRef.value?.init(activeKey.value); - }); + onBeforeMount(async () => { + await initProtocolList(); + const localProtocol = getLocalStorage(ProtocolKeyEnum.API_SCENARIO_IMPORT_PROTOCOL); + if (localProtocol?.length && protocolOptions.value.some((item) => item.value === localProtocol)) { + protocol.value = localProtocol; + } else { + protocol.value = 'HTTP'; + } });