refactor(接口测试): 优化创建场景状态是空的缺陷 (#15836)

--bug=1014924 --user=王孝刚 【接口测试】场景-更多操作-创建场景,状态是空的
https://www.tapd.cn/55049933/s/1202822

Co-authored-by: wxg0103 <727495428@qq.com>
This commit is contained in:
MeterSphere Bot 2022-07-15 17:25:00 +08:00 committed by GitHub
parent 6ab23d2224
commit 787c529490
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 226 additions and 221 deletions

View File

@ -58,85 +58,86 @@
</template>
<script>
import {WORKSPACE_ID} from '@/common/js/constants';
import {getCurrentProjectID, getCurrentUser, getUUID} from "@/common/js/utils";
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
import {saveScenario} from "@/business/components/api/automation/api-automation";
import {getCurrentProjectID, getCurrentUser, getUUID} from "@/common/js/utils";
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
import {saveScenario} from "@/business/components/api/automation/api-automation";
export default {
name: "MsAddBasisScenario",
components: {MsDialogFooter},
props: {},
data() {
return {
scenarioForm: {follows:[]},
visible: false,
currentModule: {},
userOptions: [],
rule: {
name: [
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{max: 100, message: this.$t('test_track.length_less_than') + '100', trigger: 'blur'}
],
principal: [{
required: true,
message: this.$t('api_test.automation.scenario.select_principal'),
trigger: 'change'
}],
},
}
},
computed: {
projectId() {
return getCurrentProjectID();
export default {
name: "MsAddBasisScenario",
components: {MsDialogFooter},
props: {},
data() {
return {
scenarioForm: {follows: []},
visible: false,
currentModule: {},
userOptions: [],
rule: {
name: [
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{max: 100, message: this.$t('test_track.length_less_than') + '100', trigger: 'blur'}
],
principal: [{
required: true,
message: this.$t('api_test.automation.scenario.select_principal'),
trigger: 'change'
}],
},
}
},
computed: {
projectId() {
return getCurrentProjectID();
},
methods: {
saveScenario(saveAs) {
this.$refs['scenarioForm'].validate((valid) => {
if (valid) {
let path = "/api/automation/create";
this.setParameter();
if (saveAs) {
this.scenarioForm.request = JSON.stringify(this.scenarioForm.request);
this.$emit('saveAsEdit', this.scenarioForm);
this.visible = false;
} else {
saveScenario(path, this.scenarioForm, [], this,(response) => {
this.$success(this.$t('commons.save_success'));
this.visible = false;
this.$emit('refresh');
});
}
},
methods: {
saveScenario(saveAs) {
this.$refs['scenarioForm'].validate((valid) => {
if (valid) {
let path = "/api/automation/create";
this.setParameter();
this.scenarioForm.status = 'Underway';
this.scenarioForm.level = 'P0';
if (saveAs) {
this.scenarioForm.request = JSON.stringify(this.scenarioForm.request);
this.$emit('saveAsEdit', this.scenarioForm);
this.visible = false;
} else {
return false;
saveScenario(path, this.scenarioForm, [], this, (response) => {
this.$success(this.$t('commons.save_success'));
this.visible = false;
this.$emit('refresh');
});
}
})
},
setParameter() {
this.scenarioForm.projectId = this.projectId;
this.scenarioForm.id = getUUID().substring(0, 8);
this.scenarioForm.protocol = this.currentProtocol;
if (this.currentModule && this.currentModule.id != "root") {
this.scenarioForm.modulePath = this.currentModule.method !== undefined ? this.currentModule.method : null;
this.scenarioForm.apiScenarioModuleId = this.currentModule.id;
} else {
this.scenarioForm.modulePath = this.$t("commons.module_title");
this.scenarioForm.apiScenarioModuleId = "default-module";
return false;
}
},
getMaintainerOptions() {
this.$get('/user/project/member/list', response => {
this.userOptions = response.data;
});
},
open(currentModule) {
this.scenarioForm = {principal: getCurrentUser().id};
this.currentModule = currentModule;
this.getMaintainerOptions();
this.visible = true;
})
},
setParameter() {
this.scenarioForm.projectId = this.projectId;
this.scenarioForm.id = getUUID().substring(0, 8);
this.scenarioForm.protocol = this.currentProtocol;
if (this.currentModule && this.currentModule.id != "root") {
this.scenarioForm.modulePath = this.currentModule.method !== undefined ? this.currentModule.method : null;
this.scenarioForm.apiScenarioModuleId = this.currentModule.id;
} else {
this.scenarioForm.modulePath = this.$t("commons.module_title");
this.scenarioForm.apiScenarioModuleId = "default-module";
}
},
getMaintainerOptions() {
this.$get('/user/project/member/list', response => {
this.userOptions = response.data;
});
},
open(currentModule) {
this.scenarioForm = {principal: getCurrentUser().id};
this.currentModule = currentModule;
this.getMaintainerOptions();
this.visible = true;
}
}
}
</script>

View File

@ -37,7 +37,7 @@
:rows="2" size="small"/>
</el-form-item>
<el-form-item class="create-tip">
{{$t('api_test.definition.create_tip')}}
{{ $t('api_test.definition.create_tip') }}
</el-form-item>
</el-form>
@ -56,164 +56,168 @@
</template>
<script>
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
import {WORKSPACE_ID} from '../../../../../../common/js/constants';
import {REQ_METHOD} from "../../model/JsonData";
import {getCurrentProjectID, getCurrentUser} from "../../../../../../common/js/utils";
import {createComponent, Request} from "../jmeter/components";
import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting";
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
import {REQ_METHOD} from "../../model/JsonData";
import {getCurrentProjectID, getCurrentUser} from "../../../../../../common/js/utils";
import {createComponent, Request} from "../jmeter/components";
import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting";
export default {
name: "MsAddBasisApi",
components: {MsDialogFooter},
props: {
currentProtocol: {
type: String,
default: "HTTP"
},
export default {
name: "MsAddBasisApi",
components: {MsDialogFooter},
props: {
currentProtocol: {
type: String,
default: "HTTP"
},
data() {
let validateURL = (rule, value, callback) => {
if (!this.httpForm.path.startsWith("/")) {
callback(this.$t('api_test.definition.request.path_valid_info'));
}
callback();
};
return {
httpForm: {environmentId: ""},
httpVisible: false,
currentModule: {},
maintainerOptions: [],
rule: {
name: [
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{max: 100, message: this.$t('test_track.length_less_than') + '100', trigger: 'blur'}
],
path: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}, {validator: validateURL, trigger: 'blur'}],
userId: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
},
value: REQ_METHOD[0].id,
options: REQ_METHOD,
},
data() {
let validateURL = (rule, value, callback) => {
if (!this.httpForm.path.startsWith("/")) {
callback(this.$t('api_test.definition.request.path_valid_info'));
}
},
computed: {
projectId() {
return getCurrentProjectID();
callback();
};
return {
httpForm: {environmentId: ""},
httpVisible: false,
currentModule: {},
maintainerOptions: [],
rule: {
name: [
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{max: 100, message: this.$t('test_track.length_less_than') + '100', trigger: 'blur'}
],
path: [{
required: true,
message: this.$t('api_test.definition.request.path_info'),
trigger: 'blur'
}, {validator: validateURL, trigger: 'blur'}],
userId: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
},
},
methods: {
compatibleHistory(stepArray) {
if (stepArray) {
for (let i in stepArray) {
if (!stepArray[i].clazzName) {
stepArray[i].clazzName = TYPE_TO_C.get(stepArray[i].type);
}
if (stepArray[i] && stepArray[i].authManager && !stepArray[i].authManager.clazzName) {
stepArray[i].authManager.clazzName = TYPE_TO_C.get(stepArray[i].authManager.type);
}
if (stepArray[i].hashTree && stepArray[i].hashTree.length > 0) {
this.compatibleHistory(stepArray[i].hashTree);
}
}
}
},
saveApi(saveAs) {
this.$refs['httpForm'].validate((valid) => {
if (valid) {
let bodyFiles = [];
let path = "/api/definition/create";
this.setParameter();
//
if (this.httpForm.request) {
this.httpForm.request.clazzName = TYPE_TO_C.get(this.httpForm.request.type);
this.compatibleHistory(this.httpForm.request.hashTree);
}
this.result = this.$fileUpload(path, null, bodyFiles, this.httpForm, () => {
this.httpVisible = false;
if (saveAs) {
this.httpForm.request = JSON.stringify(this.httpForm.request);
this.$emit('saveAsEdit', this.httpForm);
} else {
this.$emit('refresh');
}
});
} else {
return false;
}
})
},
setParameter() {
switch (this.currentProtocol) {
case Request.TYPES.SQL:
this.initSQL();
break;
case Request.TYPES.DUBBO:
this.initDUBBO();
break;
case Request.TYPES.TCP:
this.initTCP();
break;
default:
this.initHTTP();
break;
}
this.httpForm.bodyUploadIds = [];
this.httpForm.projectId = this.projectId;
this.httpForm.id = this.httpForm.request.id;
this.httpForm.protocol = this.currentProtocol;
this.httpForm.request.name = this.httpForm.name;
this.httpForm.request.protocol = this.currentProtocol;
if (this.currentProtocol === 'HTTP') {
this.httpForm.request.method = this.httpForm.method;
this.httpForm.request.path = this.httpForm.path;
}
if (this.currentModule != null && this.currentModule.id) {
this.httpForm.modulePath = this.currentModule.method != undefined ? this.currentModule.method : null;
this.httpForm.moduleId = this.currentModule.id;
} else {
this.httpForm.modulePath = this.$t("commons.module_title");
this.httpForm.moduleId = "default-module";
}
},
initHTTP() {
let request = createComponent("HTTPSamplerProxy");
request.path = this.httpForm.path;
this.httpForm.request = request;
},
initSQL() {
this.httpForm.method = Request.TYPES.SQL;
this.httpForm.request = createComponent("JDBCSampler");
},
initTCP() {
this.httpForm.method = Request.TYPES.TCP;
this.httpForm.request = createComponent("TCPSampler");
},
initDUBBO() {
this.httpForm.method = "dubbo://";
this.httpForm.request = createComponent("DubboSampler");
},
getMaintainerOptions() {
this.$get('/user/project/member/list', response => {
this.maintainerOptions = response.data;
});
},
open(currentModule) {
this.httpForm = {method: REQ_METHOD[0].id, userId: getCurrentUser().id};
this.currentModule = currentModule;
this.getMaintainerOptions();
this.httpVisible = true;
}
,
value: REQ_METHOD[0].id,
options: REQ_METHOD,
}
},
computed: {
projectId() {
return getCurrentProjectID();
},
},
methods: {
compatibleHistory(stepArray) {
if (stepArray) {
for (let i in stepArray) {
if (!stepArray[i].clazzName) {
stepArray[i].clazzName = TYPE_TO_C.get(stepArray[i].type);
}
if (stepArray[i] && stepArray[i].authManager && !stepArray[i].authManager.clazzName) {
stepArray[i].authManager.clazzName = TYPE_TO_C.get(stepArray[i].authManager.type);
}
if (stepArray[i].hashTree && stepArray[i].hashTree.length > 0) {
this.compatibleHistory(stepArray[i].hashTree);
}
}
}
},
saveApi(saveAs) {
this.$refs['httpForm'].validate((valid) => {
if (valid) {
let bodyFiles = [];
let path = "/api/definition/create";
this.setParameter();
this.httpForm.status = 'Underway';
//
if (this.httpForm.request) {
this.httpForm.request.clazzName = TYPE_TO_C.get(this.httpForm.request.type);
this.compatibleHistory(this.httpForm.request.hashTree);
}
this.result = this.$fileUpload(path, null, bodyFiles, this.httpForm, () => {
this.httpVisible = false;
if (saveAs) {
this.httpForm.request = JSON.stringify(this.httpForm.request);
this.$emit('saveAsEdit', this.httpForm);
} else {
this.$emit('refresh');
}
});
} else {
return false;
}
})
},
setParameter() {
switch (this.currentProtocol) {
case Request.TYPES.SQL:
this.initSQL();
break;
case Request.TYPES.DUBBO:
this.initDUBBO();
break;
case Request.TYPES.TCP:
this.initTCP();
break;
default:
this.initHTTP();
break;
}
this.httpForm.bodyUploadIds = [];
this.httpForm.projectId = this.projectId;
this.httpForm.id = this.httpForm.request.id;
this.httpForm.protocol = this.currentProtocol;
this.httpForm.request.name = this.httpForm.name;
this.httpForm.request.protocol = this.currentProtocol;
if (this.currentProtocol === 'HTTP') {
this.httpForm.request.method = this.httpForm.method;
this.httpForm.request.path = this.httpForm.path;
}
if (this.currentModule != null && this.currentModule.id) {
this.httpForm.modulePath = this.currentModule.method != undefined ? this.currentModule.method : null;
this.httpForm.moduleId = this.currentModule.id;
} else {
this.httpForm.modulePath = this.$t("commons.module_title");
this.httpForm.moduleId = "default-module";
}
},
initHTTP() {
let request = createComponent("HTTPSamplerProxy");
request.path = this.httpForm.path;
this.httpForm.request = request;
},
initSQL() {
this.httpForm.method = Request.TYPES.SQL;
this.httpForm.request = createComponent("JDBCSampler");
},
initTCP() {
this.httpForm.method = Request.TYPES.TCP;
this.httpForm.request = createComponent("TCPSampler");
},
initDUBBO() {
this.httpForm.method = "dubbo://";
this.httpForm.request = createComponent("DubboSampler");
},
getMaintainerOptions() {
this.$get('/user/project/member/list', response => {
this.maintainerOptions = response.data;
});
},
open(currentModule) {
this.httpForm = {method: REQ_METHOD[0].id, userId: getCurrentUser().id};
this.currentModule = currentModule;
this.getMaintainerOptions();
this.httpVisible = true;
}
,
}
}
</script>
<style scoped>
.create-tip {
color: #8c939d;
}
.create-tip {
color: #8c939d;
}
</style>