feat:实现 接口测试-接口定义界面,ctrl + s 保存快捷键 (#1254)

This commit is contained in:
Coooder-X 2021-01-26 13:05:03 +08:00 committed by GitHub
parent cffe0f8b3a
commit 5ee7fffd68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 102 additions and 14 deletions

View File

@ -35,7 +35,7 @@
closable>
<div class="ms-api-scenario-div">
<ms-edit-api-scenario @refresh="refresh" :currentScenario="item.currentScenario"
:moduleOptions="moduleOptions"/>
:moduleOptions="moduleOptions" ref="autoScenarioConfig"/>
</div>
</el-tab-pane>
@ -111,6 +111,16 @@
// DOM my-component
this.renderComponent = true;
});
},
'$route'(to, from) { // ctrl s
if (to.path.indexOf('/api/automation') == -1) {
if (this.$refs && this.$refs.autoScenarioConfig) {
console.log(this.$refs.autoScenarioConfig);
this.$refs.autoScenarioConfig.forEach(item => {
item.removeListener();
});
}
}
}
},
methods: {
@ -158,6 +168,20 @@
label = tab.currentScenario.name;
this.tabs.push({label: label, name: name, currentScenario: tab.currentScenario});
}
if (this.$refs && this.$refs.autoScenarioConfig) {
this.$refs.autoScenarioConfig.forEach(item => {
item.removeListener();
}); // tab ctrl + s
this.addListener();
}
},
addListener() {
let index = this.tabs.findIndex(item => item.name === this.activeName); // tabindex
if(index != -1) { // tab
this.$nextTick(()=>{
this.$refs.autoScenarioConfig[index].addListener();
});
}
},
handleTabClose() {
this.tabs = [];
@ -181,6 +205,7 @@
this.tabs = this.tabs.filter(tab => tab.name !== targetName);
if (this.tabs.length > 0) {
this.activeName = this.tabs[this.tabs.length - 1].name;
this.addListener(); //
} else {
this.activeName = "default"
}

View File

@ -5,7 +5,7 @@
<!--操作按钮-->
<div class="ms-opt-btn">
<el-button type="primary" size="small" @click="editScenario">{{$t('commons.save')}}</el-button>
<el-button type="primary" size="small" @click="editScenario" title="ctrl + s">{{$t('commons.save')}}</el-button>
</div>
<div class="tip">{{$t('test_track.plan_view.base_info')}}</div>
@ -222,6 +222,7 @@
import ScenarioApiRelevance from "./api/ApiRelevance";
import ScenarioRelevance from "./api/ScenarioRelevance";
import MsComponentConfig from "./component/ComponentConfig";
import {handleCtrlSEvent} from "../../../../../common/js/utils";
export default {
name: "EditApiScenario",
@ -295,6 +296,7 @@
this.operatingElements = ELEMENTS.get("ALL");
this.getMaintainerOptions();
this.getApiScenario();
this.addListener(); // ctrl s
},
directives: {OutsideClick},
computed: {
@ -413,6 +415,17 @@
}
},
methods: {
addListener() {
document.addEventListener("keydown", this.createCtrlSHandle);
// document.addEventListener("keydown", (even => handleCtrlSEvent(even, this.$refs.httpApi.saveApi)));
},
removeListener() {
document.removeEventListener("keydown", this.createCtrlSHandle);
},
createCtrlSHandle(event) {
console.log("create ctrl + s");
handleCtrlSEvent(event, this.editScenario);
},
getIdx(index) {
return index - 0.33
},
@ -822,15 +835,13 @@
}
return bodyUploadFiles;
},
editScenario(showMessage) {
editScenario() {
this.$refs['currentScenario'].validate((valid) => {
if (valid) {
this.setParameter();
let bodyFiles = this.getBodyUploadFiles(this.currentScenario);
this.$fileUpload(this.path, null, bodyFiles, this.currentScenario, response => {
if (showMessage) {
this.$success(this.$t('commons.save_success'));
}
this.$success(this.$t('commons.save_success'));
this.path = "/api/automation/update";
if (response.data) {
this.currentScenario.id = response.data.id;

View File

@ -198,6 +198,15 @@
// DOM my-component
this.renderComponent = true;
});
},
'$route'(to, from) { // ctrl s
if (to.path.indexOf('/api/definition') == -1) {
if (this.$refs && this.$refs.apiConfig) {
this.$refs.apiConfig.forEach(item => {
item.removeListener();
});
}
}
}
},
methods: {
@ -211,6 +220,17 @@
if (tab.name === 'add') {
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug");
}
if(this.$refs.apiConfig) {
this.$refs.apiConfig.forEach(item => {
console.log(item);
item.removeListener();
}); // tab ctrl + s
let tabs = this.apiTabs;
let index = tabs.findIndex(item => item.name === tab.name); // tabindex
if(index != -1) {
this.$refs.apiConfig[index - 1].addListener(); // tab ctrl + s index-1tab
}
}
},
handleCommand(e) {
switch (e) {

View File

@ -3,16 +3,16 @@
<div class="card-container">
<!-- HTTP 请求参数 -->
<ms-edit-complete-http-api @runTest="runTest" @saveApi="saveApi" @createRootModelInTree="createRootModelInTree" :request="request" :response="response"
:basisData="currentApi" :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'HTTP'"/>
:basisData="currentApi" :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'HTTP'" ref="httpApi"/>
<!-- TCP -->
<ms-edit-complete-tcp-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'TCP'"/>
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'TCP'" ref="tcpApi"/>
<!--DUBBO-->
<ms-edit-complete-dubbo-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'DUBBO'"/>
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'DUBBO'" ref="dubboApi"/>
<!--SQL-->
<ms-edit-complete-sql-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'SQL'"/>
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'SQL'" ref="sqlApi"/>
</div>
</template>
@ -27,6 +27,7 @@
import {createComponent, Request} from "./jmeter/components";
import Sampler from "./jmeter/components/sampler/sampler";
import {WORKSPACE_ID} from '@/common/js/constants';
import {handleCtrlSEvent} from "../../../../../common/js/utils";
export default {
name: "ApiConfig",
@ -65,8 +66,30 @@
break;
}
this.formatApi();
this.addListener();
},
methods: {
addListener() {
document.addEventListener("keydown", this.createCtrlSHandle);
// document.addEventListener("keydown", (even => handleCtrlSEvent(even, this.$refs.httpApi.saveApi)));
},
removeListener() {
document.removeEventListener("keydown", this.createCtrlSHandle);
},
createCtrlSHandle(event) {
if(this.$refs.httpApi) {
handleCtrlSEvent(event, this.$refs.httpApi.saveApi);
}
else if(this.$refs.tcpApi) {
handleCtrlSEvent(event, this.$refs.tcpApi.saveApi);
}
else if(this.$refs.dubboApi) {
handleCtrlSEvent(event, this.$refs.dubboApi.saveApi);
}
else if(this.$refs.sqlApi) {
handleCtrlSEvent(event, this.$refs.sqlApi.saveApi);
}
},
runTest(data) {
this.setParameters(data);
let bodyFiles = this.getBodyUploadFiles(data);

View File

@ -6,7 +6,7 @@
<el-col>
<!--操作按钮-->
<div style="float: right;margin-right: 20px;margin-top: 20px">
<el-button type="primary" size="small" @click="saveApi">{{ $t('commons.save') }}</el-button>
<el-button type="primary" size="small" @click="saveApi" title="ctrl + s">{{ $t('commons.save') }}</el-button>
<el-button type="primary" size="small" @click="runTest">{{ $t('commons.test') }}</el-button>
</div>
</el-col>

View File

@ -6,7 +6,7 @@
<el-form :model="httpForm" :rules="rule" ref="httpForm" label-width="80px" label-position="right">
<!-- 操作按钮 -->
<div style="float: right;margin-right: 20px">
<el-button type="primary" size="small" @click="saveApi">{{ $t('commons.save') }}</el-button>
<el-button type="primary" size="small" @click="saveApi" title="ctrl + s">{{ $t('commons.save') }}</el-button>
<el-button type="primary" size="small" @click="runTest">{{ $t('commons.test') }}</el-button>
</div>
<br/>

View File

@ -5,7 +5,7 @@
<el-col>
<!--操作按钮-->
<div style="float: right;margin-right: 20px;margin-top: 20px">
<el-button type="primary" size="small" @click="saveApi">{{ $t('commons.save') }}</el-button>
<el-button type="primary" size="small" @click="saveApi" title="ctrl + s">{{ $t('commons.save') }}</el-button>
<el-button type="primary" size="small" @click="runTest">{{ $t('commons.test') }}</el-button>
</div>
</el-col>

View File

@ -5,7 +5,7 @@
<el-col>
<!--操作按钮-->
<div style="float: right;margin-right: 20px;margin-top: 20px">
<el-button type="primary" size="small" @click="saveApi">{{ $t('commons.save') }}</el-button>
<el-button type="primary" size="small" @click="saveApi" title="ctrl + s">{{ $t('commons.save') }}</el-button>
<el-button type="primary" size="small" @click="runTest">{{ $t('commons.test') }}</el-button>
</div>
</el-col>

View File

@ -356,3 +356,12 @@ export function _getBodyUploadFiles(request, bodyUploadFiles, obj) {
}
}
}
export function handleCtrlSEvent(event, func) {
if (event.keyCode === 83 && event.ctrlKey) {
// console.log('拦截到 ctrl + s');//ctrl+s
func();
event.preventDefault();
event.returnValue = false;
return false;
}
}