TestCase.vue 11.0 KB
Newer Older
C
chenjianxing 已提交
1
<template>
W
wenyann 已提交
2
  <ms-container v-if="renderComponent" v-loading="loading">
C
ms-  
chenjianxing 已提交
3 4

    <ms-aside-container>
5
      <test-case-node-tree
C
ms-  
chenjianxing 已提交
6
        @nodeSelectEvent="nodeChange"
7
        @refreshTable="refresh"
8
        @setTreeNodes="setTreeNodes"
W
wenyann 已提交
9
        @exportTestCase="exportTestCase"
W
wenyann 已提交
10
        @saveAsEdit="editTestCase"
11
        @createCase="handleCaseSimpleCreate($event, 'add')"
12
        @refreshAll="refreshAll"
C
ms-  
chenjianxing 已提交
13
        :type="'edit'"
W
wenyann 已提交
14 15
        ref="nodeTree"
      />
C
ms-  
chenjianxing 已提交
16 17 18
    </ms-aside-container>

    <ms-main-container>
W
wenyann 已提交
19 20
      <el-tabs v-model="activeName" @tab-click="addTab" @tab-remove="removeTab">
        <el-tab-pane name="default" :label="$t('api_test.definition.case_title')">
C
chenjianxing 已提交
21 22
          <ms-tab-button
            :active-dom.sync="activeDom"
23 24
            :left-tip="$t('test_track.case.list')"
            :left-content="$t('test_track.case.list')"
C
chenjianxing 已提交
25 26
            :right-tip="$t('test_track.case.minder')"
            :right-content="$t('test_track.case.minder')"
C
chenjianxing 已提交
27
            :middle-button-enable="false">
W
wenyann 已提交
28
          <test-case-list
C
chenjianxing 已提交
29
            v-if="activeDom === 'left'"
W
wenyann 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43
            :checkRedirectID="checkRedirectID"
            :module-options="moduleOptions"
            :select-node-ids="selectNodeIds"
            :isRedirectEdit="isRedirectEdit"
            :select-parent-nodes="selectParentNodes"
            :tree-nodes="treeNodes"
            @testCaseEdit="editTestCase"
            @testCaseCopy="copyTestCase"
            @testCaseDetail="showTestCaseDetail"
            @refresh="refresh"
            @refreshAll="refreshAll"
            @setCondition="setCondition"
            ref="testCaseList">
          </test-case-list>
C
chenjianxing 已提交
44
          <test-case-minder
C
chenjianxing 已提交
45
            :tree-nodes="treeNodes"
C
chenjianxing 已提交
46
            :project-id="projectId"
C
chenjianxing 已提交
47
            v-if="activeDom === 'right'"
48
            ref="minder"/>
C
chenjianxing 已提交
49
          </ms-tab-button>
W
wenyann 已提交
50 51 52 53 54 55 56 57 58 59 60 61
        </el-tab-pane>
        <el-tab-pane
          :key="item.name"
          v-for="(item) in tabs"
          :label="item.label"
          :name="item.name"
          closable>
          <div class="ms-api-scenario-div">
            <test-case-edit
              :currentTestCaseInfo="item.testCaseInfo"
              @refresh="refreshTable"
              @setModuleOptions="setModuleOptions"
62 63
              @caseEdit="handleCaseCreateOrEdit($event,'edit')"
              @caseCreate="handleCaseCreateOrEdit($event,'add')"
W
wenyann 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
              :read-only="testCaseReadOnly"
              :tree-nodes="treeNodes"
              :select-node="selectNode"
              :select-condition="condition"
              :type="type"
              @addTab="addTab"
              ref="testCaseEdit">
            </test-case-edit>
          </div>
        </el-tab-pane>
        <el-tab-pane name="add">
          <template v-slot:label>
            <el-dropdown @command="handleCommand" v-tester>
              <el-button type="primary" plain icon="el-icon-plus" size="mini" v-tester/>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="ADD">{{ $t('test_track.case.create') }}</el-dropdown-item>
                <el-dropdown-item command="CLOSE_ALL">{{ $t('api_test.definition.request.close_all_label') }}
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-tab-pane>

      </el-tabs>
C
ms-  
chenjianxing 已提交
88

W
wenyann 已提交
89
    </ms-main-container>
C
ms-  
chenjianxing 已提交
90

91

C
ms-  
chenjianxing 已提交
92 93
  </ms-container>

C
chenjianxing 已提交
94 95 96
</template>

<script>
C
chenjianxing 已提交
97

98 99 100 101 102 103 104
import NodeTree from '../common/NodeTree';
import TestCaseEdit from './components/TestCaseEdit';
import TestCaseList from "./components/TestCaseList";
import SelectMenu from "../common/SelectMenu";
import MsContainer from "../../common/components/MsContainer";
import MsAsideContainer from "../../common/components/MsAsideContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
105
import {checkoutTestManagerOrTestUser, getUUID} from "../../../../common/js/utils";
106
import TestCaseNodeTree from "../common/TestCaseNodeTree";
C
chenjianxing 已提交
107

