refactor: 创建测试时选中默认项目

This commit is contained in:
shiziyuan9527 2020-12-15 15:08:59 +08:00
parent 18310dcec3
commit 66b9962919
2 changed files with 8 additions and 37 deletions

View File

@ -8,10 +8,7 @@
<el-input :disabled="isReadOnly" class="test-name" v-model="test.name" maxlength="60"
:placeholder="$t('api_test.input_name')"
show-word-limit>
<el-select filterable class="test-project" v-model="test.projectId" slot="prepend"
:placeholder="$t('api_test.select_project')">
<el-option v-for="project in projects" :key="project.id" :label="project.name" :value="project.id"/>
</el-select>
<template slot="prepend">测试名称</template>
</el-input>
<el-tooltip :content="'Ctrl + S'"
@ -80,7 +77,7 @@ import MsApiScenarioConfig from "./components/ApiScenarioConfig";
import {Scenario, Test} from "./model/ScenarioModel"
import MsApiReportStatus from "../report/ApiReportStatus";
import MsApiReportDialog from "./ApiReportDialog";
import {checkoutTestManagerOrTestUser, downloadFile, getUUID} from "@/common/js/utils";
import {checkoutTestManagerOrTestUser, downloadFile, getCurrentProjectID, getUUID} from "@/common/js/utils";
import MsScheduleConfig from "../../common/components/MsScheduleConfig";
import ApiImport from "./components/import/ApiImport";
import {ApiEvent, LIST_CHANGE} from "@/business/components/common/head/ListEvent";
@ -124,8 +121,6 @@ export default {
methods: {
init() {
let projectId;
this.isReadOnly = !checkoutTestManagerOrTestUser();
if (this.id) {
@ -137,14 +132,8 @@ export default {
if (this.$refs.config) {
this.$refs.config.reset();
}
//
projectId = this.$store.state.common.projectId;
}
this.result = this.$get("/project/listAll", response => {
this.projects = response.data;
//
if (projectId) this.test.projectId = projectId;
})
this.test.projectId = getCurrentProjectID();
},
updateReference() {
let updateIds = [];
@ -318,7 +307,6 @@ export default {
break;
case "performance":
this.$store.commit('setTest', {
projectId: this.test.projectId,
name: this.test.name,
jmx: this.test.toJMX()
})

View File

@ -8,17 +8,7 @@
class="input-with-select"
maxlength="30" show-word-limit
>
<template v-slot:prepend>
<el-select filterable v-model="test.projectId"
:placeholder="$t('load_test.select_project')">
<el-option
v-for="item in projects"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</template>
<template slot="prepend">测试名称</template>
</el-input>
</el-col>
<el-col :span="12" :offset="2">
@ -59,7 +49,7 @@ import PerformancePressureConfig from "./components/PerformancePressureConfig";
import PerformanceAdvancedConfig from "./components/PerformanceAdvancedConfig";
import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
import {checkoutTestManagerOrTestUser} from "@/common/js/utils";
import {checkoutTestManagerOrTestUser, getCurrentProjectID} from "@/common/js/utils";
import MsScheduleConfig from "../../common/components/MsScheduleConfig";
import {LIST_CHANGE, PerformanceEvent} from "@/business/components/common/head/ListEvent";
@ -77,7 +67,6 @@ export default {
return {
result: {},
test: {schedule: {}},
listProjectPath: "/project/listAll",
savePath: "/performance/save",
editPath: "/performance/edit",
runPath: "/performance/run",
@ -127,9 +116,6 @@ export default {
}
this.getTest(this.$route.params.testId);
},
activated() {
this.listProjects();
},
mounted() {
this.importAPITest();
},
@ -137,7 +123,6 @@ export default {
importAPITest() {
let apiTest = this.$store.state.api.test;
if (apiTest && apiTest.name) {
this.$set(this.test, "projectId", apiTest.projectId);
this.$set(this.test, "name", apiTest.name);
let blob = new Blob([apiTest.jmx.xml], {type: "application/octet-stream"});
let file = new File([blob], apiTest.jmx.name);
@ -160,11 +145,6 @@ export default {
});
}
},
listProjects() {
this.result = this.$get(this.listProjectPath, response => {
this.projects = response.data;
})
},
save() {
if (!this.validTest()) {
return;
@ -237,6 +217,9 @@ export default {
this.$router.push({path: '/performance/test/all'})
},
validTest() {
let currentProjectId = getCurrentProjectID();
this.test.projectId = currentProjectId;
if (!this.test.name) {
this.$error(this.$t('load_test.test_name_is_null'));
return false;