refactor: 执行测试之后跳转到报告查看页面

This commit is contained in:
Captain.B 2020-07-27 11:11:31 +08:00
parent 3841ff55d8
commit 62fa6fd9c6
9 changed files with 45 additions and 20 deletions

View File

@ -14,11 +14,11 @@
</el-breadcrumb> </el-breadcrumb>
</el-row> </el-row>
<el-row class="ms-report-view-btns"> <el-row class="ms-report-view-btns">
<el-button :disabled="isReadOnly || status !== 'Running'" type="primary" plain size="mini" <el-button :disabled="isReadOnly || report.status !== 'Running'" type="primary" plain size="mini"
@click="stopTest(reportId)"> @click="stopTest(reportId)">
{{$t('report.test_stop_now')}} {{$t('report.test_stop_now')}}
</el-button> </el-button>
<el-button :disabled="isReadOnly || status !== 'Completed'" type="success" plain size="mini" <el-button :disabled="isReadOnly || report.status !== 'Completed'" type="success" plain size="mini"
@click="rerun(testId)"> @click="rerun(testId)">
{{$t('report.test_execute_again')}} {{$t('report.test_execute_again')}}
</el-button> </el-button>
@ -156,7 +156,7 @@
this.$warning(this.$t('report.generation_error')); this.$warning(this.$t('report.generation_error'));
break; break;
case 'Starting': case 'Starting':
this.$warning(this.$t('report.start_status')); this.$alert(this.$t('report.start_status'));
break; break;
case 'Reporting': case 'Reporting':
case 'Running': case 'Running':
@ -190,26 +190,32 @@
cancelButtonText: this.$t('commons.cancel'), cancelButtonText: this.$t('commons.cancel'),
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.result = this.$post('/performance/run', {id: testId, triggerMode: 'MANUAL'}, () => { this.result = this.$post('/performance/run', {id: testId, triggerMode: 'MANUAL'}, (response) => {
this.$success(this.$t('load_test.is_running')) this.reportId = response.data;
this.$router.push({path: '/performance/report/all'}) this.$router.push({path: '/performance/report/view/' + this.reportId})
// socket
this.initWebSocket();
}) })
}).catch(() => { }).catch(() => {
}); });
}, },
onOpen() { onOpen() {
window.console.log("open WebSocket"); window.console.log("socket opening.");
}, },
onError(e) { onError(e) {
window.console.error(e) window.console.error(e)
}, },
onMessage(e) { onMessage(e) {
this.$set(this.report, "refresh", e.data); // this.$set(this.report, "refresh", e.data); //
this.$set(this.report, "status", 'Running');
this.initReportTimeInfo(); this.initReportTimeInfo();
window.console.log('receive a message:', e.data);
}, },
onClose(e) { onClose(e) {
this.$set(this.report, "refresh", e.data); // this.$set(this.report, "refresh", Math.random()); //
this.$set(this.report, "status", 'Completed');
this.initReportTimeInfo(); this.initReportTimeInfo();
window.console.log("socket closed.");
} }
}, },
created() { created() {

View File

@ -153,6 +153,9 @@
watch: { watch: {
report: { report: {
handler(val) { handler(val) {
if (!val.status || !val.id) {
return;
}
let status = val.status; let status = val.status;
this.id = val.id; this.id = val.id;
if (status === "Completed" || status === "Running") { if (status === "Completed" || status === "Running") {

View File

@ -80,6 +80,9 @@
watch: { watch: {
report: { report: {
handler(val) { handler(val) {
if (!val.status || !val.id) {
return;
}
let status = val.status; let status = val.status;
this.id = val.id; this.id = val.id;
if (status === "Completed" || status === "Running") { if (status === "Completed" || status === "Running") {

View File

@ -162,6 +162,9 @@
watch: { watch: {
report: { report: {
handler(val){ handler(val){
if (!val.status || !val.id) {
return;
}
let status = val.status; let status = val.status;
this.id = val.id; this.id = val.id;
if (status === "Completed" || status === "Running") { if (status === "Completed" || status === "Running") {

View File

@ -325,6 +325,9 @@
watch: { watch: {
report: { report: {
handler(val) { handler(val) {
if (!val.status || !val.id) {
return;
}
let status = val.status; let status = val.status;
this.id = val.id; this.id = val.id;
if (status === "Completed" || status === "Running") { if (status === "Completed" || status === "Running") {

View File

@ -4,11 +4,13 @@
<el-card v-loading="result.loading"> <el-card v-loading="result.loading">
<el-row> <el-row>
<el-col :span="10"> <el-col :span="10">
<el-input :disabled="isReadOnly" :placeholder="$t('load_test.input_name')" v-model="testPlan.name" class="input-with-select" <el-input :disabled="isReadOnly" :placeholder="$t('load_test.input_name')" v-model="testPlan.name"
class="input-with-select"
maxlength="30" show-word-limit maxlength="30" show-word-limit
> >
<template v-slot:prepend> <template v-slot:prepend>
<el-select :disabled="isReadOnly" v-model="testPlan.projectId" :placeholder="$t('load_test.select_project')"> <el-select :disabled="isReadOnly" v-model="testPlan.projectId"
:placeholder="$t('load_test.select_project')">
<el-option <el-option
v-for="item in projects" v-for="item in projects"
:key="item.id" :key="item.id"
@ -21,10 +23,13 @@
</el-col> </el-col>
<el-col :span="12" :offset="2"> <el-col :span="12" :offset="2">
<el-button :disabled="isReadOnly" type="primary" plain @click="save">{{$t('commons.save')}}</el-button> <el-button :disabled="isReadOnly" type="primary" plain @click="save">{{$t('commons.save')}}</el-button>
<el-button :disabled="isReadOnly" type="primary" plain @click="saveAndRun">{{$t('load_test.save_and_run')}}</el-button> <el-button :disabled="isReadOnly" type="primary" plain @click="saveAndRun">
{{$t('load_test.save_and_run')}}
</el-button>
<el-button :disabled="isReadOnly" type="warning" plain @click="cancel">{{$t('commons.cancel')}}</el-button> <el-button :disabled="isReadOnly" type="warning" plain @click="cancel">{{$t('commons.cancel')}}</el-button>
<ms-schedule-config :schedule="testPlan.schedule" :save="saveCronExpression" @scheduleChange="saveSchedule" :check-open="checkScheduleEdit" :custom-validate="durationValidate"/> <ms-schedule-config :schedule="testPlan.schedule" :save="saveCronExpression" @scheduleChange="saveSchedule"
:check-open="checkScheduleEdit" :custom-validate="durationValidate"/>
</el-col> </el-col>
</el-row> </el-row>
@ -34,7 +39,8 @@
<performance-basic-config :is-read-only="isReadOnly" :test-plan="testPlan" ref="basicConfig"/> <performance-basic-config :is-read-only="isReadOnly" :test-plan="testPlan" ref="basicConfig"/>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('load_test.pressure_config')"> <el-tab-pane :label="$t('load_test.pressure_config')">
<performance-pressure-config :is-read-only="isReadOnly" :test-plan="testPlan" :test-id="testId" ref="pressureConfig" @changeActive="changeTabActive"/> <performance-pressure-config :is-read-only="isReadOnly" :test-plan="testPlan" :test-id="testId"
ref="pressureConfig" @changeActive="changeTabActive"/>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('load_test.advanced_config')" class="advanced-config"> <el-tab-pane :label="$t('load_test.advanced_config')" class="advanced-config">
<performance-advanced-config :read-only="isReadOnly" :test-id="testId" ref="advancedConfig"/> <performance-advanced-config :read-only="isReadOnly" :test-id="testId" ref="advancedConfig"/>
@ -67,7 +73,7 @@
data() { data() {
return { return {
result: {}, result: {},
testPlan: {schedule:{}}, testPlan: {schedule: {}},
listProjectPath: "/project/listAll", listProjectPath: "/project/listAll",
savePath: "/performance/save", savePath: "/performance/save",
editPath: "/performance/edit", editPath: "/performance/edit",
@ -177,9 +183,10 @@
this.result = this.$request(options, (response) => { this.result = this.$request(options, (response) => {
this.testPlan.id = response.data; this.testPlan.id = response.data;
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.result = this.$post(this.runPath, {id: this.testPlan.id, triggerMode: 'MANUAL'}, () => { this.result = this.$post(this.runPath, {id: this.testPlan.id, triggerMode: 'MANUAL'}, (response) => {
this.$success(this.$t('load_test.is_running')) this.$success(this.$t('load_test.is_running'))
this.$router.push({path: '/performance/report/all'}) let reportId = response.data;
this.$router.push({path: '/performance/report/view/' + reportId})
}) })
}); });
}, },
@ -249,7 +256,7 @@
return true; return true;
}, },
changeTabActive(activeName) { changeTabActive(activeName) {
this.$nextTick(()=> { this.$nextTick(() => {
this.active = activeName; this.active = activeName;
}); });
}, },

View File

@ -258,7 +258,7 @@ export default {
generation_error: 'Report generation error, cannot be viewed!', generation_error: 'Report generation error, cannot be viewed!',
being_generated: 'Report is being generated...', being_generated: 'Report is being generated...',
delete_confirm: 'Confirm delete: ', delete_confirm: 'Confirm delete: ',
start_status: 'The test is starting, please check the report later!', start_status: 'The test is in the beginning state, we will automatically display it on the page after we generate the report!',
run_status: 'The test is running, please check the report later', run_status: 'The test is running, please check the report later',
user_name: 'Creator', user_name: 'Creator',
project_name: 'Project Name' project_name: 'Project Name'

View File

@ -256,7 +256,7 @@ export default {
generation_error: '报告生成错误,无法查看!', generation_error: '报告生成错误,无法查看!',
being_generated: '报告正在生成中...', being_generated: '报告正在生成中...',
delete_confirm: '确认删除报告: ', delete_confirm: '确认删除报告: ',
start_status: '测试处于开始状态,请稍后查看报告', start_status: '测试处于开始状态, 我们生成报告后会自动展示到页面上',
run_status: '测试处于运行状态,请稍后查看报告!', run_status: '测试处于运行状态,请稍后查看报告!',
user_name: '创建人', user_name: '创建人',
project_name: '所属项目', project_name: '所属项目',

View File

@ -256,7 +256,7 @@ export default {
generation_error: '報告生成錯誤,無法查看!', generation_error: '報告生成錯誤,無法查看!',
being_generated: '報告正在生成中...', being_generated: '報告正在生成中...',
delete_confirm: '確認刪除報告: ', delete_confirm: '確認刪除報告: ',
start_status: '測試處於開始狀態,請稍後查看報告', start_status: '測試處於開始狀態, 我們生成報告後會自動展示到頁面上',
run_status: '測試處於運行狀態,請稍後查看報告!', run_status: '測試處於運行狀態,請稍後查看報告!',
user_name: '創建人', user_name: '創建人',
project_name: '所屬項目' project_name: '所屬項目'