This commit is contained in:
chenjianxing 2020-08-25 14:15:24 +08:00
commit dc64026250
2 changed files with 149 additions and 116 deletions

View File

@ -12,7 +12,7 @@
</template> </template>
<one-click-operation ref="OneClickOperation" :select-ids="selectIds" :select-names="selectNames" <one-click-operation ref="OneClickOperation" :select-ids="selectIds" :select-names="selectNames"
:select-project-names="selectProjectNames"></one-click-operation> :select-project-names="selectProjectNames" @refresh="init()"></one-click-operation>
<el-table border :data="tableData" class="adjust-table table-content" @sort-change="sort" <el-table border :data="tableData" class="adjust-table table-content" @sort-change="sort"
@row-click="handleView" @row-click="handleView"

View File

@ -21,13 +21,14 @@
</template> </template>
<script> <script>
import MsDialogFooter from '../../common/components/MsDialogFooter' import MsDialogFooter from '../../common/components/MsDialogFooter'
import {Test} from "./model/ScenarioModel"; import {Test} from "./model/ScenarioModel"
import MsApiScenarioConfig from "./components/ApiScenarioConfig"; import MsApiScenarioConfig from "./components/ApiScenarioConfig";
import MsApiReportStatus from "../report/ApiReportStatus"; import MsApiReportStatus from "../report/ApiReportStatus";
import MsApiReportDialog from "./ApiReportDialog"; import MsApiReportDialog from "./ApiReportDialog";
export default {
export default {
name: "OneClickOperation", name: "OneClickOperation",
components: { components: {
MsApiReportDialog, MsApiReportStatus, MsApiScenarioConfig, MsDialogFooter MsApiReportDialog, MsApiReportStatus, MsApiScenarioConfig, MsDialogFooter
@ -38,6 +39,7 @@ export default {
test: null, test: null,
tests: [], tests: [],
ruleForm: {}, ruleForm: {},
change: false,
rule: { rule: {
testName: [ testName: [
{required: true, message: this.$t('api_test.input_name'), trigger: 'blur'}, {required: true, message: this.$t('api_test.input_name'), trigger: 'blur'},
@ -45,6 +47,15 @@ export default {
} }
}; };
}, },
watch: {
test: {
handler: function () {
this.change = true;
},
deep: true
}
},
props: { props: {
selectIds: { selectIds: {
type: Set type: Set
@ -62,12 +73,16 @@ export default {
}, },
checkedSaveAndRunTest() { checkedSaveAndRunTest() {
if (this.selectNames.has(this.ruleForm.testName)) { if (this.selectNames.has(this.ruleForm.testName)) {
this.selectIds.clear()
this.$warning(this.$t('load_test.already_exists')); this.$warning(this.$t('load_test.already_exists'));
this.oneClickOperationVisible = false; this.oneClickOperationVisible = false;
this.$emit('refresh')
} else { } else {
if (this.selectProjectNames.size > 1) { if (this.selectProjectNames.size > 1) {
this.selectIds.clear()
this.$warning(this.$t('load_test.same_project_test')); this.$warning(this.$t('load_test.same_project_test'));
this.oneClickOperationVisible = false; this.oneClickOperationVisible = false;
this.$emit('refresh')
} else { } else {
for (let x of this.selectIds) { for (let x of this.selectIds) {
this.getTest(x) this.getTest(x)
@ -75,12 +90,33 @@ export default {
} }
} }
}, },
_getEnvironmentAndRunTest: function (item) {
let count = 0;
this.result = this.$get('/api/environment/list/' + item.projectId, response => {
let environments = response.data;
let environmentMap = new Map();
environments.forEach(environment => {
environmentMap.set(environment.id, environment);
});
this.test.scenarioDefinition.forEach(scenario => {
if (scenario.environmentId) {
scenario.environment = environmentMap.get(scenario.environmentId);
}
}
)
this.tests = [];
this.saveRunTest();
this.oneClickOperationVisible = false;
this.$emit('refresh')
});
},
getTest(id) { getTest(id) {
this.result = this.$get("/api/get/" + id, response => { this.result = this.$get("/api/get/" + id, response => {
if (response.data) { if (response.data) {
let item = response.data; let item = response.data;
this.tests.push(item); this.tests.push(item);
let test = new Test({ let test = new Test({
id: item.id,
projectId: item.projectId, projectId: item.projectId,
name: this.ruleForm.testName, name: this.ruleForm.testName,
scenarioDefinition: JSON.parse(item.scenarioDefinition), scenarioDefinition: JSON.parse(item.scenarioDefinition),
@ -89,28 +125,24 @@ export default {
this.test = this.test || test; this.test = this.test || test;
if (this.tests.length > 1) { if (this.tests.length > 1) {
this.test.scenarioDefinition = this.test.scenarioDefinition.concat(test.scenarioDefinition); this.test.scenarioDefinition = this.test.scenarioDefinition.concat(test.scenarioDefinition);
} }
if (this.tests.length === this.selectIds.size) { if (this.tests.length === this.selectIds.size) {
this.tests = []; this._getEnvironmentAndRunTest(item);
this.saveRunTest();
this.oneClickOperationVisible = false;
} }
} }
}); });
}, },
saveRunTest() { saveRunTest() {
this.change = false;
this.save(() => { this.save(() => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.runTest(); this.runTest();
}) })
}, },
save(callback) { save(callback) {
this.change = false;
let url = "/api/create"; let url = "/api/create";
this.result = this.$request(this.getOptions(url), () => { this.result = this.$request(this.getOptions(url), () => {
this.create = false;
if (callback) callback(); if (callback) callback();
}); });
}, },
@ -120,6 +152,7 @@ export default {
this.$router.push({ this.$router.push({
path: '/api/report/view/' + response.data path: '/api/report/view/' + response.data
}) })
this.test = ""
}); });
}, },
getOptions(url) { getOptions(url) {
@ -144,7 +177,7 @@ export default {
this.ruleForm = {} this.ruleForm = {}
}, },
} }
} }
</script> </script>
<style scoped> <style scoped>