提交 844eb8b9 编写于 作者: C chenjianxing

代码重构

上级 ca98ce42
...@@ -9,16 +9,19 @@ ...@@ -9,16 +9,19 @@
@dataChange="changeProject"> @dataChange="changeProject">
</select-menu> </select-menu>
<node-tree class="node-tree" <node-tree class="node-tree"
:current-project="currentProject" v-loading="result.loading"
@nodeSelectEvent="nodeChange" @nodeSelectEvent="nodeChange"
@refresh="refreshTable" @refresh="refresh"
ref="nodeTree"> :tree-nodes="treeNodes"
</node-tree> :type="'edit'"
ref="nodeTree"/>
</el-aside> </el-aside>
<el-main class="test-case-list"> <el-main class="test-case-list">
<test-case-list <test-case-list
:current-project="currentProject" :current-project="currentProject"
:selectNodeIds="selectNodeIds"
:selectNodeNames="selectNodeNames"
@openTestCaseEditDialog="openTestCaseEditDialog" @openTestCaseEditDialog="openTestCaseEditDialog"
@testCaseEdit="openTestCaseEditDialog" @testCaseEdit="openTestCaseEditDialog"
@refresh="refresh" @refresh="refresh"
...@@ -29,17 +32,17 @@ ...@@ -29,17 +32,17 @@
<test-case-edit <test-case-edit
@refresh="refreshTable" @refresh="refreshTable"
:tree-nodes="treeNodes"
ref="testCaseEditDialog"> ref="testCaseEditDialog">
</test-case-edit> </test-case-edit>
</div>
</div>
</template> </template>
<script> <script>
import NodeTree from './components/NodeTree'; import NodeTree from '../common/NodeTree';
import TestCaseEdit from './components/TestCaseEdit'; import TestCaseEdit from './components/TestCaseEdit';
import {CURRENT_PROJECT, WORKSPACE_ID} from '../../../../common/js/constants'; import {CURRENT_PROJECT} from '../../../../common/js/constants';
import TestCaseList from "./components/TestCaseList"; import TestCaseList from "./components/TestCaseList";
import SelectMenu from "../common/SelectMenu"; import SelectMenu from "../common/SelectMenu";
...@@ -50,20 +53,19 @@ ...@@ -50,20 +53,19 @@
data() { data() {
return { return {
result: {}, result: {},
tableData: [],
multipleSelection: [],
currentPage: 1, currentPage: 1,
pageSize: 5, pageSize: 5,
total: 0, total: 0,
projects: [], projects: [],
currentProject: null, currentProject: null,
treeNodes: [] treeNodes: [],
selectNodeIds: [],
selectNodeNames: []
} }
}, },
created() {
this.getProjects();
},
mounted() { mounted() {
this.getProjects();
this.refresh();
if (this.$route.params.projectId){ if (this.$route.params.projectId){
this.getProjectById(this.$route.params.projectId) this.getProjectById(this.$route.params.projectId)
} }
...@@ -77,11 +79,16 @@ ...@@ -77,11 +79,16 @@
let path = to.path; let path = to.path;
if (to.params.projectId){ if (to.params.projectId){
this.getProjectById(to.params.projectId) this.getProjectById(to.params.projectId)
this.getProjects();
} }
if (path.indexOf("/track/case/edit") >= 0){ if (path.indexOf("/track/case/edit") >= 0){
this.openRecentTestCaseEditDialog(); this.openRecentTestCaseEditDialog();
this.$router.push('/track/case/all'); this.$router.push('/track/case/all');
this.getProjects();
} }
},
currentProject() {
this.refresh();
} }
}, },
methods: { methods: {
...@@ -90,7 +97,7 @@ ...@@ -90,7 +97,7 @@
this.projects = response.data; this.projects = response.data;
let lastProject = JSON.parse(localStorage.getItem(CURRENT_PROJECT)); let lastProject = JSON.parse(localStorage.getItem(CURRENT_PROJECT));
if (lastProject) { if (lastProject) {
let hasCurrentProject = false; let hasCurrentProject = false;
for (let i = 0; i < this.projects.length; i++) { for (let i = 0; i < this.projects.length; i++) {
if (this.projects[i].id == lastProject.id) { if (this.projects[i].id == lastProject.id) {
this.currentProject = lastProject; this.currentProject = lastProject;
...@@ -123,40 +130,14 @@ ...@@ -123,40 +130,14 @@
this.setCurrentProject(project); this.setCurrentProject(project);
}, },
nodeChange(nodeIds, nodeNames) { nodeChange(nodeIds, nodeNames) {
this.$refs.testCaseList.selectNodeNames = nodeNames; this.selectNodeIds = nodeIds;
this.$refs.testCaseList.initTableData(nodeIds); this.selectNodeNames = nodeNames;
}, },
refreshTable(data) { refreshTable() {
this.$refs.testCaseList.initTableData(data); this.$refs.testCaseList.initTableData();
},
openTestCaseEditDialog(data) {
this.setNodePathOption(this.$refs.nodeTree.treeNodes);
this.setMaintainerOptions();
this.$refs.testCaseEditDialog.openTestCaseEditDialog(data);
},
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);
if (node.children) {
for (let i = 0; i < node.children.length; i++){
this.buildNodePath(node.children[i], { path: option.path }, moduleOptions);
}
}
}, },
setMaintainerOptions() { openTestCaseEditDialog(testCase) {
let workspaceId = localStorage.getItem(WORKSPACE_ID); this.$refs.testCaseEditDialog.open(testCase);
this.$post('/user/ws/member/list/all', {workspaceId:workspaceId}, response => {
this.$refs.testCaseEditDialog.maintainerOptions = response.data;
});
}, },
getProjectByCaseId(caseId) { getProjectByCaseId(caseId) {
return this.$get('/test/case/project/' + caseId, async response => { return this.$get('/test/case/project/' + caseId, async response => {
...@@ -164,9 +145,10 @@ ...@@ -164,9 +145,10 @@
}); });
}, },
refresh() { refresh() {
this.selectNodeIds = [];
this.selectNodeNames = [];
this.$refs.testCaseList.initTableData(); this.$refs.testCaseList.initTableData();
this.$refs.nodeTree.getNodeTree(); this.getNodeTree();
this.getProjects();
}, },
openRecentTestCaseEditDialog() { openRecentTestCaseEditDialog() {
let caseId = this.$route.params.caseId; let caseId = this.$route.params.caseId;
...@@ -194,8 +176,14 @@ ...@@ -194,8 +176,14 @@
localStorage.setItem(CURRENT_PROJECT, JSON.stringify(project)); localStorage.setItem(CURRENT_PROJECT, JSON.stringify(project));
} }
this.refresh(); this.refresh();
},
getNodeTree() {
if (this.currentProject) {
this.result = this.$get("/case/node/list/" + this.currentProject.id, response => {
this.treeNodes = response.data;
});
}
} }
} }
} }
</script> </script>
...@@ -220,13 +208,8 @@ ...@@ -220,13 +208,8 @@
margin-left: 0; margin-left: 0;
} }
.main-content {
/*background: white;*/
}
.test-case-list { .test-case-list {
padding: 15px; padding: 15px;
} }
</style> </style>
...@@ -167,18 +167,11 @@ ...@@ -167,18 +167,11 @@
</el-form> </el-form>
<template v-slot:footer> <template v-slot:footer>
<div class="dialog-footer"> <ms-dialog-footer
<el-button @cancel="dialogFormVisible = false"
@click="dialogFormVisible = false"> @confirm="saveCase"/>
{{$t('test_track.cancel')}}
</el-button>
<el-button
type="primary"
@click="saveCase">
{{$t('test_track.confirm')}}
</el-button>
</div>
</template> </template>
</el-dialog> </el-dialog>
</div> </div>
...@@ -188,126 +181,163 @@ ...@@ -188,126 +181,163 @@
<script> <script>
import {CURRENT_PROJECT} from '../../../../../common/js/constants'; import {CURRENT_PROJECT, WORKSPACE_ID} from '../../../../../common/js/constants';
import MsDialogFooter from '../../../common/components/MsDialogFooter'
export default { export default {
name: "TestCaseEdit", name: "TestCaseEdit",
data() { components: {MsDialogFooter},
return { data() {
dialogFormVisible: false, return {
form: { dialogFormVisible: false,
name: '', form: {
module: '', name: '',
maintainer: '', module: '',
priority: '', maintainer: '',
type: '', priority: '',
method: '', type: '',
prerequisite: '', method: '',
steps: [{ prerequisite: '',
num: 1 , steps: [{
desc: '', num: 1 ,
result: '' desc: '',
}], result: ''
remark: '', }],
}, remark: '',
moduleOptions: [],
maintainerOptions: [],
rules:{
name :[
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{ max: 30, message: this.$t('test_track.length_less_than') + '30', trigger: 'blur' }
],
module :[{required: true, message: this.$t('test_track.case.input_module'), trigger: 'change'}],
maintainer :[{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
priority :[{required: true, message: this.$t('test_track.case.input_priority'), trigger: 'change'}],
type :[{required: true, message: this.$t('test_track.case.input_type'), trigger: 'change'}],
method :[{required: true, message: this.$t('test_track.case.input_method'), trigger: 'change'}]
},
formLabelWidth: "120px",
operationType: ''
};
},
methods: {
openTestCaseEditDialog(testCase) {
this.resetForm();
this.operationType = 'add';
if(testCase){
//修改
this.operationType = 'edit';
let tmp = {};
Object.assign(tmp, testCase);
tmp.steps = JSON.parse(testCase.steps);
Object.assign(this.form, tmp);
this.form.module = testCase.nodeId;
}
this.dialogFormVisible = true;
},
handleAddStep(index, data) {
let step = {};
step.num = data.num + 1;
step.desc = null;
step.result = null;
this.form.steps.forEach(step => {
if(step.num > data.num){
step.num ++;
}
});
this.form.steps.push(step);
}, },
handleDeleteStep(index, data) { moduleOptions: [],
this.form.steps.splice(index, 1); maintainerOptions: [],
this.form.steps.forEach(step => { workspaceId: '',
if(step.num > data.num){ rules:{
step.num --; name :[
} {required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
}); { max: 30, message: this.$t('test_track.length_less_than') + '30', trigger: 'blur' }
],
module :[{required: true, message: this.$t('test_track.case.input_module'), trigger: 'change'}],
maintainer :[{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
priority :[{required: true, message: this.$t('test_track.case.input_priority'), trigger: 'change'}],
type :[{required: true, message: this.$t('test_track.case.input_type'), trigger: 'change'}],
method :[{required: true, message: this.$t('test_track.case.input_method'), trigger: 'change'}]
}, },
saveCase(){ formLabelWidth: "120px",
this.$refs['caseFrom'].validate((valid) => { operationType: ''
if (valid) { };
let param = {}; },
Object.assign(param, this.form); props: {
param.steps = JSON.stringify(this.form.steps); treeNodes: {
param.nodeId = this.form.module; type: Array
this.moduleOptions.forEach(item => { }
if(this.form.module === item.id){ },
param.nodePath = item.path; methods: {
} open(testCase) {
}); this.resetForm();
if(localStorage.getItem(CURRENT_PROJECT)) { this.getSelectOptions();
param.projectId = JSON.parse(localStorage.getItem(CURRENT_PROJECT)).id; this.operationType = 'add';
if(testCase){
//修改
this.operationType = 'edit';
let tmp = {};
Object.assign(tmp, testCase);
tmp.steps = JSON.parse(testCase.steps);
Object.assign(this.form, tmp);
this.form.module = testCase.nodeId;
}
this.dialogFormVisible = true;
},
handleAddStep(index, data) {
let step = {};
step.num = data.num + 1;
step.desc = null;
step.result = null;
this.form.steps.forEach(step => {
if(step.num > data.num){
step.num ++;
}
});
this.form.steps.push(step);
},
handleDeleteStep(index, data) {
this.form.steps.splice(index, 1);
this.form.steps.forEach(step => {
if(step.num > data.num){
step.num --;
}
});
},
saveCase(){
this.$refs['caseFrom'].validate((valid) => {
if (valid) {
let param = {};
Object.assign(param, this.form);
param.steps = JSON.stringify(this.form.steps);
param.nodeId = this.form.module;
this.moduleOptions.forEach(item => {
if(this.form.module === item.id){
param.nodePath = item.path;
} }
this.$post('/test/case/' + this.operationType, param, () => { });
this.$message.success(this.$t('commons.save_success')); if(localStorage.getItem(CURRENT_PROJECT)) {
this.dialogFormVisible = false; param.projectId = JSON.parse(localStorage.getItem(CURRENT_PROJECT)).id;
this.$emit("refresh");
});
} else {
return false;
} }
}); this.$post('/test/case/' + this.operationType, param, () => {
} this.$message.success(this.$t('commons.save_success'));
, this.dialogFormVisible = false;
resetForm() { this.$emit("refresh");
if (this.$refs['caseFrom']) { });
this.$refs['caseFrom'].resetFields(); } else {
return false;
}
});
},
getModuleOptions() {
let moduleOptions = [];
this.treeNodes.forEach(node => {
this.buildNodePath(node, {path: ''}, moduleOptions);
});
this.moduleOptions = moduleOptions;
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/ws/member/list/all', {workspaceId:workspaceId}, response => {
this.maintainerOptions = response.data;
});
},
getSelectOptions() {
this.getModuleOptions();
this.getMaintainerOptions();
},
buildNodePath(node, option, moduleOptions) {
//递归构建节点路径
option.id = node.id;
option.path = option.path + '/' + node.name;
moduleOptions.push(option);
if (node.children) {
for (let i = 0; i < node.children.length; i++){
this.buildNodePath(node.children[i], { path: option.path }, moduleOptions);
} }
this.form.name = '';
this.form.module = '';
this.form.type = '';
this.form.method = '';
this.form.maintainer = '';
this.form.priority = '';
this.form.prerequisite = '';
this.form.remark = '';
this.form.steps = [{
num: 1 ,
desc: '',
result: ''
}];
} }
},
resetForm() {
if (this.$refs['caseFrom']) {
this.$refs['caseFrom'].resetFields();
}
this.form.name = '';
this.form.module = '';
this.form.type = '';
this.form.method = '';
this.form.maintainer = '';
this.form.priority = '';
this.form.prerequisite = '';
this.form.remark = '';
this.form.steps = [{
num: 1 ,
desc: '',
result: ''
}];
} }
} }
}
</script> </script>
<style scoped> <style scoped>
......
...@@ -37,7 +37,8 @@ ...@@ -37,7 +37,8 @@
<li v-for="errFile in errList" :key="errFile.rowNum"> <li v-for="errFile in errList" :key="errFile.rowNum">
{{errFile.errMsg}} {{errFile.errMsg}}
</li> </li>
</ul></el-row> </ul>
</el-row>
</el-dialog> </el-dialog>
......
...@@ -104,7 +104,6 @@ ...@@ -104,7 +104,6 @@
deletePath: "/test/case/delete", deletePath: "/test/case/delete",
condition: {}, condition: {},
tableData: [], tableData: [],
selectNodeNames: [],
currentPage: 1, currentPage: 1,
pageSize: 5, pageSize: 5,
total: 0, total: 0,
...@@ -113,6 +112,12 @@ ...@@ -113,6 +112,12 @@
props: { props: {
currentProject: { currentProject: {
type: Object type: Object
},
selectNodeIds: {
type: Array
},
selectNodeNames: {
type: Array
} }
}, },
created: function () { created: function () {
...@@ -121,12 +126,14 @@ ...@@ -121,12 +126,14 @@
watch: { watch: {
currentProject() { currentProject() {
this.initTableData(); this.initTableData();
},
selectNodeIds() {
this.initTableData();
} }
}, },
methods: { methods: {
initTableData(nodeIds) { initTableData() {
this.condition.nodeIds = this.selectNodeIds;
this.condition.nodeIds = nodeIds;
if (this.currentProject) { if (this.currentProject) {
this.condition.projectId = this.currentProject.id; this.condition.projectId = this.currentProject.id;
this.result = this.$post(this.buildPagePath('/test/case/list'), this.condition, response => { this.result = this.$post(this.buildPagePath('/test/case/list'), this.condition, response => {
...@@ -169,7 +176,6 @@ ...@@ -169,7 +176,6 @@
}); });
}, },
refresh() { refresh() {
this.selectNodeNames = [];
this.condition = {}; this.condition = {};
this.$emit('refresh'); this.$emit('refresh');
} }
......
<template>
<el-dialog :title="$t('test_track.module.add_module')"
:visible.sync="dialogFormVisible"
width="30%">
<el-row type="flex" justify="center">
<el-col :span="18">
<el-form :model="form" :rules="rules">
<el-form-item
:label="$t('test_track.module.name')"
:label-width="formLabelWidth"
prop="name">
<el-input v-model="form.name" autocomplete="off"></el-input>
</el-form-item>
</el-form>
</el-col>
</el-row>
<template v-slot:footer>
<ms-dialog-footer
@cancel="dialogFormVisible = false"
@confirm="saveNode"/>
</template>
</el-dialog>
</template>
<script>
import {CURRENT_PROJECT} from '../../../../common/js/constants';
import MsDialogFooter from '../../common/components/MsDialogFooter';
export default {
components: {MsDialogFooter},
data() {
return {
name: "NodeEdit",
form: {
name: '',
},
rules:{
name :[
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{ max: 30, message: this.$t('test_track.length_less_than') + '30', trigger: 'blur' }
]
},
type: '',
node: {},
formLabelWidth: '80px',
dialogFormVisible: false,
}
},
methods: {
open(type, data) {
this.type = type;
this.node = data;
this.dialogFormVisible = true;
},
saveNode() {
let param = {};
let url = this.buildParam(param);
this.$post(url, param, () => {
this.$message.success(this.$t('commons.save_success'));
this.$emit('refresh');
this.close();
});
},
buildParam(param, ) {
let url = '';
if (this.type === 'add') {
url = '/case/node/add';
param.level = 1;
if (this.node) {
//非根节点
param.pId = this.node.id;
param.level = this.node.level + 1;
}
} else if (this.type === 'edit') {
url = '/case/node/edit';
param.id = this.node.id
}
param.name = this.form.name;
param.label = this.form.name;
if (localStorage.getItem(CURRENT_PROJECT)) {
param.projectId = JSON.parse(localStorage.getItem(CURRENT_PROJECT)).id;
}
return url;
},
close() {
this.form.name = '';
this.dialogFormVisible = false;
}
}
}
</script>
<style scoped>
</style>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div v-loading="result.loading"> <div v-loading="result.loading">
<el-input :placeholder="$t('test_track.module.search')" v-model="filterText" <el-input :placeholder="$t('test_track.module.search')" v-model="filterText"
size="small"> size="small">
<template v-slot:append> <template v-if="type == 'edit'" v-slot:append>
<el-button icon="el-icon-folder-add" @click="openEditNodeDialog('add')"></el-button> <el-button icon="el-icon-folder-add" @click="openEditNodeDialog('add')"></el-button>
</template> </template>
</el-input> </el-input>
...@@ -20,47 +20,37 @@ ...@@ -20,47 +20,37 @@
ref="tree"> ref="tree">
<template v-slot:default="{node,data}"> <template v-slot:default="{node,data}">
<span class="custom-tree-node father" @click="selectNode(node)"> <span class="custom-tree-node father" @click="selectNode(node)">
<span>{{node.label}}</span> <span>{{node.label}}</span>
<el-dropdown class="node-dropdown child">
<el-dropdown v-if="type == 'edit'" class="node-dropdown child">
<span class="el-dropdown-link"> <span class="el-dropdown-link">
<i class="el-icon-folder-add"></i> <i class="el-icon-folder-add"></i>
</span> </span>
<el-dropdown-menu v-slot:default> <el-dropdown-menu v-slot:default>
<el-dropdown-item> <el-dropdown-item>
<div @click="openEditNodeDialog('edit', data)">{{$t('test_track.module.rename')}}</div> <div @click="openEditNodeDialog('edit', data)">{{$t('test_track.module.rename')}}</div>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item> <el-dropdown-item>
<div @click="openEditNodeDialog('add', data)">{{$t('test_track.module.add_submodule')}}</div> <div @click="openEditNodeDialog('add', data)">{{$t('test_track.module.add_submodule')}}</div>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item> <el-dropdown-item>
<div @click="remove(node, data)">{{$t('commons.delete')}}</div> <div @click="remove(node, data)">{{$t('commons.delete')}}</div>
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
</span> </span>
<!--<span v-if="type == 'view'" class="custom-tree-node" @click="selectNode(node)">-->
<!--{{node.label}}$$-->
<!--</span>-->
</template> </template>
</el-tree> </el-tree>
<el-dialog :title="$t('test_track.module.add_module')" :visible.sync="dialogFormVisible" width="500px"> <node-edit ref="nodeEdit" @refresh="refreshNode"/>
<el-row type="flex" justify="center">
<el-col :span="18">
<el-form :model="form">
<el-form-item :label="$t('test_track.module.name')" :label-width="formLabelWidth">
<el-input v-model="form.name" autocomplete="off"></el-input>
</el-form-item>
</el-form>
</el-col>
</el-row>
<template v-slot:footer>
<div class="dialog-footer">
<el-button @click="dialogFormVisible = false">{{$t('test_track.cancel')}}</el-button>
<el-button type="primary" @click="editNode">{{$t('test_track.confirm')}}</el-button>
</div>
</template>
</el-dialog>
</div> </div>
...@@ -68,10 +58,11 @@ ...@@ -68,10 +58,11 @@
<script> <script>
import {CURRENT_PROJECT} from '../../../../../common/js/constants'; import NodeEdit from './NodeEdit';
export default { export default {
name: "NodeTree", name: "NodeTree",
components: {NodeEdit},
data() { data() {
return { return {
result: {}, result: {},
...@@ -80,34 +71,23 @@ ...@@ -80,34 +71,23 @@
children: 'children', children: 'children',
label: 'label' label: 'label'
}, },
form: { // treeNodes: [],
name: '',
},
formLabelWidth: '80px',
dialogTableVisible: false,
dialogFormVisible: false,
editType: '',
editData: {},
treeNodes: [],
defaultKeys: []
}; };
}, },
props: { props: {
currentProject: { type: {
type: Object type: String,
default: 'view'
},
treeNodes: {
type: Array
} }
}, },
watch: { watch: {
filterText(val) { filterText(val) {
this.$refs.tree.filter(val); this.$refs.tree.filter(val);
},
currentProject() {
this.getNodeTree();
} }
}, },
created() {
this.getNodeTree();
},
methods: { methods: {
handleDragEnd(draggingNode, dropNode, dropType, ev) { handleDragEnd(draggingNode, dropNode, dropType, ev) {
let param = {}; let param = {};
...@@ -152,7 +132,6 @@ ...@@ -152,7 +132,6 @@
this.getChildNodeId(node, nodeIds); this.getChildNodeId(node, nodeIds);
this.getParentNodeName(node, nodeNames); this.getParentNodeName(node, nodeNames);
this.$emit("nodeSelectEvent", nodeIds, nodeNames); this.$emit("nodeSelectEvent", nodeIds, nodeNames);
}, },
getChildNodeId(rootNode, nodeIds) { getChildNodeId(rootNode, nodeIds) {
//递归获取所有子节点ID //递归获取所有子节点ID
...@@ -173,63 +152,12 @@ ...@@ -173,63 +152,12 @@
if (!value) return true; if (!value) return true;
return data.label.indexOf(value) !== -1; return data.label.indexOf(value) !== -1;
}, },
editNode() {
this.saveNode(this.editType, this.editData);
this.dialogFormVisible = false;
},
openEditNodeDialog(type, data) { openEditNodeDialog(type, data) {
this.editType = type; this.$refs.nodeEdit.open(type, data);
this.editData = data;
this.dialogFormVisible = true;
},
getNodeTree() {
if (this.currentProject) {
let projectId = this.currentProject.id;
this.result = this.$get("/case/node/list/" + projectId, response => {
this.treeNodes = response.data;
});
}
},
saveNode(type, pNode) {
let param = {};
let url = '';
if (type === 'add') {
url = '/case/node/add';
param.level = 1;
if (pNode) {
//非根节点
param.pId = pNode.id;
param.level = pNode.level + 1;
}
} else if (type === 'edit') {
url = '/case/node/edit';
param.id = this.editData.id
}
param.name = this.form.name;
param.label = this.form.name;
if (localStorage.getItem(CURRENT_PROJECT)) {
param.projectId = JSON.parse(localStorage.getItem(CURRENT_PROJECT)).id;
}
this.$post(url, param, response => {
if (type === 'edit') {
this.editData.label = param.label;
}
if (type === 'add') {
param.id = response.data;
if (pNode) {
this.$refs.tree.append(param, pNode);
} else {
this.treeNodes.push(param);
}
}
this.$message.success(this.$t('commons.save_success'));
});
this.form.name = '';
}, },
refreshNode() {
this.$emit('refresh');
}
} }
} }
</script> </script>
......
...@@ -6,16 +6,14 @@ ...@@ -6,16 +6,14 @@
:data="testPlans" :data="testPlans"
:current-data="currentPlan" :current-data="currentPlan"
:title="$t('test_track.plan_view.plan')" :title="$t('test_track.plan_view.plan')"
@dataChange="changePlan"> @dataChange="changePlan"/>
</select-menu>
<plan-node-tree
class="node-tree"
:plan-id="planId"
@nodeSelectEvent="selectNodeIdsChange"
ref="tree">
</plan-node-tree>
<node-tree class="node-tree"
v-loading="result.loading"
@nodeSelectEvent="nodeChange"
@refresh="refresh"
:tree-nodes="treeNodes"
ref="nodeTree"/>
</el-aside> </el-aside>
<el-main> <el-main>
...@@ -25,35 +23,36 @@ ...@@ -25,35 +23,36 @@
:plan-id="planId" :plan-id="planId"
:select-node-ids="selectNodeIds" :select-node-ids="selectNodeIds"
:select-node-names="selectNodeNames" :select-node-names="selectNodeNames"
ref="testCasePlanList"></test-plan-test-case-list> ref="testCasePlanList"/>
</el-main> </el-main>
</el-container> </el-container>
<test-case-relevance <test-case-relevance
@refresh="refresh" @refresh="refresh"
:plan-id="planId" :plan-id="planId"
ref="testCaseRelevance"> ref="testCaseRelevance"/>
</test-case-relevance>
</div> </div>
</template> </template>
<script> <script>
import PlanNodeTree from "./components/PlanNodeTree"; import NodeTree from "../common/NodeTree";
import TestPlanTestCaseList from "./components/TestPlanTestCaseList"; import TestPlanTestCaseList from "./components/TestPlanTestCaseList";
import TestCaseRelevance from "./components/TestCaseRelevance"; import TestCaseRelevance from "./components/TestCaseRelevance";
import SelectMenu from "../common/SelectMenu"; import SelectMenu from "../common/SelectMenu";
export default { export default {
name: "TestPlanView", name: "TestPlanView",
components: {PlanNodeTree, TestPlanTestCaseList, TestCaseRelevance, SelectMenu}, components: {NodeTree, TestPlanTestCaseList, TestCaseRelevance, SelectMenu},
data() { data() {
return { return {
result: {},
testPlans: [], testPlans: [],
currentPlan: {}, currentPlan: {},
selectNodeIds: [], selectNodeIds: [],
selectNodeNames: [] selectNodeNames: [],
treeNodes: []
} }
}, },
computed: { computed: {
...@@ -61,23 +60,23 @@ ...@@ -61,23 +60,23 @@
return this.$route.params.planId; return this.$route.params.planId;
} }
}, },
created() { mounted() {
this.getTestPlans(); this.initData();
}, },
watch: { watch: {
planId() { planId() {
this.getTestPlans(); this.initData();
} }
}, },
methods: { methods: {
refresh() { refresh() {
this.selectNodeIds = []; this.selectNodeIds = [];
this.selectNodeNames = []; this.selectNodeNames = [];
this.$refs.tree.initTree(); this.getNodeTreeByPlanId();
}, },
selectNodeIdsChange(nodeIds, nodeNames) { initData() {
this.selectNodeNames = nodeNames; this.getTestPlans();
this.selectNodeIds = nodeIds; this.getNodeTreeByPlanId();
}, },
openTestCaseRelevanceDialog() { openTestCaseRelevanceDialog() {
this.$refs.testCaseRelevance.openTestCaseRelevanceDialog(); this.$refs.testCaseRelevance.openTestCaseRelevanceDialog();
...@@ -92,9 +91,20 @@ ...@@ -92,9 +91,20 @@
}); });
}); });
}, },
nodeChange(nodeIds, nodeNames) {
this.selectNodeIds = nodeIds;
this.selectNodeNames = nodeNames;
},
changePlan(plan) { changePlan(plan) {
this.currentPlan = plan; this.currentPlan = plan;
this.$router.push('/track/plan/view/' + plan.id); this.$router.push('/track/plan/view/' + plan.id);
},
getNodeTreeByPlanId() {
if(this.planId){
this.result = this.$get("/case/node/list/plan/" + this.planId, response => {
this.treeNodes = response.data;
});
}
} }
} }
} }
......
...@@ -9,12 +9,11 @@ ...@@ -9,12 +9,11 @@
<el-container class="main-content"> <el-container class="main-content">
<el-aside class="node-tree" width="250px"> <el-aside class="node-tree" width="250px">
<plan-node-tree <node-tree class="node-tree"
:tree-nodes="treeNodes" @nodeSelectEvent="nodeChange"
:plan-id="planId" @refresh="refresh"
:showAll=true :tree-nodes="treeNodes"
@nodeSelectEvent="getCaseNameByNodeIds" ref="nodeTree"/>
ref="tree"></plan-node-tree>
</el-aside> </el-aside>
<el-container> <el-container>
...@@ -45,32 +44,22 @@ ...@@ -45,32 +44,22 @@
</el-container> </el-container>
<template v-slot:footer> <template v-slot:footer>
<div class="dialog-footer"> <ms-dialog-footer @cancel="dialogFormVisible = false" @confirm="saveCaseRelevance"/>
<el-button
@click="dialogFormVisible = false">
{{$t('test_track.cancel')}}
</el-button>
<el-button
type="primary"
@click="saveCaseRelevance">
{{$t('test_track.confirm')}}
</el-button>
</div>
</template> </template>
</el-dialog>
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
import PlanNodeTree from './PlanNodeTree'; import NodeTree from '../../common/NodeTree';
import MsDialogFooter from '../../../common/components/MsDialogFooter'
export default { export default {
name: "TestCaseRelevance", name: "TestCaseRelevance",
components: {PlanNodeTree}, components: {NodeTree, MsDialogFooter},
data() { data() {
return { return {
result: {}, result: {},
...@@ -78,7 +67,9 @@ ...@@ -78,7 +67,9 @@
isCheckAll: false, isCheckAll: false,
testCases: [], testCases: [],
selectIds: new Set(), selectIds: new Set(),
treeNodes: [] treeNodes: [],
selectNodeIds: [],
selectNodeNames: []
}; };
}, },
props: { props: {
...@@ -88,12 +79,15 @@ ...@@ -88,12 +79,15 @@
}, },
watch: { watch: {
planId() { planId() {
this.initData();
},
selectNodeIds() {
this.getCaseNames(); this.getCaseNames();
} }
}, },
methods: { methods: {
openTestCaseRelevanceDialog() { openTestCaseRelevanceDialog() {
this.getCaseNames(); this.initData();
this.dialogFormVisible = true; this.dialogFormVisible = true;
}, },
saveCaseRelevance(){ saveCaseRelevance(){
...@@ -107,13 +101,13 @@ ...@@ -107,13 +101,13 @@
this.$emit('refresh'); this.$emit('refresh');
}); });
}, },
getCaseNames(nodeIds) { getCaseNames() {
let param = {}; let param = {};
if (this.planId) { if (this.planId) {
param.planId = this.planId; param.planId = this.planId;
} }
if (nodeIds && nodeIds.length > 0){ if (this.selectNodeIds && this.selectNodeIds.length > 0){
param.nodeIds = nodeIds; param.nodeIds = this.selectNodeIds;
} }
this.result = this.$post('/test/case/name', param, response => { this.result = this.$post('/test/case/name', param, response => {
this.testCases = response.data; this.testCases = response.data;
...@@ -122,10 +116,6 @@ ...@@ -122,10 +116,6 @@
}); });
}); });
}, },
getCaseNameByNodeIds(nodeIds) {
this.dialogFormVisible = true;
this.getCaseNames(nodeIds);
},
handleSelectAll(selection) { handleSelectAll(selection) {
if(selection.length > 0){ if(selection.length > 0){
this.testCases.forEach(item => { this.testCases.forEach(item => {
...@@ -142,8 +132,28 @@ ...@@ -142,8 +132,28 @@
this.selectIds.add(row.id); this.selectIds.add(row.id);
} }
}, },
nodeChange(nodeIds, nodeNames) {
this.selectNodeIds = nodeIds;
this.selectNodeNames = nodeNames;
},
initData() {
this.getCaseNames();
this.getAllNodeTreeByPlanId();
},
refresh() {
this.close();
},
getAllNodeTreeByPlanId() {
if (this.planId) {
this.result = this.$get("/case/node/list/all/plan/" + this.planId, response => {
this.treeNodes = response.data;
});
}
},
close() { close() {
this.selectIds.clear(); this.selectIds.clear();
this.selectNodeIds = [];
this.selectNodeNames = [];
} }
} }
} }
......
...@@ -156,7 +156,7 @@ ...@@ -156,7 +156,7 @@
</template> </template>
<script> <script>
import PlanNodeTree from './PlanNodeTree'; import PlanNodeTree from '../../common/PlanNodeTree';
import ExecutorEdit from './ExecutorEdit'; import ExecutorEdit from './ExecutorEdit';
import StatusEdit from './StatusEdit'; import StatusEdit from './StatusEdit';
import TestPlanTestCaseEdit from "../components/TestPlanTestCaseEdit"; import TestPlanTestCaseEdit from "../components/TestPlanTestCaseEdit";
...@@ -303,7 +303,6 @@ ...@@ -303,7 +303,6 @@
float: right; float: right;
} }
.el-breadcrumb { .el-breadcrumb {
display: inline-block; display: inline-block;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册