From a17b78c141d2ca02c2fb7b7c5975940f7b79efa7 Mon Sep 17 00:00:00 2001 From: "xinxin.wu" Date: Fri, 9 Aug 2024 19:00:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3API=E7=94=A8=E4=BE=8B=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=97=A0=E5=B7=AE=E5=BC=82=E6=89=8B=E5=8A=A8=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/management/case/caseTable.vue | 1 + .../management/case/differentDrawer.vue | 177 +++++++++--------- 2 files changed, 94 insertions(+), 84 deletions(-) diff --git a/frontend/src/views/api-test/management/components/management/case/caseTable.vue b/frontend/src/views/api-test/management/components/management/case/caseTable.vue index 3db2eabb71..22208172a5 100644 --- a/frontend/src/views/api-test/management/components/management/case/caseTable.vue +++ b/frontend/src/views/api-test/management/components/management/case/caseTable.vue @@ -316,6 +316,7 @@ @close="closeDifferent" @clear-this-change="handleClearThisChange" @sync="syncParamsHandler" + @load-list="loadCaseListAndResetSelector" /> diff --git a/frontend/src/views/api-test/management/components/management/case/differentDrawer.vue b/frontend/src/views/api-test/management/components/management/case/differentDrawer.vue index 8bcaab2415..214dee02d8 100644 --- a/frontend/src/views/api-test/management/components/management/case/differentDrawer.vue +++ b/frontend/src/views/api-test/management/components/management/case/differentDrawer.vue @@ -148,6 +148,7 @@ (e: 'close'): void; (e: 'clearThisChange', isEvery: boolean): void; (e: 'sync', mergeRequest: RequestParam): void; + (e: 'loadList'): void; }>(); const showDiffVisible = defineModel('visible', { @@ -196,13 +197,6 @@ const form = ref({ ...initForm }); - function cancel() { - form.value = { ...initForm }; - checkType.value = [...initCheckList]; - showDiffVisible.value = false; - emit('close'); - } - const syncLoading = ref(false); const defaultCaseParams = inject('defaultCaseParams'); @@ -210,9 +204,52 @@ const apiDetailInfo = ref>({}); const apiDefinedRequest = ref>({}); - + const syncCaseDetail = ref>({}); const diffDistanceMap = ref>({}); + // 获取用例详情 + async function getCaseDetailInfo(id: string) { + try { + const res = await getCaseDetail(id); + syncCaseDetail.value = res; + const result = await diffDataRequest(id); + const { caseRequest, apiRequest } = result; + caseDetail.value = { + ...caseDetail.value, + ...caseRequest, + num: caseDetail.value.num, + }; + apiDefinedRequest.value = apiRequest; + let parseRequestBodyResult; + if (res.protocol === 'HTTP') { + parseRequestBodyResult = parseRequestBodyFiles(res.request.body); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 + } + caseDetail.value = { + ...cloneDeep(defaultCaseParams as RequestParam), + ...({ + ...res, + ...caseRequest, + num: res.num, + url: res.path, + ...parseRequestBodyResult, + } as Partial), + }; + form.value.ignoreApiChange = caseDetail.value.ignoreApiChange; + } catch (error) { + // eslint-disable-next-line no-console + console.log(error); + } + } + + async function getApiDetail(apiDefinitionId: string) { + try { + const detail = await getDefinitionDetail(apiDefinitionId); + apiDetailInfo.value = detail as ApiDefinitionDetail; + } catch (error) { + // eslint-disable-next-line no-console + console.log(error); + } + } /** * 设置对比 * @params apiValue 接口数据 @@ -332,11 +369,57 @@ getBodyData(RequestBodyFormat.FORM_DATA); getBodyData(RequestBodyFormat.WWW_FORM); } + + const loading = ref(false); + async function getRequestDetail(definedId: string, apiCaseId: string) { + loading.value = true; + try { + await Promise.all([getApiDetail(definedId), getCaseDetailInfo(apiCaseId)]); + processData(); + } catch (error) { + // eslint-disable-next-line no-console + console.error(error); + } finally { + loading.value = false; + } + } + + const ignoreThisChangeLoading = ref(false); + // 忽略并清除本次变更 + async function clearThisChangeHandler() { + if (props.activeApiCaseId) { + ignoreThisChangeLoading.value = true; + try { + await clearThisChange(props.activeApiCaseId); + getRequestDetail(props.activeDefinedId, props.activeApiCaseId); + emit('clearThisChange', true); + } catch (error) { + // eslint-disable-next-line no-console + console.log(error); + } finally { + ignoreThisChangeLoading.value = false; + } + } + } + + async function cancel() { + if (!caseDetail.value.inconsistentWithApi) { + try { + await clearThisChange(props.activeApiCaseId); + emit('loadList'); + } catch (error) { + console.log(error); + } + } + form.value = { ...initForm }; + checkType.value = [...initCheckList]; + showDiffVisible.value = false; + emit('close'); + } + // 是否显示配置项 const showSyncConfig = computed(() => caseDetail.value.inconsistentWithApi && !form.value.ignoreApiChange); - const syncCaseDetail = ref>({}); - // 同步 async function confirmSync() { if ( @@ -371,80 +454,6 @@ } } - // 获取用例详情 - async function getCaseDetailInfo(id: string) { - try { - const res = await getCaseDetail(id); - syncCaseDetail.value = res; - const result = await diffDataRequest(id); - const { caseRequest, apiRequest } = result; - caseDetail.value = { - ...caseDetail.value, - ...caseRequest, - num: caseDetail.value.num, - }; - apiDefinedRequest.value = apiRequest; - let parseRequestBodyResult; - if (res.protocol === 'HTTP') { - parseRequestBodyResult = parseRequestBodyFiles(res.request.body); // 解析请求体中的文件,将详情中的文件 id 集合收集,更新时以判断文件是否删除以及是否新上传的文件 - } - caseDetail.value = { - ...cloneDeep(defaultCaseParams as RequestParam), - ...({ - ...res, - ...caseRequest, - num: res.num, - url: res.path, - ...parseRequestBodyResult, - } as Partial), - }; - form.value.ignoreApiChange = caseDetail.value.ignoreApiChange; - } catch (error) { - // eslint-disable-next-line no-console - console.log(error); - } - } - - async function getApiDetail(apiDefinitionId: string) { - try { - const detail = await getDefinitionDetail(apiDefinitionId); - apiDetailInfo.value = detail as ApiDefinitionDetail; - } catch (error) { - // eslint-disable-next-line no-console - console.log(error); - } - } - - const loading = ref(false); - async function getRequestDetail(definedId: string, apiCaseId: string) { - loading.value = true; - try { - await Promise.all([getApiDetail(definedId), getCaseDetailInfo(apiCaseId)]); - processData(); - } catch (error) { - // eslint-disable-next-line no-console - console.error(error); - } finally { - loading.value = false; - } - } - const ignoreThisChangeLoading = ref(false); - // 忽略并清除本次变更 - async function clearThisChangeHandler() { - if (props.activeApiCaseId) { - ignoreThisChangeLoading.value = true; - try { - await clearThisChange(props.activeApiCaseId); - getRequestDetail(props.activeDefinedId, props.activeApiCaseId); - emit('clearThisChange', true); - } catch (error) { - // eslint-disable-next-line no-console - console.log(error); - } finally { - ignoreThisChangeLoading.value = false; - } - } - } // 忽略每次变更 async function changeIgnore(newValue: string | number | boolean) { try {