增加场景的按钮,修复复制后id重复问题
This commit is contained in:
parent
7ab5fa1987
commit
f5bdeb1695
|
@ -13,8 +13,12 @@
|
|||
<el-dropdown trigger="click" @command="handleCommand">
|
||||
<span class="el-dropdown-link el-icon-more"/>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="{type: 'copy', index: index}">复制请求</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type: 'delete', index: index}">删除请求</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type: 'copy', index: index}">
|
||||
{{$t('api_test.request.copy')}}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type: 'delete', index: index}">
|
||||
{{$t('api_test.request.delete')}}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
|
@ -50,12 +54,12 @@
|
|||
|
||||
methods: {
|
||||
createRequest: function () {
|
||||
let request = new Request({method: "GET"});
|
||||
let request = new Request();
|
||||
this.requests.push(request);
|
||||
},
|
||||
copyRequest: function (index) {
|
||||
let request = this.requests[index];
|
||||
this.requests.push(JSON.parse(JSON.stringify(request)));
|
||||
this.requests.push(request.clone());
|
||||
},
|
||||
deleteRequest: function (index) {
|
||||
this.requests.splice(index, 1);
|
||||
|
|
|
@ -12,13 +12,17 @@
|
|||
{{$t('api_test.scenario.config')}}
|
||||
</span>
|
||||
</div>
|
||||
<!-- 暂时去掉,将来再加-->
|
||||
<!-- <el-dropdown trigger="click" @command="handleCommand">-->
|
||||
<!-- <span class="el-dropdown-link el-icon-more scenario-btn"/>-->
|
||||
<!-- <el-dropdown-menu slot="dropdown">-->
|
||||
<!-- <el-dropdown-item :command="{type:'delete', index:index}">删除场景</el-dropdown-item>-->
|
||||
<!-- </el-dropdown-menu>-->
|
||||
<!-- </el-dropdown>-->
|
||||
<el-dropdown trigger="click" @command="handleCommand">
|
||||
<span class="el-dropdown-link el-icon-more scenario-btn"/>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="{type: 'copy', index: index}">
|
||||
{{$t('api_test.scenario.copy')}}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'delete', index:index}">
|
||||
{{$t('api_test.scenario.delete')}}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
<ms-api-request-config :requests="scenario.requests" :open="select"/>
|
||||
</ms-api-collapse-item>
|
||||
|
@ -71,6 +75,10 @@
|
|||
createScenario: function () {
|
||||
this.scenarios.push(new Scenario());
|
||||
},
|
||||
copyScenario: function (index) {
|
||||
let scenario = this.scenarios[index];
|
||||
this.scenarios.push(scenario.clone());
|
||||
},
|
||||
deleteScenario: function (index) {
|
||||
this.scenarios.splice(index, 1);
|
||||
if (this.scenarios.length === 0) {
|
||||
|
@ -83,6 +91,9 @@
|
|||
},
|
||||
handleCommand: function (command) {
|
||||
switch (command.type) {
|
||||
case "copy":
|
||||
this.copyScenario(command.index);
|
||||
break;
|
||||
case "delete":
|
||||
this.deleteScenario(command.index);
|
||||
break;
|
||||
|
|
|
@ -137,6 +137,16 @@ export class Scenario extends BaseConfig {
|
|||
options.requests = options.requests || [new Request()];
|
||||
return options;
|
||||
}
|
||||
|
||||
clone() {
|
||||
let scenario = new Scenario(this);
|
||||
scenario.id = uuid();
|
||||
scenario.requests.forEach(function (request) {
|
||||
request.id = uuid();
|
||||
});
|
||||
|
||||
return scenario;
|
||||
}
|
||||
}
|
||||
|
||||
export class Request extends BaseConfig {
|
||||
|
@ -168,6 +178,12 @@ export class Request extends BaseConfig {
|
|||
isValid() {
|
||||
return !!this.url && !!this.method
|
||||
}
|
||||
|
||||
clone() {
|
||||
let request = new Request(this);
|
||||
request.id = uuid();
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
export class Body extends BaseConfig {
|
||||
|
|
|
@ -252,8 +252,12 @@ export default {
|
|||
variables: "Variables",
|
||||
headers: "Headers",
|
||||
kv_description: "Variables are available for all requests",
|
||||
copy: "Copy scenario",
|
||||
delete: "Delete scenario"
|
||||
},
|
||||
request: {
|
||||
copy: "Copy request",
|
||||
delete: "Delete request",
|
||||
input_name: "Please enter the request name",
|
||||
name: "Name",
|
||||
method: "Method",
|
||||
|
|
|
@ -252,8 +252,12 @@ export default {
|
|||
variables: "自定义变量",
|
||||
headers: "请求头",
|
||||
kv_description: "所有请求可以使用自定义变量",
|
||||
copy: "复制场景",
|
||||
delete: "删除场景"
|
||||
},
|
||||
request: {
|
||||
copy: "复制请求",
|
||||
delete: "删除请求",
|
||||
input_name: "请输入请求名称",
|
||||
name: "请求名称",
|
||||
method: "请求方法",
|
||||
|
|
|
@ -252,8 +252,12 @@ export default {
|
|||
variables: "自定義變數",
|
||||
headers: "請求頭",
|
||||
kv_description: "所有請求可以使用自定義變數",
|
||||
copy: "複製場景",
|
||||
delete: "删除場景"
|
||||
},
|
||||
request: {
|
||||
copy: "複製請求",
|
||||
delete: "删除請求",
|
||||
input_name: "請輸入請求名稱",
|
||||
name: "請求名稱",
|
||||
method: "請求方法",
|
||||
|
|
Loading…
Reference in New Issue