refactor(测试跟踪): 用例编辑减少loading次数

This commit is contained in:
chenjianxing 2023-03-09 15:43:20 +08:00 committed by jianxing
parent 2d525c0fd2
commit 78bdc78ef6
7 changed files with 84 additions and 93 deletions

View File

@ -53,6 +53,7 @@ import io.metersphere.service.remote.project.TrackIssueTemplateService;
import io.metersphere.service.wapper.TrackProjectService; import io.metersphere.service.wapper.TrackProjectService;
import io.metersphere.service.wapper.UserService; import io.metersphere.service.wapper.UserService;
import io.metersphere.utils.DistinctKeyUtil; import io.metersphere.utils.DistinctKeyUtil;
import io.metersphere.xpack.track.dto.AttachmentRequest;
import io.metersphere.xpack.track.dto.PlatformStatusDTO; import io.metersphere.xpack.track.dto.PlatformStatusDTO;
import io.metersphere.xpack.track.dto.PlatformUser; import io.metersphere.xpack.track.dto.PlatformUser;
import io.metersphere.xpack.track.dto.*; import io.metersphere.xpack.track.dto.*;

View File

@ -175,7 +175,7 @@ export default {
}, },
computed: { computed: {
edit() { edit() {
return this.editable || this.selfEditable || this.hoverEditable; return this.editable;
}, },
}, },
mounted() { mounted() {

View File

@ -23,7 +23,7 @@
<!-- 版本历史 v-xpack --> <!-- 版本历史 v-xpack -->
<mx-version-history <mx-version-history
v-xpack v-xpack
v-if="versionEnable" v-show="versionEnable"
ref="versionHistory" ref="versionHistory"
:current-id="currentTestCaseInfo.id" :current-id="currentTestCaseInfo.id"
:is-read="readOnly" :is-read="readOnly"
@ -240,11 +240,11 @@
:project-id="projectId" :project-id="projectId"
:form="form" :form="form"
:is-form-alive="isFormAlive" :is-form-alive="isFormAlive"
:isloading="loading" :is-loading="loading"
:read-only="readOnly || !editable" :read-only="readOnly || !editable"
:enable-default-module="!caseId"
:public-enable="isPublicShow" :public-enable="isPublicShow"
:show-input-tag="showInputTag" :show-input-tag="showInputTag"
:tree-nodes="treeNodes"
:project-list="projectList" :project-list="projectList"
:custom-field-form="customFieldForm" :custom-field-form="customFieldForm"
:custom-field-rules="customFieldRules" :custom-field-rules="customFieldRules"
@ -376,11 +376,9 @@ import {
testCaseEditFollows, testCaseEditFollows,
testCaseGetByVersionId, testCaseGetByVersionId,
testCaseDeleteToGc, testCaseDeleteToGc,
getTestCaseNodesByCaseFilter,
getTestCaseByVersionId, getTestCaseByVersionId,
getEditSimpleTestCase, getEditSimpleTestCase,
getSimpleTestCase, getSimpleTestCase,
testCaseBatchEdit,
} from "@/api/testCase"; } from "@/api/testCase";
import { import {
@ -395,7 +393,6 @@ import CaseEditInfoComponent from "./case/CaseEditInfoComponent";
import CaseBaseInfo from "./case/CaseBaseInfo"; import CaseBaseInfo from "./case/CaseBaseInfo";
import PriorityTableItem from "../../common/tableItems/planview/PriorityTableItem"; import PriorityTableItem from "../../common/tableItems/planview/PriorityTableItem";
import MxVersionHistory from "./common/CaseVersionHistory" import MxVersionHistory from "./common/CaseVersionHistory"
import {buildTree} from "metersphere-frontend/src/model/NodeTree";
import {getProject, versionEnableByProjectId} from "@/api/project"; import {getProject, versionEnableByProjectId} from "@/api/project";
import {openCaseEdit} from "@/business/case/test-case"; import {openCaseEdit} from "@/business/case/test-case";
import ListItemDeleteConfirm from "metersphere-frontend/src/components/ListItemDeleteConfirm"; import ListItemDeleteConfirm from "metersphere-frontend/src/components/ListItemDeleteConfirm";
@ -456,7 +453,6 @@ export default {
form: { form: {
name: "", name: "",
num: '', num: '',
module: "default-module",
nodePath: "/未规划用例", nodePath: "/未规划用例",
maintainer: getCurrentUser().id, maintainer: getCurrentUser().id,
priority: "P0", priority: "P0",
@ -502,7 +498,7 @@ export default {
trigger: "blur", trigger: "blur",
}, },
], ],
module: [ nodeId: [
{ {
required: true, required: true,
message: this.$t("test_track.case.input_module"), message: this.$t("test_track.case.input_module"),
@ -572,7 +568,6 @@ export default {
isClickAttachmentTab: false, isClickAttachmentTab: false,
latestVersionId: "", latestVersionId: "",
hasLatest: false, hasLatest: false,
treeNodes: [],
currentTestCaseInfo: {}, currentTestCaseInfo: {},
currentVersionName: "", currentVersionName: "",
versionEnable: false, versionEnable: false,
@ -754,6 +749,13 @@ export default {
setIsLastedVersion(isLastedVersion) { setIsLastedVersion(isLastedVersion) {
this.isLastedVersion = isLastedVersion; this.isLastedVersion = isLastedVersion;
}, },
async freshTestCase(caseId) {
this.loading = true;
this.routerToEdit(caseId);
this.$nextTick(() => {
this.initEdit();
});
},
async loadTestCase() { async loadTestCase() {
if (localStorage.getItem('projectChangeFlag')) { if (localStorage.getItem('projectChangeFlag')) {
@ -761,6 +763,10 @@ export default {
return; return;
} }
if (this.isPublicShow) {
this.resetForm();
}
let initFuc = this.initEdit; let initFuc = this.initEdit;
this.loading = true; this.loading = true;
@ -791,22 +797,6 @@ export default {
}); });
} }
if (!this.isPublicShow) {
//
getTestCaseNodesByCaseFilter(this.projectId, {})
.then(r => {
this.treeNodes = r.data;
this.treeNodes.forEach(node => {
node.name = node.name === '未规划用例' ? this.$t('api_test.unplanned_case') : node.name
buildTree(node, {path: ''});
});
if (!this.caseId) {
// ID
this.setDefaultModule();
}
});
}
getTestCaseFollow(this.caseId).then((response) => { getTestCaseFollow(this.caseId).then((response) => {
this.form.follows = response.data; this.form.follows = response.data;
for (let i = 0; i < response.data.length; i++) { for (let i = 0; i < response.data.length; i++) {
@ -993,7 +983,6 @@ export default {
history.pushState(null, null, document.URL); history.pushState(null, null, document.URL);
window.addEventListener("popstate", this.close); window.addEventListener("popstate", this.close);
} }
this.resetForm();
listenGoBack(this.close); listenGoBack(this.close);
if (this.caseId) { if (this.caseId) {
@ -1030,11 +1019,6 @@ export default {
callback(); callback();
} }
}, },
setDefaultModule() {
if (this.$refs.testCaseBaseInfo) {
this.$refs.testCaseBaseInfo.doSetDefaultModule(this.treeNodes);
}
},
async checkCurrentProject() { async checkCurrentProject() {
if (this.isPublicShow) { if (this.isPublicShow) {
// //
@ -1145,9 +1129,6 @@ export default {
} }
this.casePublic = tmp.casePublic; this.casePublic = tmp.casePublic;
this.form.module = testCase.nodeId;
this.$refs.testCaseBaseInfo.setDefaultModule();
// //
this.customFieldForm = parseCustomField( this.customFieldForm = parseCustomField(
this.form, this.form,
@ -1223,7 +1204,7 @@ export default {
.then((response) => { .then((response) => {
if (this.editableState) { if (this.editableState) {
// , reload // , reload
location.reload(); this.editableState = false;
} }
response = response.data; response = response.data;
// //
@ -1246,14 +1227,15 @@ export default {
if (this.createVersionId) { if (this.createVersionId) {
// //
this.createVersionId = null; this.createVersionId = null;
this.routerToEdit(response.data.id); this.freshTestCase(response.data.id);
} }
} else { } else {
param.id = response.data.id; param.id = response.data.id;
this.close(); this.close();
if (this.saveType === 2) { if (this.saveType === 2) {
// //
location.reload(); this.resetForm();
this.initEdit();
} else { } else {
this.isLastedVersion = true; this.isLastedVersion = true;
this.routerToEdit(response.data.id); this.routerToEdit(response.data.id);
@ -1269,9 +1251,6 @@ export default {
}, },
routerToEdit(id) { routerToEdit(id) {
this.$router.push({path: '/track/case/edit/' + id}); this.$router.push({path: '/track/case/edit/' + id});
setTimeout(() => {
window.location.reload();
}, 300);
}, },
buildParam() { buildParam() {
let param = {}; let param = {};
@ -1280,7 +1259,6 @@ export default {
} }
Object.assign(param, this.form); Object.assign(param, this.form);
param.steps = JSON.stringify(this.form.steps); param.steps = JSON.stringify(this.form.steps);
param.nodeId = this.form.module;
param.copyCaseId = this.caseId; param.copyCaseId = this.caseId;
param.projectId = this.projectId; param.projectId = this.projectId;
@ -1415,7 +1393,7 @@ export default {
}, },
_resetForm() { _resetForm() {
this.form.name = ""; this.form.name = "";
this.form.module = ""; this.form.nodeId = "";
this.form.type = ""; this.form.type = "";
this.form.method = ""; this.form.method = "";
this.form.maintainer = ""; this.form.maintainer = "";
@ -1540,7 +1518,7 @@ export default {
}); });
}, },
checkout(testCase) { checkout(testCase) {
this.routerToEdit(testCase.id); this.freshTestCase(testCase.id);
}, },
validateForm() { validateForm() {
let isValidate = true; let isValidate = true;
@ -1564,12 +1542,12 @@ export default {
for (let i = 0; i < customFieldFormFields.length; i++) { for (let i = 0; i < customFieldFormFields.length; i++) {
let customField = customFieldFormFields[i]; let customField = customFieldFormFields[i];
if (customField.validateState === "error") { if (customField.validateState === "error") {
let name = customField.label || customField.labelFor;
if (this.currentValidateName) { if (this.currentValidateName) {
this.currentValidateName = this.currentValidateName =
this.currentValidateName + "," + customField.label; this.currentValidateName + "," + name;
} else { } else {
this.currentValidateName = this.currentValidateName = name;
customField.label || customField.labelFor;
} }
} }
} }

View File

@ -1,6 +1,6 @@
<template> <template>
<!-- 功能用例编辑页面右侧基本信息--> <!-- 功能用例编辑页面右侧基本信息-->
<div v-loading="isloading" class="case-base-info-form"> <div v-loading="isLoading" class="case-base-info-form">
<el-form ref="caseFrom" :rules="headerRules" :model="form" class="case-padding"> <el-form ref="caseFrom" :rules="headerRules" :model="form" class="case-padding">
<!-- ID及自定义ID --> <!-- ID及自定义ID -->
<div class="id-row case-wrap" v-if="!editable || isCustomNum"> <div class="id-row case-wrap" v-if="!editable || isCustomNum">
@ -92,7 +92,7 @@
<div class="required required-item"></div> <div class="required required-item"></div>
</div> </div>
<div class="side-content"> <div class="side-content" v-if="treeNodes">
<base-edit-item-component <base-edit-item-component
:editable="editable" :editable="editable"
:auto-save="!readOnly" :auto-save="!readOnly"
@ -114,7 +114,7 @@
:disabled="readOnly" :disabled="readOnly"
:data="treeNodes" :data="treeNodes"
:obj="moduleObj" :obj="moduleObj"
:default-key="defaultModuleKey" :default-key="form.nodeId"
@getValue="setModule" @getValue="setModule"
clearable clearable
checkStrictly checkStrictly
@ -344,6 +344,8 @@ import CustomFiledFormRow from "./CaseCustomFiledFormRow";
import { useStore } from "@/store"; import { useStore } from "@/store";
import BaseEditItemComponent from "../BaseEditItemComponent"; import BaseEditItemComponent from "../BaseEditItemComponent";
import { issueDemandList } from "@/api/issue"; import { issueDemandList } from "@/api/issue";
import {getTestCaseNodesByCaseFilter} from "@/api/testCase";
import {buildTree} from "@/business/utils/sdk-utils";
export default { export default {
name: "CaseBaseInfo", name: "CaseBaseInfo",
components: { components: {
@ -365,8 +367,7 @@ export default {
this.buildDemandOptions(); this.buildDemandOptions();
}, },
projectId() { projectId() {
this.getDemandOptions(); this.init();
this.getVersionOptions();
} }
}, },
data() { data() {
@ -429,7 +430,7 @@ export default {
trigger: "blur", trigger: "blur",
}, },
], ],
module: [ nodeId: [
{ {
required: true, required: true,
message: this.$t("test_track.case.input_module"), message: this.$t("test_track.case.input_module"),
@ -448,7 +449,8 @@ export default {
demandOptions: [], demandOptions: [],
versionFilters: [], versionFilters: [],
demandList: [], demandList: [],
defaultModuleKey: '' defaultModuleKey: '',
treeNodes: null,
}; };
}, },
props: { props: {
@ -456,11 +458,10 @@ export default {
editableState: Boolean, editableState: Boolean,
form: Object, form: Object,
isFormAlive: Boolean, isFormAlive: Boolean,
isloading: Boolean, isLoading: Boolean,
readOnly: Boolean, readOnly: Boolean,
publicEnable: Boolean, publicEnable: Boolean,
showInputTag: Boolean, showInputTag: Boolean,
treeNodes: Array,
projectList: Array, projectList: Array,
customFieldForm: Object, customFieldForm: Object,
customFieldRules: Object, customFieldRules: Object,
@ -468,6 +469,7 @@ export default {
defaultOpen: String, defaultOpen: String,
versionEnable: Boolean, versionEnable: Boolean,
projectId: String, projectId: String,
enableDefaultModule: Boolean
}, },
computed: { computed: {
isCustomNum() { isCustomNum() {
@ -478,32 +480,53 @@ export default {
} }
}, },
mounted() { mounted() {
this.getDemandOptions(); this.init();
this.getVersionOptions();
}, },
methods: { methods: {
setDefaultModule() { init() {
this.doSetDefaultModule(this.treeNodes); this.getDemandOptions();
this.getVersionOptions();
this.getNodeTrees();
}, },
doSetDefaultModule(treeNodes) { setDefaultModule(treeNodes) {
if (this.enableDefaultModule) {
// ID
if (treeNodes && treeNodes.length > 0) { if (treeNodes && treeNodes.length > 0) {
if (this.createNodeId) { if (this.createNodeId) {
// //
this.form.module = this.createNodeId; this.form.nodeId = this.createNodeId;
let node = this.findTreeNode(treeNodes);
this.form.nodePath = node.path;
} else if (this.form.module) {
// nodePath
let node = this.findTreeNode(treeNodes); let node = this.findTreeNode(treeNodes);
this.form.nodePath = node ? node.path : ''; this.form.nodePath = node ? node.path : '';
} else { } else {
// ID // ID
this.form.module = treeNodes[0].id; this.form.nodeId = treeNodes[0].id;
this.form.nodePath = treeNodes[0].path; this.form.nodePath = treeNodes[0].path;
} }
this.defaultModuleKey = this.form.module;
this.$refs.moduleTree.setData(this.form.module);
} }
} else {
if (this.form.nodeId) {
// nodePath
let node = this.findTreeNode(treeNodes);
this.form.nodePath = node ? node.path : '';
}
}
},
getNodeTrees() {
if (this.publicEnable || !this.projectId) {
return;
}
getTestCaseNodesByCaseFilter(this.projectId, {})
.then(r => {
let treeNodes = r.data;
treeNodes.forEach(node => {
node.name = node.name === '未规划用例' ? this.$t('api_test.unplanned_case') : node.name
buildTree(node, {path: ''});
});
this.setDefaultModule(treeNodes);
this.treeNodes = treeNodes;
});
}, },
handleDemandOptionPlatform(data){ handleDemandOptionPlatform(data){
if(data.platform){ if(data.platform){
@ -577,7 +600,7 @@ export default {
findTreeNode(nodeArray) { findTreeNode(nodeArray) {
for (let i = 0; i < nodeArray.length; i++) { for (let i = 0; i < nodeArray.length; i++) {
let node = nodeArray[i]; let node = nodeArray[i];
if (node.id === this.form.module) { if (node.id === this.form.nodeId) {
return node; return node;
} else { } else {
if (node.children && node.children.length > 0) { if (node.children && node.children.length > 0) {
@ -591,7 +614,7 @@ export default {
}, },
setModule(id, data) { setModule(id, data) {
if (data) { if (data) {
this.form.module = id; this.form.nodeId = id;
this.form.nodePath = data.path; this.form.nodePath = data.path;
} }
}, },

View File

@ -330,20 +330,6 @@ export default {
setRelationshipGraph(val) { setRelationshipGraph(val) {
this.$emit("syncRelationGraphOpen", val); this.$emit("syncRelationGraphOpen", val);
}, },
setModuleId(moduleId) {
let data = {
id: getUUID(),
resourceId: getCurrentProjectID(),
moduleId: moduleId,
projectId: getCurrentProjectID(),
fileName: this.dumpFile.name,
attachmentId: this.dumpFile.id,
};
dumpAttachment(data).then(() => {
this.$success(this.$t("organization.integration.successful_operation"));
});
},
getRelatedTest() { getRelatedTest() {
if (this.$refs.relateTest) { if (this.$refs.relateTest) {
this.$refs.relateTest.initTable(); this.$refs.relateTest.initTable();

View File

@ -46,10 +46,11 @@ export default {
}, },
computed: { computed: {
titleNum() { titleNum() {
if (!this.form.num) { let num = this.isCustomNum ? this.form.customNum : this.form.num;
if (!num) {
return ''; return '';
} }
return '【' + (this.isCustomNum ? this.form.customNum : this.form.num) + '】'; return `${num}`;
}, },
isCustomNum() { isCustomNum() {
return useStore().currentProjectIsCustomNum; return useStore().currentProjectIsCustomNum;

View File

@ -7,6 +7,8 @@ export {hasLicense, hasPermissions, hasPermission} from "metersphere-frontend/sr
export {get, post, downloadFile, fileDownloadGet, fileDownloadPost, fileUpload, generateShareUrl, generateModuleUrl} from "metersphere-frontend/src/plugins/request"; export {get, post, downloadFile, fileDownloadGet, fileDownloadPost, fileUpload, generateShareUrl, generateModuleUrl} from "metersphere-frontend/src/plugins/request";
export {CURRENT_LANGUAGE} from "metersphere-frontend/src/utils/constants"; export {CURRENT_LANGUAGE} from "metersphere-frontend/src/utils/constants";
export {CUSTOM_TABLE_HEADER} from "metersphere-frontend/src/utils/default-table-header"; export {CUSTOM_TABLE_HEADER} from "metersphere-frontend/src/utils/default-table-header";
export {buildTree} from "metersphere-frontend/src/model/NodeTree";
export {generateColumnKey, getAdvSearchCustomField} from "metersphere-frontend/src/components/search/custom-component"; export {generateColumnKey, getAdvSearchCustomField} from "metersphere-frontend/src/components/search/custom-component";