fix(接口定义): 测试接口时不更新原接口数据

This commit is contained in:
fit2-zhao 2021-01-21 18:26:31 +08:00
parent 0d278cf20b
commit deac357040
10 changed files with 125 additions and 23 deletions

View File

@ -57,7 +57,7 @@
<!-- 添加/编辑测试窗口--> <!-- 添加/编辑测试窗口-->
<div v-else-if="item.type=== 'ADD'" class="ms-api-div"> <div v-else-if="item.type=== 'ADD'" class="ms-api-div">
<ms-api-config @runTest="runTest" @saveApi="saveApi" @createRootModel="createRootModel" ref="apiConfig" <ms-api-config :syncTabs="syncTabs" @runTest="runTest" @saveApi="saveApi" @createRootModel="createRootModel" ref="apiConfig"
:current-api="item.api" :current-api="item.api"
:currentProtocol="currentProtocol" :currentProtocol="currentProtocol"
:moduleOptions="moduleOptions"/> :moduleOptions="moduleOptions"/>
@ -76,13 +76,13 @@
<!-- 测试--> <!-- 测试-->
<div v-else-if="item.type=== 'TEST'" class="ms-api-div"> <div v-else-if="item.type=== 'TEST'" class="ms-api-div">
<ms-run-test-http-page :currentProtocol="currentProtocol" :api-data="item.api" @saveAsApi="editApi" <ms-run-test-http-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api" @saveAsApi="editApi"
@refresh="refresh" v-if="currentProtocol==='HTTP'"/> @refresh="refresh" v-if="currentProtocol==='HTTP'"/>
<ms-run-test-tcp-page :currentProtocol="currentProtocol" :api-data="item.api" @saveAsApi="editApi" <ms-run-test-tcp-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api" @saveAsApi="editApi"
@refresh="refresh" v-if="currentProtocol==='TCP'"/> @refresh="refresh" v-if="currentProtocol==='TCP'"/>
<ms-run-test-sql-page :currentProtocol="currentProtocol" :api-data="item.api" @saveAsApi="editApi" <ms-run-test-sql-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api" @saveAsApi="editApi"
@refresh="refresh" v-if="currentProtocol==='SQL'"/> @refresh="refresh" v-if="currentProtocol==='SQL'"/>
<ms-run-test-dubbo-page :currentProtocol="currentProtocol" :api-data="item.api" @saveAsApi="editApi" <ms-run-test-dubbo-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api" @saveAsApi="editApi"
@refresh="refresh" v-if="currentProtocol==='DUBBO'"/> @refresh="refresh" v-if="currentProtocol==='DUBBO'"/>
</div> </div>
</el-tab-pane> </el-tab-pane>
@ -184,7 +184,8 @@
type: "list", type: "list",
closable: false closable: false
}], }],
isApiListEnable: true isApiListEnable: true,
syncTabs: [],
} }
}, },
watch: { watch: {

View File

@ -3,16 +3,16 @@
<div class="card-container"> <div class="card-container">
<!-- HTTP 请求参数 --> <!-- HTTP 请求参数 -->
<ms-edit-complete-http-api @runTest="runTest" @saveApi="saveApi" @createRootModelInTree="createRootModelInTree" :request="request" :response="response" <ms-edit-complete-http-api @runTest="runTest" @saveApi="saveApi" @createRootModelInTree="createRootModelInTree" :request="request" :response="response"
:basisData="currentApi" :moduleOptions="moduleOptions" v-if="currentProtocol === 'HTTP'"/> :basisData="currentApi" :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'HTTP'"/>
<!-- TCP --> <!-- TCP -->
<ms-edit-complete-tcp-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi" <ms-edit-complete-tcp-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" v-if="currentProtocol === 'TCP'"/> :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'TCP'"/>
<!--DUBBO--> <!--DUBBO-->
<ms-edit-complete-dubbo-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi" <ms-edit-complete-dubbo-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" v-if="currentProtocol === 'DUBBO'"/> :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'DUBBO'"/>
<!--SQL--> <!--SQL-->
<ms-edit-complete-sql-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi" <ms-edit-complete-sql-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" v-if="currentProtocol === 'SQL'"/> :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'SQL'"/>
</div> </div>
</template> </template>
@ -45,6 +45,7 @@
currentApi: {}, currentApi: {},
moduleOptions: {}, moduleOptions: {},
currentProtocol: String, currentProtocol: String,
syncTabs: Array,
}, },
created() { created() {
this.projectId = getCurrentProjectID(); this.projectId = getCurrentProjectID();

View File

@ -44,8 +44,30 @@
isReadOnly: { isReadOnly: {
type: Boolean, type: Boolean,
default: false default: false
},
syncTabs: Array,
},
watch: {
syncTabs() {
if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) {
//
let url = "/api/definition/get/";
this.$get(url + this.basisData.id, response => {
if (response.data) {
let request = JSON.parse(response.data.request);
let index = this.syncTabs.findIndex(item => {
if (item === this.basisData.id) {
return true;
}
})
this.syncTabs.splice(index, 1);
Object.assign(this.request, request);
}
});
}
} }
}, },
data() { data() {
return {validated: false} return {validated: false}
}, },

