TestCase.vue 6.0 KB
Newer Older
C
chenjianxing 已提交
1
<template>
C
chenjianxing 已提交
2
    <div class="main-content">
C
chenjianxing 已提交
3 4 5 6 7 8 9 10 11
        <el-container class="case-container">
          <el-aside class="tree-aside">
            <select-menu
              :data="projects"
              :current-data="currentProject"
              :title="$t('test_track.project')"
              @dataChange="changeProject">
            </select-menu>
            <node-tree class="node-tree"
C
chenjianxing 已提交
12
                       v-loading="result.loading"
C
chenjianxing 已提交
13
                       @nodeSelectEvent="nodeChange"
C
chenjianxing 已提交
14 15 16 17
                       @refresh="refresh"
                       :tree-nodes="treeNodes"
                       :type="'edit'"
                       ref="nodeTree"/>
C
chenjianxing 已提交
18 19
          </el-aside>

C
样式  
chenjianxing 已提交
20
          <el-main class="test-case-list">
C
chenjianxing 已提交
21 22
            <test-case-list
              :current-project="currentProject"
C
chenjianxing 已提交
23 24
              :selectNodeIds="selectNodeIds"
              :selectNodeNames="selectNodeNames"
C
chenjianxing 已提交
25 26 27 28 29 30 31 32 33
              @openTestCaseEditDialog="openTestCaseEditDialog"
              @testCaseEdit="openTestCaseEditDialog"
              @refresh="refresh"
              ref="testCaseList">
            </test-case-list>
          </el-main>
        </el-container>

        <test-case-edit
C
chenjianxing 已提交
34
          @refresh="refresh"
C
chenjianxing 已提交
35
          :tree-nodes="treeNodes"
C
chenjianxing 已提交
36 37
          ref="testCaseEditDialog">
        </test-case-edit>
C
chenjianxing 已提交
38
    </div>
C
chenjianxing 已提交
39 40 41
</template>

<script>
C
chenjianxing 已提交
42

C
chenjianxing 已提交
43
  import NodeTree from '../common/NodeTree';
C
chenjianxing 已提交
44
  import TestCaseEdit from './components/TestCaseEdit';
C
chenjianxing 已提交
45
  import {CURRENT_PROJECT} from '../../../../common/js/constants';
C
chenjianxing 已提交
46
  import TestCaseList from "./components/TestCaseList";
47
  import SelectMenu from "../common/SelectMenu";
