style(接口测试): 修复接口测试首页swagger跳转的问题

--bug=1015399 --user=宋天阳 【接口测试】首页-运行中的定时任务,swagger定时任务跳转后没有显示定时任务tab
https://www.tapd.cn/55049933/s/1215835
This commit is contained in:
song-tianyang 2022-07-29 19:02:32 +08:00 committed by 建国
parent 294dbdb82a
commit 134e781f7c
3 changed files with 309 additions and 262 deletions

View File

@ -220,30 +220,32 @@ export default {
if (!params) { if (!params) {
return; return;
} }
let paramArr = params.split("edit:"); if (params instanceof String) {
if (paramArr.length !== 2) { let paramArr = params.split("edit:");
return; if (paramArr.length !== 2) {
} return;
let scenarioId = paramArr[1];
//
this.$post("/api/automation/list/1/1", {id: scenarioId}, response => {
let data = response.data;
if (data && data.listObject && data.listObject.length > 0) {
let row = data.listObject[0];
let checks = ["array", "object"];
if (row && row.tags && (checks.indexOf(Object.prototype.toString.call(row.tags)
.match(/\[object (\w+)\]/)[1].toLowerCase()) !== -1)) {
row.tags = JSON.parse(row.tags);
}
//
if (this.moduleOptions && this.moduleOptions.length === 0) {
let projectId = data.projectId ? data.projectId : this.projectId;
this.initModules(row, projectId);
} else {
this.editScenario(row);
}
} }
}); let scenarioId = paramArr[1];
//
this.$post("/api/automation/list/1/1", {id: scenarioId}, response => {
let data = response.data;
if (data && data.listObject && data.listObject.length > 0) {
let row = data.listObject[0];
let checks = ["array", "object"];
if (row && row.tags && (checks.indexOf(Object.prototype.toString.call(row.tags)
.match(/\[object (\w+)\]/)[1].toLowerCase()) !== -1)) {
row.tags = JSON.parse(row.tags);
}
//
if (this.moduleOptions && this.moduleOptions.length === 0) {
let projectId = data.projectId ? data.projectId : this.projectId;
this.initModules(row, projectId);
} else {
this.editScenario(row);
}
}
});
}
}, },
initModules(row, projectId) { initModules(row, projectId) {
this.$get("/api/automation/module/list/" + projectId, response => { this.$get("/api/automation/module/list/" + projectId, response => {

View File

@ -354,51 +354,52 @@ export default {
}; };
}, },
activated() { activated() {
this.selectNodeIds = []; this.$nextTick(() => {
let routeParamObj = this.$route.params.paramObj; let routeParamObj = this.$route.params.paramObj;
if (routeParamObj) { if (routeParamObj) {
let dataRange = routeParamObj.dataSelectRange; let dataRange = routeParamObj.dataSelectRange;
if (dataRange && dataRange.length > 0) { if (dataRange && dataRange.length > 0) {
this.activeDom = 'middle';
}
let dataType = routeParamObj.dataType;
if (dataType) {
if (dataType === "api") {
this.activeDom = 'left';
} else {
this.activeDom = 'middle'; this.activeDom = 'middle';
} }
} let dataType = routeParamObj.dataType;
if (routeParamObj.dataSelectRange) { if (dataType) {
let item = JSON.parse(JSON.stringify(routeParamObj.dataSelectRange)).param; if (dataType === "api") {
if (item !== undefined) { this.activeDom = 'left';
let type = item.taskGroup.toString(); } else {
if (type === "SWAGGER_IMPORT") { this.activeDom = 'middle';
this.handleTabsEdit(this.$t('api_test.api_import.timing_synchronization'), 'SCHEDULE'); }
this.param = item; }
if (routeParamObj.dataSelectRange) {
let item = JSON.parse(JSON.stringify(routeParamObj.dataSelectRange)).param;
if (item !== undefined) {
let type = item.taskGroup.toString();
if (type === "SWAGGER_IMPORT") {
this.openSwaggerScheduleTab();
this.param = item;
}
}
}
} else {
let dataType = this.$route.params.dataType;
if (dataType) {
if (dataType === "api") {
this.activeDom = 'left';
} else {
this.activeDom = 'middle';
}
}
if (this.$route.params.dataSelectRange) {
let item = JSON.parse(JSON.stringify(this.$route.params.dataSelectRange)).param;
if (item !== undefined) {
let type = item.taskGroup.toString();
if (type === "SWAGGER_IMPORT") {
this.openSwaggerScheduleTab();
this.param = item;
}
} }
} }
} }
} else { });
let dataType = this.$route.params.dataType;
if (dataType) {
if (dataType === "api") {
this.activeDom = 'left';
} else {
this.activeDom = 'middle';
}
}
if (this.$route.params.dataSelectRange) {
let item = JSON.parse(JSON.stringify(this.$route.params.dataSelectRange)).param;
if (item !== undefined) {
let type = item.taskGroup.toString();
if (type === "SWAGGER_IMPORT") {
this.handleTabsEdit(this.$t('api_test.api_import.timing_synchronization'), 'SCHEDULE');
this.param = item;
}
}
}
}
}, },
watch: { watch: {
currentProtocol() { currentProtocol() {
@ -463,6 +464,22 @@ export default {
} }
}, },
methods: { methods: {
openSwaggerScheduleTab() {
//
let scheduleTabName = "";
if (this.apiTabs) {
this.apiTabs.forEach(tab => {
if (tab.type === 'SCHEDULE') {
scheduleTabName = tab.name;
}
});
}
if (scheduleTabName === "") {
this.handleTabsEdit(this.$t('api_test.api_import.timing_synchronization'), 'SCHEDULE');
} else {
this.apiDefaultTab = scheduleTabName;
}
},
setEnvironment(data) { setEnvironment(data) {
if (data) { if (data) {
this.useEnvironment = data.id; this.useEnvironment = data.id;
@ -733,7 +750,7 @@ export default {
if (routeParamObj) { if (routeParamObj) {
let dataRange = routeParamObj.dataSelectRange; let dataRange = routeParamObj.dataSelectRange;
let dataType = routeParamObj.dataType; let dataType = routeParamObj.dataType;
if (dataRange) { if (dataRange && dataRange instanceof String) {
let selectParamArr = dataRange.split("edit:"); let selectParamArr = dataRange.split("edit:");
if (selectParamArr.length === 2) { if (selectParamArr.length === 2) {
let scenarioId = selectParamArr[1]; let scenarioId = selectParamArr[1];
@ -747,7 +764,7 @@ export default {
} else { } else {
let dataRange = this.$route.params.dataSelectRange; let dataRange = this.$route.params.dataSelectRange;
let dataType = this.$route.params.dataType; let dataType = this.$route.params.dataType;
if (dataRange) { if (dataRange && dataRange instanceof String) {
let selectParamArr = dataRange.split("edit:"); let selectParamArr = dataRange.split("edit:");
if (selectParamArr.length === 2) { if (selectParamArr.length === 2) {
let scenarioId = selectParamArr[1]; let scenarioId = selectParamArr[1];

View File

@ -4,23 +4,23 @@
<slot name="header"></slot> <slot name="header"></slot>
<ms-node-tree <ms-node-tree
v-loading="result.loading" v-loading="result.loading"
:tree-nodes="data" :tree-nodes="data"
:type="isReadOnly ? 'view' : 'edit'" :type="isReadOnly ? 'view' : 'edit'"
:allLabel="$t('api_test.definition.api_all')" :allLabel="$t('api_test.definition.api_all')"
:default-label="$t('api_test.definition.unplanned_api')" :default-label="$t('api_test.definition.unplanned_api')"
local-suffix="api_definition" local-suffix="api_definition"
@add="add" @add="add"
@edit="edit" @edit="edit"
@drag="drag" @drag="drag"
@remove="remove" @remove="remove"
@refresh="list" @refresh="list"
@filter="filter" @filter="filter"
:show-case-num="showCaseNum" :show-case-num="showCaseNum"
:delete-permission="['PROJECT_API_DEFINITION:READ+DELETE_API']" :delete-permission="['PROJECT_API_DEFINITION:READ+DELETE_API']"
:add-permission="['PROJECT_API_DEFINITION:READ+CREATE_API']" :add-permission="['PROJECT_API_DEFINITION:READ+CREATE_API']"
:update-permission="['PROJECT_API_DEFINITION:READ+EDIT_API']" :update-permission="['PROJECT_API_DEFINITION:READ+EDIT_API']"
@nodeSelectEvent="nodeChange" @nodeSelectEvent="nodeChange"
ref="nodeTree"> ref="nodeTree">
<template v-slot:header> <template v-slot:header>
@ -67,208 +67,236 @@ export default {
}, },
data() { data() {
return { return {
result: {}, result: {},
condition: { condition: {
protocol: OPTIONS[0].value, protocol: OPTIONS[0].value,
filterText: "", filterText: "",
trashEnable: false trashEnable: false
}, },
data: [], data: [],
currentModule: {}, currentModule: {},
}
},
props: {
isReadOnly: {
type: Boolean,
default() {
return false;
} }
}, },
props: { showCaseNum: {
isReadOnly: { type: Boolean,
type: Boolean, default() {
default() { return true;
return false;
}
},
showCaseNum: {
type: Boolean,
default() {
return true;
}
},
showOperator: Boolean,
planId: String,
currentVersion: String,
relevanceProjectId: String,
reviewId: String,
pageSource: String,
total: Number,
isRelevance: Boolean,
options: {
type: Array,
default() {
return OPTIONS;
}
} }
}, },
computed: { showOperator: Boolean,
isPlanModel() { planId: String,
return this.planId ? true : false; currentVersion: String,
}, relevanceProjectId: String,
isRelevanceModel() { reviewId: String,
return this.relevanceProjectId ? true : false; pageSource: String,
}, total: Number,
isReviewModel() { isRelevance: Boolean,
return this.reviewId ? true : false; options: {
}, type: Array,
projectId() { default() {
return getCurrentProjectID(); return OPTIONS;
} }
}
},
computed: {
isPlanModel() {
return this.planId ? true : false;
}, },
mounted() { isRelevanceModel() {
this.initProtocol(); return this.relevanceProjectId ? true : false;
}, },
isReviewModel() {
return this.reviewId ? true : false;
},
projectId() {
return getCurrentProjectID();
}
},
mounted() {
this.initProtocol();
},
watch: { watch: {
'condition.filterText'() { 'condition.filterText'() {
this.filter(); this.filter();
}, },
'condition.protocol'() { 'condition.protocol'() {
this.$emit('protocolChange', this.condition.protocol);
this.list();
},
'condition.trashEnable'() {
this.$emit('enableTrash', this.condition.trashEnable);
},
planId() {
this.list();
},
relevanceProjectId() {
this.list();
},
reviewId() {
this.list();
}
},
methods: {
initProtocol() {
//
let isRedirectPage = this.isRedirect();
if (this.$route.params.type) {
this.condition.protocol = this.$route.params.type;
this.$emit('protocolChange', this.condition.protocol); this.$emit('protocolChange', this.condition.protocol);
this.list(); this.list();
}, } else if (!this.isRelevance && !isRedirectPage) {
'condition.trashEnable'() { //
this.$emit('enableTrash', this.condition.trashEnable); this.$get('/api/module/getUserDefaultApiType/', response => {
}, this.condition.protocol = response.data;
planId() { this.$emit('protocolChange', this.condition.protocol);
this.list(); this.list();
}, });
relevanceProjectId() { } else {
this.list(); this.$emit('protocolChange', this.condition.protocol);
},
reviewId() {
this.list(); this.list();
} }
}, },
methods: { isRedirect() {
initProtocol() { let isRedirectPage = false;
if(this.$route.params.type){ let routeParamObj = this.$route.params.paramObj;
this.condition.protocol = this.$route.params.type; if (routeParamObj) {
this.$emit('protocolChange', this.condition.protocol); if (routeParamObj.dataSelectRange) {
this.list(); let item = JSON.parse(JSON.stringify(routeParamObj.dataSelectRange)).param;
}else if (!this.isRelevance) { if (item !== undefined) {
// let type = item.taskGroup.toString();
this.$get('/api/module/getUserDefaultApiType/', response => { if (type === "SWAGGER_IMPORT") {
this.condition.protocol = response.data; isRedirectPage = true;
this.$emit('protocolChange', this.condition.protocol);
this.list();
});
} else {
this.$emit('protocolChange', this.condition.protocol);
this.list();
}
},
filter() {
this.$refs.nodeTree.filter(this.condition.filterText);
},
list(projectId) {
let url = undefined;
if (this.isPlanModel) {
url = '/api/module/list/plan/' + this.planId + '/' + this.condition.protocol;
} else if (this.isRelevanceModel) {
url = "/api/module/list/" + this.relevanceProjectId + "/" + this.condition.protocol +
(this.currentVersion ? '/' + this.currentVersion : '');
} else {
url = "/api/module/list/" + (projectId ? projectId : this.projectId) + "/" + this.condition.protocol +
(this.currentVersion ? '/' + this.currentVersion : '');
if (!this.projectId) {
return;
}
}
this.result = this.$get(url, response => {
if (response.data != undefined && response.data != null) {
this.data = response.data;
this.data.forEach(node => {
node.name = node.name === '未规划接口' ? this.$t('api_test.definition.unplanned_api') : node.name
buildTree(node, {path: ''});
});
this.$emit('setModuleOptions', this.data);
this.$emit('setNodeTree', this.data);
if (this.$refs.nodeTree) {
this.$refs.nodeTree.filter(this.condition.filterText);
} }
} }
}); }
}, } else {
edit(param) { if (this.$route.params.dataSelectRange) {
param.projectId = this.projectId; let item = JSON.parse(JSON.stringify(this.$route.params.dataSelectRange)).param;
param.protocol = this.condition.protocol; if (item !== undefined) {
this.$post("/api/module/edit", param, () => { let type = item.taskGroup.toString();
if (type === "SWAGGER_IMPORT") {
isRedirectPage = true;
}
}
}
}
return isRedirectPage;
},
filter() {
this.$refs.nodeTree.filter(this.condition.filterText);
},
list(projectId) {
let url = undefined;
if (this.isPlanModel) {
url = '/api/module/list/plan/' + this.planId + '/' + this.condition.protocol;
} else if (this.isRelevanceModel) {
url = "/api/module/list/" + this.relevanceProjectId + "/" + this.condition.protocol +
(this.currentVersion ? '/' + this.currentVersion : '');
} else {
url = "/api/module/list/" + (projectId ? projectId : this.projectId) + "/" + this.condition.protocol +
(this.currentVersion ? '/' + this.currentVersion : '');
if (!this.projectId) {
return;
}
}
this.result = this.$get(url, response => {
if (response.data != undefined && response.data != null) {
this.data = response.data;
this.data.forEach(node => {
node.name = node.name === '未规划接口' ? this.$t('api_test.definition.unplanned_api') : node.name
buildTree(node, {path: ''});
});
this.$emit('setModuleOptions', this.data);
this.$emit('setNodeTree', this.data);
if (this.$refs.nodeTree) {
this.$refs.nodeTree.filter(this.condition.filterText);
}
}
});
},
edit(param) {
param.projectId = this.projectId;
param.protocol = this.condition.protocol;
this.$post("/api/module/edit", param, () => {
this.$success(this.$t('commons.save_success'));
this.list();
this.refresh();
}, (error) => {
this.list();
});
},
add(param) {
param.projectId = this.projectId;
param.protocol = this.condition.protocol;
if (param && param.level >= 9) {
this.list();
this.$error(this.$t('commons.warning_module_add'));
return;
} else {
this.$post("/api/module/add", param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.list(); this.list();
this.refresh();
}, (error) => { }, (error) => {
this.list(); this.list();
}); });
}, }
add(param) { },
param.projectId = this.projectId; remove(nodeIds) {
param.protocol = this.condition.protocol; this.$post("/api/module/delete", nodeIds, () => {
if (param && param.level >= 9) {
this.list();
this.$error(this.$t('commons.warning_module_add'));
return;
} else {
this.$post("/api/module/add", param, () => {
this.$success(this.$t('commons.save_success'));
this.list();
}, (error) => {
this.list();
});
}
},
remove(nodeIds) {
this.$post("/api/module/delete", nodeIds, () => {
this.list();
this.refresh();
}, (error) => {
this.list();
});
},
drag(param, list) {
this.$post("/api/module/drag", param, () => {
this.$post("/api/module/pos", list, () => {
this.list();
});
}, (error) => {
this.list();
});
},
nodeChange(node, nodeIds, pNodes) {
this.currentModule = node.data;
this.condition.trashEnable = false;
if (node.data.id === 'root') {
this.$emit("nodeSelectEvent", node, [], pNodes);
} else {
this.$emit("nodeSelectEvent", node, nodeIds, pNodes);
}
},
//---使
createRootModel() {
let dataArr = this.$refs.nodeTree.extendTreeNodes;
if (dataArr.length > 0) {
this.$refs.nodeTree.append({}, dataArr[0]);
}
},
exportAPI(type) {
this.$emit('exportAPI', type, this.data);
},
debug() {
this.$emit('debug');
},
saveAsEdit(data) {
this.$emit('saveAsEdit', data);
},
refresh() {
this.list(); this.list();
this.$emit('refreshTable'); this.refresh();
}, }, (error) => {
} this.list();
});
},
drag(param, list) {
this.$post("/api/module/drag", param, () => {
this.$post("/api/module/pos", list, () => {
this.list();
});
}, (error) => {
this.list();
});
},
nodeChange(node, nodeIds, pNodes) {
this.currentModule = node.data;
this.condition.trashEnable = false;
if (node.data.id === 'root') {
this.$emit("nodeSelectEvent", node, [], pNodes);
} else {
this.$emit("nodeSelectEvent", node, nodeIds, pNodes);
}
},
//---使
createRootModel() {
let dataArr = this.$refs.nodeTree.extendTreeNodes;
if (dataArr.length > 0) {
this.$refs.nodeTree.append({}, dataArr[0]);
}
},
exportAPI(type) {
this.$emit('exportAPI', type, this.data);
},
debug() {
this.$emit('debug');
},
saveAsEdit(data) {
this.$emit('saveAsEdit', data);
},
refresh() {
this.list();
this.$emit('refreshTable');
},
} }
}
</script> </script>
<style scoped> <style scoped>