From 42eb1a827c6b0c21998359252294d0462da76269 Mon Sep 17 00:00:00 2001 From: baiqi Date: Mon, 26 Feb 2024 14:28:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E8=B0=83=E8=AF=95):=20?= =?UTF-8?q?=2099.5%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ms-common-script/insertCommonScript.vue | 5 +- .../business/ms-params-input/index.vue | 2 +- .../src/components/business/ms-tree/index.vue | 3 +- frontend/src/components/pure/ms-tab/index.vue | 58 ++++++++++++++ frontend/src/locale/en-US/common.ts | 1 + frontend/src/locale/zh-CN/common.ts | 1 + .../api-test/components/condition/content.vue | 16 +++- .../src/views/api-test/components/config.ts | 42 ++++++++++ .../views/api-test/components/paramTable.vue | 10 ++- .../components/requestComposition/body.vue | 25 ++---- .../components/requestComposition/header.vue | 16 ++-- .../components/requestComposition/index.vue | 79 +++++++++++++++---- .../components/requestComposition/query.vue | 22 ++---- .../requestComposition/response.vue | 14 +++- .../components/requestComposition/rest.vue | 21 ++--- .../src/views/api-test/components/utils.ts | 35 ++++++++ .../api-test/debug/components/moduleTree.vue | 5 +- 17 files changed, 270 insertions(+), 85 deletions(-) create mode 100644 frontend/src/components/pure/ms-tab/index.vue create mode 100644 frontend/src/views/api-test/components/config.ts diff --git a/frontend/src/components/business/ms-common-script/insertCommonScript.vue b/frontend/src/components/business/ms-common-script/insertCommonScript.vue index 060bc1a04f..c8f2b460df 100644 --- a/frontend/src/components/business/ms-common-script/insertCommonScript.vue +++ b/frontend/src/components/business/ms-common-script/insertCommonScript.vue @@ -3,7 +3,7 @@ v-model:visible="insertScriptDrawer" :title=" props.enableRadioSelected - ? t('project.commonScript.insertCommonScript') + ? t('project.commonScript.quoteCommonScript') : t('project.commonScript.insertCommonScript') " :width="960" @@ -16,8 +16,7 @@ @cancel="handleDrawerCancel" >
-
{{ t('project.commonScript.commonScriptList') }}
- + {{ t('project.commonScript.addPublicScript') }}
{{ t('ms.paramsInput.preview') }}
diff --git a/frontend/src/components/business/ms-tree/index.vue b/frontend/src/components/business/ms-tree/index.vue index 25b1771385..19f809a28a 100644 --- a/frontend/src/components/business/ms-tree/index.vue +++ b/frontend/src/components/business/ms-tree/index.vue @@ -29,7 +29,7 @@ v-if="_props.hideMoreAction !== true" :class="[ 'ms-tree-node-extra', - innerFocusNodeKey === _props[props.fieldNames.key] ? 'ms-tree-node-extra--focus' : '', + innerFocusNodeKey === _props[props.fieldNames.key] ? 'ms-tree-node-extra--focus' : '', // TODO:通过下拉菜单的显示隐藏去控制聚焦状态似乎能有更好的性能 ]" >
+ + + + + + + + + + diff --git a/frontend/src/locale/en-US/common.ts b/frontend/src/locale/en-US/common.ts index 878e961cef..6bbf8e73e9 100644 --- a/frontend/src/locale/en-US/common.ts +++ b/frontend/src/locale/en-US/common.ts @@ -118,4 +118,5 @@ export default { 'common.to': 'To', 'common.tip': 'Tips', 'common.stay': 'Stay', + 'common.apply': 'Apply', }; diff --git a/frontend/src/locale/zh-CN/common.ts b/frontend/src/locale/zh-CN/common.ts index 16ac5c0fbb..811dcf2e61 100644 --- a/frontend/src/locale/zh-CN/common.ts +++ b/frontend/src/locale/zh-CN/common.ts @@ -121,4 +121,5 @@ export default { 'common.to': '至', 'common.tip': '温馨提示', 'common.stay': '留下', + 'common.apply': '应用', }; diff --git a/frontend/src/views/api-test/components/condition/content.vue b/frontend/src/views/api-test/components/condition/content.vue index c3a30be70b..53235fe12c 100644 --- a/frontend/src/views/api-test/components/condition/content.vue +++ b/frontend/src/views/api-test/components/condition/content.vue @@ -99,7 +99,7 @@
- {{ condition.scriptName || '-' }} + {{ condition.commonScriptInfo?.name || '-' }}
@@ -320,6 +320,14 @@ :checked-id="condition.scriptId" enable-radio-selected @save="saveQuoteScriptHandler" + @add-script="showAddScriptDrawer = true" + /> + @@ -336,6 +344,7 @@ import useTable from '@/components/pure/ms-table/useTable'; import { ActionsItem } from '@/components/pure/ms-table-more-action/types'; import InsertCommonScript from '@/components/business/ms-common-script/insertCommonScript.vue'; + import AddScriptDrawer from '@/components/business/ms-common-script/ms-addScriptDrawer.vue'; import MsScriptDefined from '@/components/business/ms-common-script/scriptDefined.vue'; import fastExtraction from '../fastExtraction/index.vue'; import moreSetting from '../fastExtraction/moreSetting.vue'; @@ -345,6 +354,7 @@ import { useI18n } from '@/hooks/useI18n'; import { ExecuteConditionProcessor, JSONPathExtract, RegexExtract, XPathExtract } from '@/models/apiTest/debug'; + import { ParamsRequestType } from '@/models/projectManagement/commonScript'; import { RequestConditionProcessor, RequestExtractEnvType, @@ -478,6 +488,10 @@ if (!result){ showQuoteDrawer.value = false; } + const showAddScriptDrawer = ref(false); + const paramsList = ref([]); + const confirmLoading = ref(false); + const sqlSourceColumns: ParamTableColumn[] = [ { title: 'apiTestDebug.paramName', diff --git a/frontend/src/views/api-test/components/config.ts b/frontend/src/views/api-test/components/config.ts new file mode 100644 index 0000000000..96a9960fa5 --- /dev/null +++ b/frontend/src/views/api-test/components/config.ts @@ -0,0 +1,42 @@ +import { + EnableKeyValueParam, + ExecuteRequestCommonParam, + ExecuteRequestFormBodyFormValue, +} from '@/models/apiTest/debug'; +import { RequestContentTypeEnum, RequestParamsType } from '@/enums/apiEnum'; + +// 请求 body 参数表格默认行的值 +export const defaultBodyParamsItem: ExecuteRequestFormBodyFormValue = { + key: '', + value: '', + paramType: RequestParamsType.STRING, + description: '', + required: false, + maxLength: undefined, + minLength: undefined, + encode: false, + enable: true, + contentType: RequestContentTypeEnum.TEXT, + files: [], +}; + +// 请求 header 参数表格默认行的值 +export const defaultHeaderParamsItem: EnableKeyValueParam = { + key: '', + value: '', + description: '', + enable: true, +}; + +// 请求 query、rest 参数表格默认行的值 +export const defaultRequestParamsItem: ExecuteRequestCommonParam = { + key: '', + value: '', + paramType: RequestParamsType.STRING, + description: '', + required: false, + maxLength: undefined, + minLength: undefined, + encode: false, + enable: true, +}; diff --git a/frontend/src/views/api-test/components/paramTable.vue b/frontend/src/views/api-test/components/paramTable.vue index 893c783ca3..45ec6d0208 100644 --- a/frontend/src/views/api-test/components/paramTable.vue +++ b/frontend/src/views/api-test/components/paramTable.vue @@ -404,6 +404,7 @@ import { RequestBodyFormat, RequestContentTypeEnum, RequestParamsType } from '@/enums/apiEnum'; import { SelectAllEnum, TableKeyEnum } from '@/enums/tableEnum'; + import { filterKeyValParams } from './utils'; import { TableOperationColumn } from '@arco-design/web-vue/es/table/interface'; // 异步加载组件 const MsAddAttachment = defineAsyncComponent(() => import('@/components/business/ms-add-attachment/index.vue')); @@ -627,9 +628,12 @@ watch( () => props.params, - (val) => { - if (val.length > 0) { - propsRes.value.data = val; + (arr) => { + if (arr.length > 0) { + propsRes.value.data = arr; + if (!filterKeyValParams(arr, props.defaultParamItem).lastDataIsDefault) { + addTableLine(arr.length - 1); + } } else { const id = new Date().getTime().toString(); propsRes.value.data = [ diff --git a/frontend/src/views/api-test/components/requestComposition/body.vue b/frontend/src/views/api-test/components/requestComposition/body.vue index a1ca8c60f0..8d7b3aa70f 100644 --- a/frontend/src/views/api-test/components/requestComposition/body.vue +++ b/frontend/src/views/api-test/components/requestComposition/body.vue @@ -13,7 +13,7 @@
@@ -31,7 +31,7 @@ :height-used="heightUsed" :show-setting="true" :table-key="TableKeyEnum.API_TEST_DEBUG_FORM_DATA" - :default-param-item="defaultParamItem" + :default-param-item="defaultBodyParamsItem" :upload-temp-file-api="props.uploadTempFileApi" @change="handleParamTableChange" /> @@ -43,7 +43,7 @@ :height-used="heightUsed" :show-setting="true" :table-key="TableKeyEnum.API_TEST_DEBUG_FORM_URL_ENCODE" - :default-param-item="defaultParamItem" + :default-param-item="defaultBodyParamsItem" @change="handleParamTableChange" />
@@ -116,10 +116,12 @@ import { useI18n } from '@/hooks/useI18n'; import useAppStore from '@/store/modules/app'; - import { ExecuteBody, ExecuteRequestFormBodyFormValue } from '@/models/apiTest/debug'; - import { RequestBodyFormat, RequestContentTypeEnum, RequestParamsType } from '@/enums/apiEnum'; + import { ExecuteBody } from '@/models/apiTest/debug'; + import { RequestBodyFormat, RequestParamsType } from '@/enums/apiEnum'; import { TableKeyEnum } from '@/enums/tableEnum'; + import { defaultBodyParamsItem } from '@/views/api-test/components/config'; + const props = defineProps<{ params: ExecuteBody; layout: 'horizontal' | 'vertical'; @@ -135,19 +137,6 @@ const { t } = useI18n(); const innerParams = useVModel(props, 'params', emit); - const defaultParamItem: ExecuteRequestFormBodyFormValue = { - key: '', - value: '', - paramType: RequestParamsType.STRING, - description: '', - required: false, - maxLength: undefined, - minLength: undefined, - encode: false, - enable: true, - contentType: RequestContentTypeEnum.TEXT, - files: [], - }; const fileList = ref( innerParams.value.binaryBody && innerParams.value.binaryBody.file ? [innerParams.value.binaryBody.file] : [] ); diff --git a/frontend/src/views/api-test/components/requestComposition/header.vue b/frontend/src/views/api-test/components/requestComposition/header.vue index f05076ff61..46f0ad478a 100644 --- a/frontend/src/views/api-test/components/requestComposition/header.vue +++ b/frontend/src/views/api-test/components/requestComposition/header.vue @@ -1,14 +1,18 @@
{{ t('apiTestDebug.responseContent') }}
(), { activeLayout: 'vertical', - hideLayoutSwicth: false, + hideLayoutSwitch: false, } ); const emit = defineEmits<{ @@ -313,7 +317,9 @@ case ResponseComposition.HEADER: return props.response.requestResults[0].responseResult.headers.trim(); case ResponseComposition.REAL_REQUEST: - return props.response.requestResults[0].body.trim(); + return `${t('apiTestDebug.requestUrl')}:\n${props.request?.url}\n${t('apiTestDebug.header')}:\n${ + props.response.requestResults[0].headers + }\nBody:\n${props.response.requestResults[0].body.trim()}`; case ResponseComposition.CONSOLE: return props.response.console.trim(); // case ResponseComposition.EXTRACT: diff --git a/frontend/src/views/api-test/components/requestComposition/rest.vue b/frontend/src/views/api-test/components/requestComposition/rest.vue index f469ec5816..463942033e 100644 --- a/frontend/src/views/api-test/components/requestComposition/rest.vue +++ b/frontend/src/views/api-test/components/requestComposition/rest.vue @@ -9,14 +9,18 @@ />
- +
@@ -32,6 +36,8 @@ import { ExecuteRequestCommonParam } from '@/models/apiTest/debug'; import { RequestParamsType } from '@/enums/apiEnum'; + import { defaultRequestParamsItem } from '@/views/api-test/components/config'; + const props = defineProps<{ params: ExecuteRequestCommonParam[]; layout: 'horizontal' | 'vertical'; @@ -45,17 +51,6 @@ const { t } = useI18n(); const innerParams = useVModel(props, 'params', emit); - const defaultParamItem = { - key: '', - value: '', - paramType: RequestParamsType.STRING, - description: '', - required: false, - maxLength: undefined, - minLength: undefined, - encode: false, - enable: true, - }; const columns: ParamTableColumn[] = [ { diff --git a/frontend/src/views/api-test/components/utils.ts b/frontend/src/views/api-test/components/utils.ts index 052b9a6b78..c8f0c6db59 100644 --- a/frontend/src/views/api-test/components/utils.ts +++ b/frontend/src/views/api-test/components/utils.ts @@ -1,3 +1,5 @@ +import { cloneDeep } from 'lodash-es'; + import { ExecuteBody } from '@/models/apiTest/debug'; import { RequestParamsType } from '@/enums/apiEnum'; @@ -100,3 +102,36 @@ export function parseRequestBodyFiles( unLinkFileIds: saveLinkFileIds?.filter((id) => !tempSaveLinkFileIds.has(id)) || [], // 存储对比已保存的文件后,需要取消关联的文件 id 集合 }; } + +/** + * 过滤无效参数 + * @param params 原始参数数组 + * @param defaultParamItem 默认参数项 + */ +export function filterKeyValParams(params: Record[], defaultParamItem: Record) { + const lastData = cloneDeep(params[params.length - 1]); + const defaultParam = cloneDeep(defaultParamItem); + if (!lastData || !defaultParam) { + return { + lastDataIsDefault: false, + validParams: params, + }; + } + // id和enable属性不参与比较 + delete lastData.id; + delete lastData.enable; + delete defaultParam.id; + delete defaultParam.enable; + const lastDataIsDefault = JSON.stringify(lastData) === JSON.stringify(defaultParam); + let validParams: Record[] = []; + if (lastDataIsDefault) { + // 如果最后一条数据是默认数据,非用户添加更改的,说明是无效参数,删除最后一个 + validParams = params.slice(0, params.length - 1); + } else { + validParams = params; + } + return { + lastDataIsDefault, + validParams, + }; +} diff --git a/frontend/src/views/api-test/debug/components/moduleTree.vue b/frontend/src/views/api-test/debug/components/moduleTree.vue index ad778727ae..998673501c 100644 --- a/frontend/src/views/api-test/debug/components/moduleTree.vue +++ b/frontend/src/views/api-test/debug/components/moduleTree.vue @@ -412,9 +412,10 @@ } } - function handleRenameFinish(newName: string, id: string) { - initModules(); + async function handleRenameFinish(newName: string, id: string) { emit('renameFinish', newName, id); + await initModules(); + initModuleCount(); } onBeforeMount(async () => {