View File

@ -149,7 +149,29 @@
options: API_STATUS, options: API_STATUS,
} }
}, },
props: {moduleOptions: {}, request: {}, response: {}, basisData: {}}, props: {moduleOptions: {}, request: {}, response: {}, basisData: {}, syncTabs: Array},
watch: {
syncTabs() {
if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) {
//
let url = "/api/definition/get/";
this.$get(url + this.basisData.id, response => {
if (response.data) {
let request = JSON.parse(response.data.request);
let index = this.syncTabs.findIndex(item => {
if (item === this.basisData.id) {
return true;
}
})
this.syncTabs.splice(index, 1);
this.httpForm.path = response.data.path;
this.httpForm.method = response.data.method;
Object.assign(this.request, request);
}
});
}
}
},
methods: { methods: {
runTest() { runTest() {
this.$refs['httpForm'].validate((valid) => { this.$refs['httpForm'].validate((valid) => {

View File

@ -43,9 +43,29 @@ export default {
isReadOnly: { isReadOnly: {
type: Boolean, type: Boolean,
default: false default: false
},
syncTabs:{},
},
watch: {
syncTabs() {
if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) {
//
let url = "/api/definition/get/";
this.$get(url + this.basisData.id, response => {
if (response.data) {
let request = JSON.parse(response.data.request);
let index = this.syncTabs.findIndex(item => {
if (item === this.basisData.id) {
return true;
}
})
this.syncTabs.splice(index, 1);
Object.assign(this.request, request);
}
});
}
} }
}, },
data() { data() {
return {validated: false} return {validated: false}
}, },

View File

@ -42,14 +42,34 @@ export default {
isReadOnly: { isReadOnly: {
type: Boolean, type: Boolean,
default: false default: false
} },
syncTabs:Array,
}, },
data() { data() {
return { return {
validated: false, validated: false,
} }
}, },
watch: {
syncTabs() {
if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) {
//
let url = "/api/definition/get/";
this.$get(url + this.basisData.id, response => {
if (response.data) {
let request = JSON.parse(response.data.request);
let index = this.syncTabs.findIndex(item => {
if (item === this.basisData.id) {
return true;
}
})
this.syncTabs.splice(index, 1);
Object.assign(this.request, request);
}
});
}
}
},
methods: { methods: {
callback() { callback() {
this.validated = true; this.validated = true;

View File

@ -89,7 +89,7 @@
reportId: "", reportId: "",
} }
}, },
props: {apiData: {}, currentProtocol: String,}, props: {apiData: {}, currentProtocol: String,syncTabs: Array},
methods: { methods: {
handleCommand(e) { handleCommand(e) {
switch (e) { switch (e) {
@ -173,6 +173,9 @@
let bodyFiles = this.getBodyUploadFiles(); let bodyFiles = this.getBodyUploadFiles();
this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$fileUpload(url, null, bodyFiles, this.api, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
if (this.syncTabs.indexOf(this.api.id) === -1) {
this.syncTabs.push(this.api.id);
}
this.$emit('saveApi', this.api); this.$emit('saveApi', this.api);
}); });
}, },
@ -228,7 +231,8 @@
} }
}, },
created() { created() {
this.api = this.apiData; //
this.api = JSON.parse(JSON.stringify(this.apiData));
this.api.protocol = this.currentProtocol; this.api.protocol = this.currentProtocol;
this.currentRequest = this.api.request; this.currentRequest = this.api.request;
this.getEnvironments(); this.getEnvironments();

View File

@ -113,7 +113,7 @@
projectId: "", projectId: "",
} }
}, },
props: {apiData: {}, currentProtocol: String,}, props: {apiData: {}, currentProtocol: String, syncTabs: Array},
methods: { methods: {
handleCommand(e) { handleCommand(e) {
switch (e) { switch (e) {
@ -205,6 +205,9 @@
this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$fileUpload(url, null, bodyFiles, this.api, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.$emit('saveApi', this.api); this.$emit('saveApi', this.api);
if (this.syncTabs.indexOf(this.api.id) === -1) {
this.syncTabs.push(this.api.id);
}
}); });
}, },
selectTestCase(item) { selectTestCase(item) {
@ -230,7 +233,8 @@
}, },
created() { created() {
this.projectId = getCurrentProjectID(); this.projectId = getCurrentProjectID();
this.api = this.apiData; //
this.api = JSON.parse(JSON.stringify(this.apiData));
this.api.protocol = this.currentProtocol; this.api.protocol = this.currentProtocol;
this.currentRequest = this.api.request; this.currentRequest = this.api.request;
this.getResult(); this.getResult();

View File

@ -89,7 +89,7 @@
reportId: "", reportId: "",
} }
}, },
props: {apiData: {}, currentProtocol: String,}, props: {apiData: {}, currentProtocol: String,syncTabs: Array},
methods: { methods: {
handleCommand(e) { handleCommand(e) {
switch (e) { switch (e) {
@ -172,6 +172,9 @@
let bodyFiles = this.getBodyUploadFiles(); let bodyFiles = this.getBodyUploadFiles();
this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$fileUpload(url, null, bodyFiles, this.api, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
if (this.syncTabs.indexOf(this.api.id) === -1) {
this.syncTabs.push(this.api.id);
}
this.$emit('saveApi', this.api); this.$emit('saveApi', this.api);
}); });
}, },
@ -227,7 +230,8 @@
} }
}, },
created() { created() {
this.api = this.apiData; //
this.api = JSON.parse(JSON.stringify(this.apiData));
this.api.protocol = this.currentProtocol; this.api.protocol = this.currentProtocol;
this.currentRequest = this.api.request; this.currentRequest = this.api.request;
this.getEnvironments(); this.getEnvironments();

View File

@ -90,7 +90,7 @@
projectId: "" projectId: ""
} }
}, },
props: {apiData: {}, currentProtocol: String,}, props: {apiData: {}, currentProtocol: String,syncTabs: Array},
methods: { methods: {
handleCommand(e) { handleCommand(e) {
switch (e) { switch (e) {
@ -173,6 +173,9 @@
let bodyFiles = this.getBodyUploadFiles(); let bodyFiles = this.getBodyUploadFiles();
this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$fileUpload(url, null, bodyFiles, this.api, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
if (this.syncTabs.indexOf(this.api.id) === -1) {
this.syncTabs.push(this.api.id);
}
this.$emit('saveApi', this.api); this.$emit('saveApi', this.api);
}); });
}, },
@ -194,7 +197,8 @@
} }
}, },
created() { created() {
this.api = this.apiData; //
this.api = JSON.parse(JSON.stringify(this.apiData));
this.api.protocol = this.currentProtocol; this.api.protocol = this.currentProtocol;
this.currentRequest = this.api.request; this.currentRequest = this.api.request;
this.projectId = getCurrentProjectID(); this.projectId = getCurrentProjectID();