C
chenjianxing 已提交
108
import MsTabButton from "@/business/components/common/components/MsTabButton";
109
import TestCaseMinder from "@/business/components/track/common/minder/TestCaseMinder";
C
chenjianxing 已提交
110

111 112 113
export default {
  name: "TestCase",
  components: {
C
chenjianxing 已提交
114
    TestCaseMinder,
C
chenjianxing 已提交
115
    MsTabButton,
116
    TestCaseNodeTree,
117
    MsMainContainer,
C
chenjianxing 已提交
118
    MsAsideContainer, MsContainer, TestCaseList, NodeTree, TestCaseEdit, SelectMenu
119 120 121 122 123 124 125 126 127 128 129
  },
  comments: {},
  data() {
    return {
      result: {},
      projects: [],
      treeNodes: [],
      selectNodeIds: [],
      selectParentNodes: [],
      testCaseReadOnly: true,
      selectNode: {},
C
chenjianxing 已提交
130
      condition: {},
W
wenyann 已提交
131 132 133 134 135
      moduleOptions: [],
      activeName: 'default',
      tabs: [],
      renderComponent:true,
      loading: false,
C
chenjianxing 已提交
136
      type:'',
C
chenjianxing 已提交
137
      activeDom: 'left',
138 139 140 141 142 143
    }
  },
  mounted() {
    this.init(this.$route);
  },
  watch: {
W
wenyann 已提交
144 145 146 147 148 149 150
    redirectID() {
      this.renderComponent = false;
      this.$nextTick(() => {
        // 在 DOM 中添加 my-component 组件
        this.renderComponent = true;
      });
    },
151 152
    '$route'(to, from) {
      this.init(to);
W
wenyann 已提交
153 154 155 156 157 158 159
      if (to.path.indexOf('/track/case/all') == -1) {
        if (this.$refs && this.$refs.autoScenarioConfig) {
          this.$refs.autoScenarioConfig.forEach(item => {
            /*item.removeListener();*/
          });
        }
      }
160
    },
161 162 163 164 165
    activeName(newVal, oldVal) {
      if (oldVal !== 'default' && newVal === 'default' && this.$refs.minder) {
        this.$refs.minder.refresh();
      }
    }
166
  },
W
wenyann 已提交
167 168 169 170 171 172 173 174 175
  computed: {
    checkRedirectID: function () {
      let redirectIDParam = this.$route.params.redirectID;
      this.changeRedirectParam(redirectIDParam);
      return redirectIDParam;
    },
    isRedirectEdit: function () {
      let redirectParam = this.$route.params.dataSelectRange;
      return redirectParam;
176 177 178 179
    },
    projectId() {
      return this.$store.state.projectId
    },
W
wenyann 已提交
180
  },
181
  methods: {
W
wenyann 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
    handleCommand(e) {
      switch (e) {
        case "ADD":
          this.addTab({name: 'add'});
          break;
        case "CLOSE_ALL":
          this.handleTabClose();
          break;
        default:
          this.addTab({name: 'add'});
          break;
      }
    },
    changeRedirectParam(redirectIDParam) {
      this.redirectID = redirectIDParam;
      if (redirectIDParam != null) {
        if (this.redirectFlag == "none") {
          this.activeName = "default";
          this.addListener();
          this.redirectFlag = "redirected";
        }
      } else {
        this.redirectFlag = "none";
      }
    },
    addTab(tab) {
C
chenjianxing 已提交
208
      if (!this.projectId) {
W
wenyann 已提交
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
        this.$warning(this.$t('commons.check_project_tip'));
        return;
      }
      if (tab.name === 'add') {
        let label = this.$t('test_track.case.create');
        let name = getUUID().substring(0, 8);
        this.activeName = name;
        this.type='add'
        this.tabs.push({label: label, name: name, testCaseInfo: {testCaseModuleId: "", id: getUUID()}});
      }
      if (tab.name === 'edit') {
        let label = this.$t('test_track.case.create');
        let name = getUUID().substring(0, 8);
        this.activeName = name;
        label = tab.testCaseInfo.name;
        this.tabs.push({label: label, name: name, testCaseInfo: tab.testCaseInfo});
      }
      if (this.$refs && this.$refs.testCaseEdit) {
        this.$refs.testCaseEdit.forEach(item => {
         /* item.removeListener();*/
        });  //  删除所有tab的 ctrl + s 监听
        this.addListener();
      }
    },
    handleTabClose() {
      this.tabs = [];
      this.activeName = "default";
      this.refresh();
    },
    removeTab(targetName) {
      this.tabs = this.tabs.filter(tab => tab.name !== targetName);
      if (this.tabs.length > 0) {
        this.activeName = this.tabs[this.tabs.length - 1].name;
        this.addListener(); //  自动切换当前标签时,也添加监听
      } else {
        this.activeName = "default"
      }
    },
    exportTestCase(){
248 249 250 251
      if (this.activeDom !== 'left') {
        this.$warning('请切换成接口列表导出!');
        return;
      }
W
wenyann 已提交
252 253 254 255 256 257 258 259 260 261 262 263
      this.$refs.testCaseList.exportTestCase()
    },
    addListener() {
      let index = this.tabs.findIndex(item => item.name === this.activeName); //  找到当前选中tab的index
      if (index != -1) {   //  为当前选中的tab添加监听
        this.$nextTick(() => {
/*
          this.$refs.testCaseEdit[index].addListener();
*/
        });
      }
    },
264 265 266 267 268 269 270 271
    init(route) {
      let path = route.path;
      if (path.indexOf("/track/case/edit") >= 0 || path.indexOf("/track/case/create") >= 0) {
        this.testCaseReadOnly = false;
        if (!checkoutTestManagerOrTestUser()) {
          this.testCaseReadOnly = true;
        }
        let caseId = this.$route.params.caseId;
C
chenjianxing 已提交
272
        if (!this.projectId) {
C
chenjianxing 已提交
273 274 275
          this.$warning(this.$t('commons.check_project_tip'));
          return;
        }
276 277 278 279 280 281 282 283
        if (caseId) {
          this.$get('test/case/get/' + caseId, response => {
            let testCase = response.data;
            this.editTestCase(testCase)
          });
        } else {
          this.addTab({name: 'add'});
        }
284
        this.$router.push('/track/case/all');
C
chenjianxing 已提交
285 286
      }
    },
287
    nodeChange(node, nodeIds, pNodes) {
288
      this.selectNodeIds = nodeIds;
289
      this.selectNode = node;
290 291 292
      this.selectParentNodes = pNodes;
    },
    refreshTable() {
293 294 295
      if ( this.$refs.testCaseList) {
        this.$refs.testCaseList.initTableData();
      }
296 297
    },
    editTestCase(testCase) {
W
wenyann 已提交
298
      this.type="edit"
299 300 301 302 303
      this.testCaseReadOnly = false;
      if (this.treeNodes.length < 1) {
        this.$warning(this.$t('test_track.case.create_module_first'));
        return;
      }
W
wenyann 已提交
304
      this.addTab({name: 'edit', testCaseInfo: testCase});
305
    },
306 307 308 309 310
    handleCaseCreateOrEdit(data, type) {
      if (this.$refs.minder) {
        this.$refs.minder.addCase(data, type);
      }
    },
311 312 313 314 315 316
    handleCaseSimpleCreate(data, type) {
      this.handleCaseCreateOrEdit(data, type);
      if (this.$refs.minder) {
        this.$refs.minder.refresh();
      }
    },
317
    copyTestCase(testCase) {
W
wenyann 已提交
318
      this.type="copy"
319
      this.testCaseReadOnly = false;
W
wenyann 已提交
320 321
      testCase.isCopy = true;
      this.addTab({name: 'edit', testCaseInfo: testCase});
322 323 324 325 326 327 328 329
    },
    showTestCaseDetail(testCase) {
      this.testCaseReadOnly = true;
    },
    refresh() {
      this.selectNodeIds = [];
      this.selectParentNodes = [];
      this.selectNode = {};
330
      this.refreshTable();
331
    },
332 333 334 335
    refreshAll() {
      this.$refs.nodeTree.list();
      this.refresh();
    },
336 337
    openRecentTestCaseEditDialog(caseId) {
      if (caseId) {
338
        // this.getProjectByCaseId(caseId);
339 340
        this.$get('/test/case/get/' + caseId, response => {
          if (response.data) {
W
wenyann 已提交
341
/*
342
            this.$refs.testCaseEditDialog.open(response.data);
W
wenyann 已提交
343
*/
C
chenjianxing 已提交
344
          }
C
chenjianxing 已提交
345
        });
346
      } else {
W
wenyann 已提交
347
/*
348
        this.$refs.testCaseEditDialog.open();
W
wenyann 已提交
349
*/
350 351
      }
    },
352 353
    setTreeNodes(data) {
      this.treeNodes = data;
C
chenjianxing 已提交
354
    },
355 356 357
    setCondition(data) {
      this.condition = data;
    },
C
chenjianxing 已提交
358 359
    setModuleOptions(data) {
      this.moduleOptions = data;
C
chenjianxing 已提交
360
    }
C
chenjianxing 已提交
361
  }
362
}
C
chenjianxing 已提交
363 364 365
</script>

<style scoped>
C
chenjianxing 已提交
366

367 368 369
.el-main {
  padding: 15px;
}
C
样式  
chenjianxing 已提交
370

C
chenjianxing 已提交
371 372 373 374
/deep/ .el-button-group>.el-button:first-child {
  padding: 4px 1px !important;
}

C
chenjianxing 已提交
375
</style>