fix: 修复api文档下滑时不会动态加载接口信息的bug

修复api文档下滑时不会动态加载接口信息的bug
This commit is contained in:
song-tianyang 2021-04-01 19:12:53 +08:00 committed by BugKing
parent f253b1ec15
commit 22fd1fa93e
1 changed files with 63 additions and 18 deletions

View File

@ -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(){