ApiTestList.vue 5.4 KB
Newer Older
H
haifeng414 已提交
1
<template>
H
haifeng414 已提交
2
  <div class="testplan-container" v-loading="result.loading">
H
haifeng414 已提交
3 4
    <div class="main-content">
      <el-card>
C
chenjianxing 已提交
5 6 7 8 9
        <template v-slot:header>
          <div>
            <el-row type="flex" justify="space-between" align="middle">
              <span class="title">{{$t('commons.test')}}</span>
              <span class="search">
C
i18n  
Captain.B 已提交
10 11 12
            <el-input type="text" size="small" :placeholder="$t('load_test.search_by_name')"
                      prefix-icon="el-icon-search"
                      maxlength="60"
H
haifeng414 已提交
13
                      v-model="condition" @change="search" clearable/>
H
haifeng414 已提交
14
          </span>
C
chenjianxing 已提交
15 16 17
            </el-row>
          </div>
        </template>
C
style  
Captain.B 已提交
18
        <el-table :data="tableData" class="test-content">
H
haifeng414 已提交
19 20
          <el-table-column
            prop="name"
C
i18n  
Captain.B 已提交
21
            :label="$t('commons.name')"
H
haifeng414 已提交
22 23 24 25 26
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="description"
C
i18n  
Captain.B 已提交
27
            :label="$t('commons.description')"
H
haifeng414 已提交
28 29 30 31
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="projectName"
C
i18n  
Captain.B 已提交
32
            :label="$t('load_test.project_name')"
H
haifeng414 已提交
33 34 35 36 37
            width="150"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            width="250"
C
i18n  
Captain.B 已提交
38
            :label="$t('commons.create_time')">
C
v-slot  
Captain.B 已提交
39
            <template v-slot:default="scope">
H
haifeng414 已提交
40 41 42 43 44
              <span>{{ scope.row.createTime | timestampFormatDate }}</span>
            </template>
          </el-table-column>
          <el-table-column
            width="250"
C
i18n  
Captain.B 已提交
45
            :label="$t('commons.update_time')">
C
v-slot  
Captain.B 已提交
46
            <template v-slot:default="scope">
H
haifeng414 已提交
47 48 49 50 51
              <span>{{ scope.row.updateTime | timestampFormatDate }}</span>
            </template>
          </el-table-column>
          <el-table-column
            width="150"
C
i18n  
Captain.B 已提交
52
            :label="$t('commons.operating')">
C
v-slot  
Captain.B 已提交
53
            <template v-slot:default="scope">
C
i18n  
Captain.B 已提交
54 55
              <el-button @click="handleEdit(scope.row)" type="primary" icon="el-icon-edit" size="mini" circle/>
              <el-button @click="handleDelete(scope.row)" type="danger" icon="el-icon-delete" size="mini" circle/>
H
haifeng414 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
            </template>
          </el-table-column>
        </el-table>
        <div>
          <el-row>
            <el-col :span="22" :offset="1">
              <div class="table-page">
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page.sync="currentPage"
                  :page-sizes="[5, 10, 20, 50, 100]"
                  :page-size="pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total">
                </el-pagination>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-card>
H
haifeng414 已提交
77 78 79 80 81 82 83 84
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
H
haifeng414 已提交
85
        result: {},
C
chenjianxing 已提交
86 87
        queryPath: "/api/list",
        deletePath: "/api/delete",
H
haifeng414 已提交
88
        condition: "",
C
Captain.B 已提交
89
        projectId: null,
H
haifeng414 已提交
90 91 92
        tableData: [],
        multipleSelection: [],
        currentPage: 1,
H
haifeng414 已提交
93
        pageSize: 5,
H
haifeng414 已提交
94
        total: 0,
H
haifeng414 已提交
95
        loading: false,
C
Captain.B 已提交
96
        testId: null,
H
haifeng414 已提交
97 98
      }
    },
C
Captain.B 已提交
99
    watch: {
C
Captain.B 已提交
100
      '$route'(to) {
C
Captain.B 已提交
101 102 103 104
        this.projectId = to.params.projectId;
        this.initTableData();
      }
    },
H
haifeng414 已提交
105
    created: function () {
C
Captain.B 已提交
106
      this.projectId = this.$route.params.projectId;
H
haifeng414 已提交
107 108 109 110
      this.initTableData();
    },
    methods: {
      initTableData() {
H
haifeng414 已提交
111
        let param = {
C
Captain.B 已提交
112
          name: this.condition,
H
haifeng414 已提交
113
        };
H
haifeng414 已提交
114

C
Captain.B 已提交
115 116 117 118
        if (this.projectId !== 'all') {
          param.projectId = this.projectId;
        }

H
haifeng414 已提交
119
        this.result = this.$post(this.buildPagePath(this.queryPath), param, response => {
H
haifeng414 已提交
120 121 122
          let data = response.data;
          this.total = data.itemCount;
          this.tableData = data.listObject;
C
Captain.B 已提交
123
        });
H
haifeng414 已提交
124
      },
H
haifeng414 已提交
125 126 127
      search() {
        this.initTableData();
      },
H
haifeng414 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
      buildPagePath(path) {
        return path + "/" + this.currentPage + "/" + this.pageSize;
      },
      handleSizeChange(size) {
        this.pageSize = size;
        this.initTableData();
      },
      handleCurrentChange(current) {
        this.currentPage = current;
        this.initTableData();
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      handleEdit(testPlan) {
H
haifeng414 已提交
143
        this.$router.push({
C
chenjianxing 已提交
144
          path: '/api/test/edit/' + testPlan.id,
H
haifeng414 已提交
145
        })
H
haifeng414 已提交
146 147
      },
      handleDelete(testPlan) {
C
i18n  
Captain.B 已提交
148 149
        this.$alert(this.$t('load_test.delete_confirm') + testPlan.name + "", '', {
          confirmButtonText: this.$t('commons.confirm'),
150 151 152 153
          callback: (action) => {
            if (action === 'confirm') {
              this._handleDelete(testPlan);
            }
H
haifeng414 已提交
154 155 156 157 158
          }
        });
      },
      _handleDelete(testPlan) {
        let data = {
H
haifeng414 已提交
159
          id: testPlan.id
H
haifeng414 已提交
160 161
        };

H
haifeng414 已提交
162
        this.result = this.$post(this.deletePath, data, () => {
H
haifeng414 已提交
163
          this.$message({
C
i18n  
Captain.B 已提交
164
            message: this.$t('commons.delete_success'),
H
haifeng414 已提交
165 166 167
            type: 'success'
          });
          this.initTableData();
H
haifeng414 已提交
168 169 170 171 172 173 174
        });
      },
    }
  }
</script>

<style scoped>
H
haifeng414 已提交
175
  .testplan-container {
H
haifeng414 已提交
176 177 178 179 180 181 182 183 184 185
    padding: 15px;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
  }

  .main-content {
    margin: 0 auto;
    width: 100%;
    max-width: 1200px;
H
haifeng414 已提交
186
  }
H
haifeng414 已提交
187

C
style  
Captain.B 已提交
188 189 190 191
  .test-content {
    width: 100%;
  }

H
haifeng414 已提交
192 193 194 195 196
  .table-page {
    padding-top: 20px;
    margin-right: -9px;
    float: right;
  }
H
haifeng414 已提交
197
</style>