From c4b5ee9101514ab7e510ebd0325818d4aa658aa4 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 1 Apr 2021 19:12:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dapi=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E4=B8=8B=E6=BB=91=E6=97=B6=E4=B8=8D=E4=BC=9A=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=8E=A5=E5=8F=A3=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复api文档下滑时不会动态加载接口信息的bug --- .../components/document/ApiDocumentAnchor.vue | 81 ++++++++++++++----- 1 file changed, 63 insertions(+), 18 deletions(-) diff --git a/frontend/src/business/components/api/definition/components/document/ApiDocumentAnchor.vue b/frontend/src/business/components/api/definition/components/document/ApiDocumentAnchor.vue index 73e447b198..01d4fcff60 100644 --- a/frontend/src/business/components/api/definition/components/document/ApiDocumentAnchor.vue +++ b/frontend/src/business/components/api/definition/components/document/ApiDocumentAnchor.vue @@ -450,6 +450,12 @@ export default { } }, initApiDocSimpleList() { + //首先跳转到第一个节点(为了让滚动条变为0,防止重新加载后滚动条位置出现动乱导致页面混乱) + if(this.apiInfoArray.length > 0){ + this.clickStep(this.apiInfoArray[0].id); + } + this.apiInfoArray = []; + this.apiShowArray = []; let simpleRequest = this.apiSearch; if (this.projectId != null && this.projectId != "") { simpleRequest.projectId = this.projectId; @@ -465,7 +471,8 @@ export default { simpleRequest.trashEnable = this.trashEnable; let simpleInfoUrl = "/api/document/selectApiSimpleInfo"; - this.apiInfoArray = []; + + this.$post(simpleInfoUrl, simpleRequest, response => { this.apiInfoArray = response.data; this.apiStepIndex = 0; @@ -509,11 +516,22 @@ export default { }, (error) => { }); }, - selectApiInfo(index,apiId) { + selectApiInfo(index,apiId,needUpdateShowArray) { let simpleInfoUrl = "/api/document/selectApiInfoById/" + apiId; this.$get(simpleInfoUrl, response => { let returnData = response.data; this.$set(this.apiInfoArray,index,returnData); + if(needUpdateShowArray){ + let showApiIndex = -1; + for(let i = 0;i< this.apiShowArray.length;i++){ + if(this.apiShowArray[i].id === apiId){ + showApiIndex = i; + } + } + if(showApiIndex > -1){ + this.$set(this.apiShowArray,showApiIndex,returnData); + } + } }); }, //itemIndex,afterNodeIndex,beforeNodeIndex 三个是回调参数,用于重新构建showArray的数据 isRedirectScroll:是否调用跳转函数 @@ -659,7 +677,21 @@ export default { let dataIndex = this.apiStepIndex -3; if(dataIndex >= 0){ let apiInfo = this.apiInfoArray[dataIndex]; - this.apiShowArray.unshift(apiInfo); + let haveData = false; + //检查showArray是否存在这条数据。不存在才加入 + this.apiShowArray.forEach(api => { + if(api.id === apiInfo.id){ + haveData = true; + } + }); + if(!haveData){ + this.apiShowArray.unshift(apiInfo); + if(!apiInfo.selectedFlag){ + this.selectApiInfo(dataIndex,this.apiInfoArray[dataIndex].id,true); + } + }else { + this.currentApiIndexInApiShowArray--; + } }else{ this.currentApiIndexInApiShowArray--; } @@ -671,27 +703,40 @@ export default { this.apiStepIndex --; }else if(lastIndex > this.currentApiIndexInApiShowArray){ //下滚 - // if(this.needAsyncSelect){ - //进行判断:是否还需要为apiShowArray 增加数据。 由于在当前数据前后最多展现2条数据, - //可得: apiStepIndex+1+ 2 < apiInfoArray,需要添加数据 - let dataIndex = this.apiStepIndex +3; - if(dataIndex < this.apiInfoArray.length){ - let apiInfo = this.apiInfoArray[dataIndex]; + //进行判断:是否还需要为apiShowArray 增加数据。 由于在当前数据前后最多展现2条数据, + //可得: apiStepIndex+1+ 2 < apiInfoArray,需要添加数据 + let dataIndex = this.apiStepIndex +3; + if(dataIndex < this.apiInfoArray.length){ + let apiInfo = this.apiInfoArray[dataIndex]; + + let haveData = false; + //检查showArray是否存在这条数据。不存在才加入 + this.apiShowArray.forEach(api => { + if(api.id === apiInfo.id){ + haveData = true; + } + }); + if(!haveData){ this.apiShowArray.push(apiInfo); + if(!apiInfo.selectedFlag){ + this.selectApiInfo(dataIndex,this.apiInfoArray[dataIndex].id,true); + } } - if(this.apiShowArray.length <= this.maxCompnentSize){ - //判断currentApiIndexInApiShowArray 是否需要添加,以及是否需要删除第一个元素 - this.currentApiIndexInApiShowArray++; - }else{ - this.apiShowArray.shift(); - let itemHeight = this.$refs.apiDocInfoDivItem[0].offsetHeight+10; - this.$refs.apiDocInfoDiv.scrollTop = (apiDocDivScrollTop-itemHeight); - } - // } + } + + if(this.apiShowArray.length <= this.maxCompnentSize){ + //判断currentApiIndexInApiShowArray 是否需要添加,以及是否需要删除第一个元素 + this.currentApiIndexInApiShowArray++; + }else{ + this.apiShowArray.shift(); + let itemHeight = this.$refs.apiDocInfoDivItem[0].offsetHeight+10; + this.$refs.apiDocInfoDiv.scrollTop = (apiDocDivScrollTop-itemHeight); + } this.apiStepIndex ++; } } + this.clickStepFlag = false; }, redirectScroll(){