测试用例项目显示问题

This commit is contained in:
chenjianxing 2020-04-02 09:30:23 +08:00
parent 810927feb9
commit 4f16362954
6 changed files with 44 additions and 18 deletions

View File

@ -65,7 +65,7 @@
<script> <script>
import MsCreateBox from "../settings/CreateBox"; import MsCreateBox from "../settings/CreateBox";
import {Message} from "element-ui"; import {Message} from "element-ui";
import {TokenKey} from "../../../common/constants"; import {TokenKey,CURRENT_PROJECT} from "../../../common/constants";
export default { export default {
name: "MsProject", name: "MsProject",
@ -166,6 +166,10 @@
this.$get('/project/delete/' + row.id, () => { this.$get('/project/delete/' + row.id, () => {
Message.success(this.$t('commons.delete_success')); Message.success(this.$t('commons.delete_success'));
this.list(); this.list();
let currentProject = JSON.parse(localStorage.getItem(CURRENT_PROJECT));
if(currentProject && row.id === currentProject.id){
localStorage.removeItem(CURRENT_PROJECT);
}
}); });
}).catch(() => { }).catch(() => {
}); });

View File

@ -9,14 +9,16 @@
<template slot="title"> <template slot="title">
{{currentProject == null ? '' : currentProject.name}} {{currentProject == null ? '' : currentProject.name}}
</template> </template>
<el-scrollbar style="height:500px"> <div style="height:400px;">
<el-scrollbar style="height:100%">
<label v-for="(item,index) in projects" :key="index"> <label v-for="(item,index) in projects" :key="index">
<el-menu-item @click="changeProject(item)"> <el-menu-item @click="changeProject(item)">
{{item.name}} {{item.name}}
<i class="el-icon-check" v-if="item.id === currentProject.id"></i> <i class="el-icon-check" v-if="item.id === currentProject.id"></i>
</el-menu-item> </el-menu-item>
</label> </label>
</el-scrollbar> </el-scrollbar>
</div>
</el-submenu> </el-submenu>
</el-menu> </el-menu>
<node-tree class="node_tree" <node-tree class="node_tree"
@ -47,7 +49,7 @@
import NodeTree from './components/NodeTree'; import NodeTree from './components/NodeTree';
import TestCaseEdit from './components/TestCaseEdit'; import TestCaseEdit from './components/TestCaseEdit';
import {WORKSPACE_ID} from '../../../../common/constants'; import {WORKSPACE_ID,CURRENT_PROJECT} from '../../../../common/constants';
import TestCaseList from "./components/TestCaseList"; import TestCaseList from "./components/TestCaseList";
export default { export default {
@ -74,17 +76,28 @@
this.projectId = this.$route.params.projectId; this.projectId = this.$route.params.projectId;
this.getProjects(); this.getProjects();
}, },
watch: {
'$route'(to, from) {
console.log(from);
console.log(to);
if (from.name.indexOf("Project") > 0){
this.getProjects();
}
}
},
methods: { methods: {
getProjects() { getProjects() {
this.$get("/project/listAll", (response) => { this.$get("/project/listAll", (response) => {
if (response.success) { if (response.success) {
this.projects = response.data; this.projects = response.data;
this.initProjects = this.projects.slice(0, 4); this.initProjects = this.projects.slice(0, 4);
if(localStorage.getItem('currentProject')) { if(localStorage.getItem(CURRENT_PROJECT)) {
this.currentProject = JSON.parse(localStorage.getItem('currentProject')); this.currentProject = JSON.parse(localStorage.getItem(CURRENT_PROJECT));
} else { } else {
this.currentProject = this.projects[0]; this.currentProject = this.projects[0];
localStorage.setItem('currentProject', JSON.stringify(this.projects[0])); if(this.projects.length > 0){
localStorage.setItem(CURRENT_PROJECT, JSON.stringify(this.projects[0]));
}
} }
} else { } else {
this.$message()({ this.$message()({
@ -93,7 +106,7 @@
}); });
} }
this.loadingRequire.project = false; this.loadingRequire.project = false;
this.checkProject(); // this.checkProject();
}); });
}, },
checkProject() { checkProject() {
@ -108,7 +121,7 @@
}, },
changeProject(project) { changeProject(project) {
this.currentProject = project; this.currentProject = project;
localStorage.setItem('currentProject', JSON.stringify(project)); localStorage.setItem(CURRENT_PROJECT, JSON.stringify(project));
this.$refs.testCaseList.initTableData() this.$refs.testCaseList.initTableData()
this.$refs.nodeTree.getNodeTree(); this.$refs.nodeTree.getNodeTree();
}, },

View File

@ -60,6 +60,9 @@
</template> </template>
<script> <script>
import {CURRENT_PROJECT} from '../../../../../common/constants';
export default { export default {
name: "NodeTree", name: "NodeTree",
data() { data() {
@ -133,7 +136,7 @@
}, },
getChildNodeId(rootNode, nodeIds) { getChildNodeId(rootNode, nodeIds) {
//ID //ID
nodeIds.push(rootNode.data.id) nodeIds.push(rootNode.data.id);
for (let i = 0; i < rootNode.childNodes.length; i++){ for (let i = 0; i < rootNode.childNodes.length; i++){
this.getChildNodeId(rootNode.childNodes[i], nodeIds); this.getChildNodeId(rootNode.childNodes[i], nodeIds);
} }
@ -153,8 +156,8 @@
this.dialogFormVisible = true; this.dialogFormVisible = true;
}, },
getNodeTree() { getNodeTree() {
if(localStorage.getItem('currentProject')){ if(localStorage.getItem(CURRENT_PROJECT)) {
let projectId = JSON.parse(localStorage.getItem('currentProject')).id; let projectId = JSON.parse(localStorage.getItem(CURRENT_PROJECT)).id;
this.$get("/case/node/list/" + projectId, response => { this.$get("/case/node/list/" + projectId, response => {
this.treeNodes = response.data; this.treeNodes = response.data;
}); });
@ -180,8 +183,8 @@
param.name = this.form.name; param.name = this.form.name;
param.label = this.form.name; param.label = this.form.name;
if(localStorage.getItem('currentProject')){ if(localStorage.getItem(CURRENT_PROJECT)) {
param.projectId = JSON.parse(localStorage.getItem('currentProject')).id; param.projectId = JSON.parse(localStorage.getItem(CURRENT_PROJECT)).id;
} }
this.$post(url, param, response => { this.$post(url, param, response => {

View File

@ -180,6 +180,9 @@
</template> </template>
<script> <script>
import {CURRENT_PROJECT} from '../../../../../common/constants';
export default { export default {
name: "TestCaseEdit", name: "TestCaseEdit",
data() { data() {
@ -261,8 +264,8 @@
param.nodePath = item.path; param.nodePath = item.path;
} }
}); });
if(localStorage.getItem('currentProject')){ if(localStorage.getItem(CURRENT_PROJECT)) {
param.projectId = JSON.parse(localStorage.getItem('currentProject')).id; param.projectId = JSON.parse(localStorage.getItem(CURRENT_PROJECT)).id;
} }
this.$post('/test/case/' + this.operationType, param, () => { this.$post('/test/case/' + this.operationType, param, () => {
this.$message.success(this.$t('commons.save_success')); this.$message.success(this.$t('commons.save_success'));

View File

@ -119,6 +119,8 @@
</template> </template>
<script> <script>
import {CURRENT_PROJECT} from '../../../../../common/constants';
export default { export default {
name: "TestCaseList", name: "TestCaseList",
data() { data() {
@ -146,8 +148,8 @@
}; };
param.nodeIds = nodeIds; param.nodeIds = nodeIds;
if(localStorage.getItem('currentProject')){ if(localStorage.getItem(CURRENT_PROJECT)) {
param.projectId = JSON.parse(localStorage.getItem('currentProject')).id; param.projectId = JSON.parse(localStorage.getItem(CURRENT_PROJECT)).id;
} }
this.$post(this.buildPagePath('/test/case/list'), param, response => { this.$post(this.buildPagePath('/test/case/list'), param, response => {

View File

@ -7,3 +7,4 @@ export const ROLE_TEST_USER = 'test_user';
export const ROLE_TEST_VIEWER = 'test_viewer'; export const ROLE_TEST_VIEWER = 'test_viewer';
export const WORKSPACE_ID = 'workspace_id'; export const WORKSPACE_ID = 'workspace_id';
export const CURRENT_PROJECT = 'current_project';