C
chenjianxing 已提交
48 49 50

  export default {
    name: "TestCase",
51
    components: {TestCaseList, NodeTree, TestCaseEdit, SelectMenu},
C
chenjianxing 已提交
52 53 54 55 56 57 58
    comments: {},
    data() {
      return {
        result: {},
        currentPage: 1,
        pageSize: 5,
        total: 0,
C
chenjianxing 已提交
59 60
        projects: [],
        currentProject: null,
C
chenjianxing 已提交
61 62 63
        treeNodes: [],
        selectNodeIds: [],
        selectNodeNames: []
C
chenjianxing 已提交
64 65
      }
    },
C
chenjianxing 已提交
66
    mounted() {
C
chenjianxing 已提交
67 68
      this.getProjects();
      this.refresh();
C
chenjianxing 已提交
69 70 71
      if (this.$route.params.projectId){
        this.getProjectById(this.$route.params.projectId)
      }
C
chenjianxing 已提交
72 73
      if (this.$route.path.indexOf("/track/case/edit") >= 0){
        this.openRecentTestCaseEditDialog();
C
chenjianxing 已提交
74
        this.$router.push('/track/case/all');
C
chenjianxing 已提交
75 76
      }
    },
C
chenjianxing 已提交
77 78
    watch: {
      '$route'(to, from) {
C
chenjianxing 已提交
79
        let path = to.path;
C
chenjianxing 已提交
80 81
        if (to.params.projectId){
          this.getProjectById(to.params.projectId)
C
chenjianxing 已提交
82
          this.getProjects();
C
chenjianxing 已提交
83 84
        }
        if (path.indexOf("/track/case/edit") >= 0){
C
chenjianxing 已提交
85
          this.openRecentTestCaseEditDialog();
C
chenjianxing 已提交
86
          this.$router.push('/track/case/all');
C
chenjianxing 已提交
87
          this.getProjects();
C
chenjianxing 已提交
88
        }
C
chenjianxing 已提交
89 90 91
      },
      currentProject() {
        this.refresh();
C
chenjianxing 已提交
92 93
      }
    },
C
chenjianxing 已提交
94
    methods: {
C
chenjianxing 已提交
95 96
      getProjects() {
          this.$get("/project/listAll", (response) => {
C
chenjianxing 已提交
97
            this.projects = response.data;
C
chenjianxing 已提交
98 99
            let lastProject = JSON.parse(localStorage.getItem(CURRENT_PROJECT));
            if (lastProject) {
C
chenjianxing 已提交
100
              let hasCurrentProject = false;
C
chenjianxing 已提交
101 102 103 104 105
              for (let i = 0; i < this.projects.length; i++) {
                if (this.projects[i].id == lastProject.id) {
                  this.currentProject = lastProject;
                  hasCurrentProject = true;
                  break;
C
chenjianxing 已提交
106
                }
C
chenjianxing 已提交
107
              }
C
chenjianxing 已提交
108 109 110
              if (!hasCurrentProject) {
                this.currentProject = null;
              }
C
chenjianxing 已提交
111
            } else {
C
chenjianxing 已提交
112
              if(this.projects.length > 0){
C
chenjianxing 已提交
113
                this.setCurrentProject(this.projects[0]);
C
chenjianxing 已提交
114
              }
C
chenjianxing 已提交
115
            }
C
chenjianxing 已提交
116
            // this.checkProject();
C
chenjianxing 已提交
117 118 119 120
          });
      },
      checkProject() {
        if(this.currentProject === null) {
C
chenjianxing 已提交
121
          this.$alert(this.$t('test_track.case.no_project'), {
C
chenjianxing 已提交
122
            confirmButtonText: this.$t('project.create'),
C
chenjianxing 已提交
123 124 125 126 127 128 129
            callback: action => {
              this.$router.push("/track/project/create");
            }
          });
        }
      },
      changeProject(project) {
C
chenjianxing 已提交
130
        this.setCurrentProject(project);
C
chenjianxing 已提交
131
      },
C
chenjianxing 已提交
132
      nodeChange(nodeIds, nodeNames) {
C
chenjianxing 已提交
133 134
        this.selectNodeIds = nodeIds;
        this.selectNodeNames = nodeNames;
C
chenjianxing 已提交
135
      },
C
chenjianxing 已提交
136 137
      refreshTable() {
        this.$refs.testCaseList.initTableData();
C
chenjianxing 已提交
138
      },
C
chenjianxing 已提交
139 140
      openTestCaseEditDialog(testCase) {
        this.$refs.testCaseEditDialog.open(testCase);
C
chenjianxing 已提交
141
      },
C
chenjianxing 已提交
142 143
      getProjectByCaseId(caseId) {
        return this.$get('/test/case/project/' + caseId, async response => {
C
chenjianxing 已提交
144
          this.setCurrentProject(response.data);
C
chenjianxing 已提交
145 146
        });
      },
C
chenjianxing 已提交
147
      refresh() {
C
chenjianxing 已提交
148 149
        this.selectNodeIds = [];
        this.selectNodeNames = [];
C
chenjianxing 已提交
150
        this.$refs.testCaseList.initTableData();
C
chenjianxing 已提交
151
        this.getNodeTree();
C
chenjianxing 已提交
152 153 154 155 156
      },
      openRecentTestCaseEditDialog() {
        let caseId = this.$route.params.caseId;
        this.getProjectByCaseId(caseId);
        this.$get('/test/case/get/' + caseId, response => {
C
chenjianxing 已提交
157 158 159
          if (response.data) {
            this.openTestCaseEditDialog(response.data);
          }
C
chenjianxing 已提交
160
        });
C
chenjianxing 已提交
161 162
      },
      getProjectById(id) {
C
chenjianxing 已提交
163
        if (id && id != 'all') {
C
chenjianxing 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
          this.$get('/project/get/' + id, response => {
            let project = response.data;
            this.setCurrentProject(project);
          });
        }
        if (id === 'all') {
          this.refresh();
        }
      },
      setCurrentProject(project) {
        if (project) {
          this.currentProject = project;
          localStorage.setItem(CURRENT_PROJECT, JSON.stringify(project));
        }
        this.refresh();
C
chenjianxing 已提交
179 180 181 182 183 184 185
      },
      getNodeTree() {
        if (this.currentProject) {
          this.result = this.$get("/case/node/list/" + this.currentProject.id, response => {
            this.treeNodes = response.data;
          });
        }
C
chenjianxing 已提交
186
      }
C
chenjianxing 已提交
187
    }
C
chenjianxing 已提交
188
  }
C
chenjianxing 已提交
189 190 191
</script>

<style scoped>
C
chenjianxing 已提交
192

C
chenjianxing 已提交
193 194 195 196 197 198 199
  .node-tree {
    margin: 3%;
  }

  .tree-aside {
    position: relative;
    border: 1px solid #EBEEF5;
C
chenjianxing 已提交
200
    box-sizing: border-box;
C
chenjianxing 已提交
201
    background: white;
C
chenjianxing 已提交
202 203
  }

C
chenjianxing 已提交
204 205 206
  .case-container {
    height: calc(100vh - 150px);
    min-height: 600px;
C
chenjianxing 已提交
207 208
    margin-top: 0;
    margin-left: 0;
C
chenjianxing 已提交
209
  }
C
chenjianxing 已提交
210

C
样式  
chenjianxing 已提交
211 212 213 214
  .test-case-list {
    padding: 15px;
  }

C
chenjianxing 已提交
215
</style>