TestCaseReportView.vue 6.2 KB
Newer Older
C
chenjianxing 已提交
1 2 3 4 5 6
<template>
  <div>

    <el-drawer
      :visible.sync="showDialog"
      :with-header="false"
7
      :modal-append-to-body="false"
C
chenjianxing 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21
      size="100%"
      ref="drawer"
      v-loading="result.loading">
      <template v-slot:default="scope">

        <el-row type="flex" class="head-bar">
          <el-col :span="12">
            <div class="name-edit">
              <el-button plain size="mini" icon="el-icon-back" @click="handleClose">{{$t('test_track.return')}}</el-button>
              &nbsp;
              <span>{{report.name}}</span>
            </div>
          </el-col>
          <el-col :span="12" class="head-right">
C
chenjianxing 已提交
22 23
            <el-button plain size="mini" @click="handleSave">{{$t('commons.save')}}</el-button>
            <el-button plain size="mini" @click="handleEdit">{{$t('test_track.plan_view.edit_component')}}</el-button>
C
chenjianxing 已提交
24 25 26 27 28 29
          </el-col>
        </el-row>

        <div class="container">
          <el-main>
            <div class="preview" v-for="item in previews" :key="item.id">
C
chenjianxing 已提交
30
              <template-component :isReportView="true" :metric="metric" :preview="item"/>
C
chenjianxing 已提交
31 32 33 34 35 36
            </div>
          </el-main>
        </div>
      </template>
    </el-drawer>

C
chenjianxing 已提交
37
    <test-case-report-template-edit :metric="metric" ref="templateEdit" @refresh="getReport"/>
C
chenjianxing 已提交
38 39 40 41 42

  </div>
</template>

<script>
C
chenjianxing 已提交
43 44 45 46 47 48 49
  import {jsonToMap, mapToJson} from "../../../../../../../common/js/utils";
    import BaseInfoComponent from "./TemplateComponent/BaseInfoComponent";
    import TestResultChartComponent from "./TemplateComponent/TestResultChartComponent";
    import TestResultComponent from "./TemplateComponent/TestResultComponent";
    import RichTextComponent from "./TemplateComponent/RichTextComponent";
    import TestCaseReportTemplateEdit from "./TestCaseReportTemplateEdit";
    import TemplateComponent from "./TemplateComponent/TemplateComponent";
C
chenjianxing 已提交
50 51 52 53

    export default {
      name: "TestCaseReportView",
      components: {
C
chenjianxing 已提交
54
        TemplateComponent,
C
chenjianxing 已提交
55 56 57 58 59 60 61 62 63
        TestCaseReportTemplateEdit,
        RichTextComponent, TestResultComponent, TestResultChartComponent, BaseInfoComponent},
      data() {
        return {
          result: {},
          showDialog: false,
          previews: [],
          report: {},
          reportId: '',
C
chenjianxing 已提交
64
          metric: {},
C
chenjianxing 已提交
65 66
          componentMap: new Map(
            [
C
chenjianxing 已提交
67 68 69 70
              [1, { name: this.$t('test_track.plan_view.base_info'), id: 1 , type: 'system'}],
              [2, { name: this.$t('test_track.plan_view.test_result'), id: 2 , type: 'system'}],
              [3, { name: this.$t('test_track.plan_view.result_distribution'), id: 3 ,type: 'system'}],
              [4, { name: this.$t('test_track.plan_view.custom_component'), id: 4 ,type: 'custom'}]
C
chenjianxing 已提交
71 72 73 74
            ]
          )
        }
      },
C
chenjianxing 已提交
75 76 77 78 79
      props: {
        planId: {
          type: String
        }
      },
C
chenjianxing 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
      methods: {
        open(id) {
          if (id) {
            this.reportId = id;
          }
          this.getReport();
          this.showDialog = true;
        },
        getReport() {
          this.result = this.$get('/case/report/get/' + this.reportId, response => {
            this.report = response.data;
            this.report.content = JSON.parse(response.data.content);
            if (this.report.content.customComponent) {
              this.report.content.customComponent = jsonToMap(this.report.content.customComponent);
            }
C
chenjianxing 已提交
95
            this.getMetric();
C
chenjianxing 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
            this.initPreviews();
          });
        },
        initPreviews() {
          this.previews = [];
          this.report.content.components.forEach(item => {
            let preview = this.componentMap.get(item);
            if (preview && preview.type != 'custom') {
              this.previews.push(preview);
            } else {
              if (this.report.content.customComponent) {
                let customComponent = this.report.content.customComponent.get(item.toString());
                if (customComponent) {
                  this.previews.push({id: item, title: customComponent.title, content: customComponent.content});
                }
              }
            }
          });
        },
        handleClose() {
          this.showDialog = false;
        },
        handleEdit() {
          this.$refs.templateEdit.open(this.reportId, true);
C
chenjianxing 已提交
120
        },
C
chenjianxing 已提交
121 122 123 124
        handleSave() {
          let param = {};
          this.buildParam(param);
          this.result = this.$post('/case/report/edit', param, () =>{
C
chenjianxing 已提交
125
            this.$success(this.$t('commons.save_success'));
C
chenjianxing 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
          });
        },
        buildParam(param) {
          let content = {};
          content.components = [];
          this.previews.forEach(item => {
            content.components.push(item.id);
            if (!this.componentMap.get(item.id)) {
              content.customComponent = new Map();
              content.customComponent.set(item.id, {title: item.title, content: item.content})
            }
          });
          param.name = this.report.name;
          if (content.customComponent) {
            content.customComponent = mapToJson(content.customComponent);
          }
          param.content = JSON.stringify(content);
          param.id = this.report.id;
          if (this.metric.startTime) {
            param.startTime = this.metric.startTime.getTime();
          }
          if (this.metric.endTime) {
            param.endTime = this.metric.endTime.getTime();
          }
        },
C
chenjianxing 已提交
151
        getMetric() {
C
chenjianxing 已提交
152
          this.result = this.$get('/test/plan/get/metric/' + this.planId, response => {
C
chenjianxing 已提交
153
            this.metric = response.data;
C
chenjianxing 已提交
154 155 156 157 158 159
            if (this.report.startTime) {
              this.metric.startTime = new Date(this.report.startTime);
            }
            if (this.report.endTime) {
              this.metric.endTime = new Date(this.report.endTime);
            }
C
chenjianxing 已提交
160
          });
C
chenjianxing 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
        }
      }
    }
</script>

<style scoped>

  .el-main {
    height: calc(100vh - 70px);
    width: 100%;
  }

  .head-bar {
    background: white;
    height: 45px;
    line-height: 45px;
    padding: 0 10px;
    border: 1px solid #EBEEF5;
    box-shadow: 0 0 2px 0 rgba(31,31,31,0.15), 0 1px 2px 0 rgba(31,31,31,0.15);
  }

  .container {
    height: 100vh;
    background: #F5F5F5;
  }

  .el-card {
    width: 70%;
    margin: 5px auto;
  }

  .head-right {
    text-align: right;
  }

</style>