TestCase.vue 6.6 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 12
        <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"
                       :current-project="currentProject"
C
chenjianxing 已提交
13
                       @nodeSelectEvent="nodeChange"
C
chenjianxing 已提交
14 15 16 17 18
                       @refresh="refreshTable"
                       ref="nodeTree">
            </node-tree>
          </el-aside>

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

        <test-case-edit
          @refresh="refreshTable"
          ref="testCaseEditDialog">
        </test-case-edit>

C
chenjianxing 已提交
35
      </div>
C
chenjianxing 已提交
36 37 38
</template>

<script>
C
chenjianxing 已提交
39 40

  import NodeTree from './components/NodeTree';
C
chenjianxing 已提交
41
  import TestCaseEdit from './components/TestCaseEdit';
C
Captain.B 已提交
42
  import {CURRENT_PROJECT, WORKSPACE_ID} from '../../../../common/js/constants';
C
chenjianxing 已提交
43
  import TestCaseList from "./components/TestCaseList";
44
  import SelectMenu from "../common/SelectMenu";
C
chenjianxing 已提交
45 46 47

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

C
chenjianxing 已提交
199
    }
C
chenjianxing 已提交
200
  }
C
chenjianxing 已提交
201 202 203
</script>

<style scoped>
C
chenjianxing 已提交
204

C
chenjianxing 已提交
205 206 207 208 209 210 211
  .node-tree {
    margin: 3%;
  }

  .tree-aside {
    position: relative;
    border: 1px solid #EBEEF5;
C
chenjianxing 已提交
212
    box-sizing: border-box;
C
chenjianxing 已提交
213
    background: white;
C
chenjianxing 已提交
214 215
  }

C
chenjianxing 已提交
216 217 218
  .case-container {
    height: calc(100vh - 150px);
    min-height: 600px;
C
chenjianxing 已提交
219 220
    margin-top: 0;
    margin-left: 0;
C
chenjianxing 已提交
221
  }
C
chenjianxing 已提交
222

C
chenjianxing 已提交
223
  .main-content {
C
样式  
chenjianxing 已提交
224
    /*background: white;*/
C
chenjianxing 已提交
225
  }
C
chenjianxing 已提交
226

C
样式  
chenjianxing 已提交
227 228 229 230 231
  .test-case-list {
    padding: 15px;
  }


C
chenjianxing 已提交
232
</style>