refactor(接口自动化): 场景变量增加批量添加

This commit is contained in:
Captain.B 2021-07-06 16:27:46 +08:00 committed by 刘瑞斌
parent f3d1a29d6e
commit e1e98a8a24
1 changed files with 245 additions and 221 deletions

View File

@ -10,9 +10,11 @@
<div>
<el-row style="margin-bottom: 10px">
<div style="float: left">
<el-input :placeholder="$t('commons.search_by_name')" v-model="selectVariable" size="small" @change="filter"
<el-input :placeholder="$t('commons.search_by_name')" v-model="selectVariable" size="small"
@change="filter"
@keyup.enter="filter">
<el-select v-model="searchType" slot="prepend" :placeholder="$t('test_resource_pool.type')" style="width: 90px" @change="filter">
<el-select v-model="searchType" slot="prepend" :placeholder="$t('test_resource_pool.type')"
style="width: 90px" @change="filter">
<el-option value="CONSTANT" :label="$t('api_test.automation.constant')"></el-option>
<el-option value="LIST" :label="$t('test_track.case.list')"></el-option>
<el-option value="CSV" label="CSV"></el-option>
@ -21,7 +23,6 @@
</el-select>
</el-input>
</div>
<div style="float: right">
<el-dropdown split-button type="primary" @command="handleClick" @click="handleClick('CONSTANT')"
size="small" style="margin-left: 10px">
@ -38,18 +39,25 @@
</el-button>
</div>
<div style="float: right; margin-top: 10px">
<el-link @click="batchAddParameter" type="primary" :disabled="disabled">
{{ $t("commons.batch_add") }}
</el-link>
</div>
</el-row>
<el-row>
<el-col :span="12">
<div style="border:1px #DCDFE6 solid; min-height: 400px;border-radius: 4px ;width: 100% ;">
<el-table ref="table" border :data="variables" class="adjust-table" :row-class-name="tableRowClassName"
<el-table ref="table" border :data="variables" class="adjust-table"
:row-class-name="tableRowClassName"
@select-all="select"
@select="select"
@row-click="edit"
v-loading="loading" height="400px">
<el-table-column type="selection" width="38"/>
<el-table-column prop="num" label="ID" sortable width="60"/>
<el-table-column prop="name" :label="$t('api_test.variable_name')" sortable show-overflow-tooltip/>
<el-table-column prop="name" :label="$t('api_test.variable_name')" sortable
show-overflow-tooltip/>
<el-table-column prop="type" :label="$t('test_track.case.type')" width="70">
<template v-slot:default="scope">
<span>{{ types.get(scope.row.type) }}</span>
@ -57,6 +65,7 @@
</el-table-column>
<el-table-column prop="value" :label="$t('api_test.value')" show-overflow-tooltip/>
</el-table>
<batch-add-parameter @batchSave="batchSaveParameter" ref="batchAddParameter"/>
</div>
</el-col>
<el-col :span="12">
@ -82,12 +91,13 @@
</span>
</el-tooltip>
<el-row>
<el-link class="ms-variable-link" @click="batchAdd" style="color: #783887" :disabled="disabled"> {{ $t("commons.batch_add") }}
<el-link class="ms-variable-link" @click="batchAddHeader" type="primary" :disabled="disabled">
{{ $t("commons.batch_add") }}
</el-link>
</el-row>
<div style="min-height: 400px">
<ms-api-key-value :items="headers" :suggestions="headerSuggestions"/>
<batch-add-parameter @batchSave="batchSave" ref="batchAddParameter"/>
<batch-add-parameter @batchSave="batchSaveHeader" ref="batchAddHeader"/>
</div>
</el-tab-pane>
</el-tabs>
@ -154,14 +164,16 @@
total: 0,
headerSuggestions: REQUEST_HEADERS,
disabled: false,
}
};
},
methods: {
batchAdd() {
batchAddParameter() {
this.$refs.batchAddParameter.open();
},
batchSave(data) {
if (data) {
batchAddHeader() {
this.$refs.batchAddHeader.open();
},
_handleBatchVars(data) {
let params = data.split("\n");
let keyValues = [];
params.forEach(item => {
@ -182,10 +194,24 @@
enable: true,
contentType: "text/plain"
}));
})
});
return keyValues;
},
batchSaveHeader(data) {
if (data) {
let keyValues = this._handleBatchVars(data);
keyValues.forEach(item => {
this.headers.unshift(item);
})
});
}
},
batchSaveParameter(data) {
if (data) {
let keyValues = this._handleBatchVars(data);
keyValues.forEach(item => {
item.type = 'CONSTANT';
this.addParameters(item);
});
}
},
handleClick(command) {
@ -215,13 +241,13 @@
this.variables.forEach(item => {
item.num = index;
index++;
})
});
},
select(selection) {
this.selection = selection.map(s => s.id);
},
isSelect(row) {
return this.selection.includes(row.id)
return this.selection.includes(row.id);
},
open: function (variables, headers, disabled) {
if (variables) {
@ -246,7 +272,7 @@
if (item.name && item.name != "") {
saveVariables.push(item);
}
})
});
this.selectVariable = "";
this.searchType = "";
this.$emit('setVariables', saveVariables, this.headers);
@ -260,7 +286,7 @@
ids.forEach(row => {
const index = this.variables.findIndex(d => d.id === row);
this.variables.splice(index, 1);
})
});
this.selection = [];
this.editData = {type: "CONSTANT"};
},
@ -273,15 +299,13 @@
} else {
item.hidden = undefined;
}
}
else if (this.selectVariable && this.selectVariable != "") {
} else if (this.selectVariable && this.selectVariable != "") {
if (item.name && item.name.toLowerCase().indexOf(this.selectVariable.toLowerCase()) == -1) {
item.hidden = true;
} else {
item.hidden = undefined;
}
}
else if (this.searchType && this.searchType != "") {
} else if (this.searchType && this.searchType != "") {
if (item.type && item.type.toLowerCase().indexOf(this.searchType.toLowerCase()) == -1) {
item.hidden = true;
} else {
@ -291,7 +315,7 @@
item.hidden = undefined;
}
datas.push(item);
})
});
this.variables = datas;
},
createFilter(queryString) {
@ -300,7 +324,7 @@
};
},
}
}
};
</script>
<style>