fix: 脑图复制粘贴新增失败

This commit is contained in:
chenjianxing 2021-06-04 17:28:03 +08:00 committed by jianxing
parent 386eb45501
commit f6fb7fed22
3 changed files with 46 additions and 23 deletions

View File

@ -52,7 +52,7 @@
"vue-float-action-button": "^0.6.6", "vue-float-action-button": "^0.6.6",
"vue-i18n": "^8.15.3", "vue-i18n": "^8.15.3",
"vue-jsonpath-picker": "^1.1.5", "vue-jsonpath-picker": "^1.1.5",
"vue-minder-editor-plus": "^1.0.26", "vue-minder-editor-plus": "^1.0.27",
"vue-papa-parse": "^2.0.0", "vue-papa-parse": "^2.0.0",
"vue-pdf": "^4.2.0", "vue-pdf": "^4.2.0",
"vue-router": "^3.1.3", "vue-router": "^3.1.3",

View File

@ -18,6 +18,7 @@
<script> <script>
import MsModuleMinder from "@/business/components/common/components/MsModuleMinder"; import MsModuleMinder from "@/business/components/common/components/MsModuleMinder";
import { import {
handleAfterSave,
handleExpandToLevel, handleTestCaseAdd, handTestCaeEdit, handleExpandToLevel, handleTestCaseAdd, handTestCaeEdit,
listenBeforeExecCommand, listenBeforeExecCommand,
listenNodeSelected, listenNodeSelected,
@ -81,29 +82,24 @@ name: "TestCaseMinder",
methods: { methods: {
handleAfterMount() { handleAfterMount() {
listenNodeSelected(() => { listenNodeSelected(() => {
let param = { loadSelectNodes(this.getParam(), getTestCasesForMinder);
request: {
projectId: this.projectId,
},
result: this.result,
isDisable: false
}
loadSelectNodes(param, getTestCasesForMinder);
}); });
listenBeforeExecCommand((even) => { listenBeforeExecCommand((even) => {
if (even.commandName === 'expandtolevel') { if (even.commandName === 'expandtolevel') {
let level = Number.parseInt(even.commandArgs); let level = Number.parseInt(even.commandArgs);
let param = { handleExpandToLevel(level, even.minder.getRoot(), this.getParam(), getTestCasesForMinder);
request: {
projectId: this.projectId,
},
result: this.result,
isDisable: false
}
handleExpandToLevel(level, even.minder.getRoot(), param, getTestCasesForMinder);
} }
}); });
}, },
getParam() {
return {
request: {
projectId: this.projectId,
},
result: this.result,
isDisable: false
}
},
save(data) { save(data) {
let saveCases = []; let saveCases = [];
let deleteCases = []; let deleteCases = [];
@ -115,6 +111,7 @@ name: "TestCaseMinder",
} }
this.result = this.$post('/test/case/minder/edit', param, () => { this.result = this.$post('/test/case/minder/edit', param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
handleAfterSave(window.minder.getRoot(), this.getParam());
}); });
}, },
buildSaveCase(root, saveCases, deleteCases, parent) { buildSaveCase(root, saveCases, deleteCases, parent) {
@ -126,10 +123,15 @@ name: "TestCaseMinder",
if (deleteChild && deleteChild.length > 0) { if (deleteChild && deleteChild.length > 0) {
deleteCases.push(...deleteChild); deleteCases.push(...deleteChild);
} }
if (data.type !== 'node') {
let tip = '用例(' + data.text + ')未添加用例标签!';
this.$error(tip)
throw new Error(tip);
}
if (root.children) { if (root.children) {
root.children.forEach((childNode) => { root.children.forEach((childNode) => {
this.buildSaveCase(childNode, saveCases, deleteCases, root.data); this.buildSaveCase(childNode, saveCases, deleteCases, root.data);
}) });
} }
} }
}, },

View File

@ -1,4 +1,5 @@
import i18n from "@/i18n/i18n"; import i18n from "@/i18n/i18n";
import {getTestCasesForMinder} from "@/network/testCase";
export function listenNodeSelected(callback) { export function listenNodeSelected(callback) {
let minder = window.minder; let minder = window.minder;
@ -222,7 +223,7 @@ function getNodeData(text, resource, isDisable) {
* @param result * @param result
*/ */
export function appendCaseNodes(parent, testCases, param, setParamCallback) { export function appendCaseNodes(parent, testCases, param, setParamCallback) {
wipeTmp(parent); clearChildren(parent);
if (testCases) { if (testCases) {
for (let i = 0; i < testCases.length; i++) { for (let i = 0; i < testCases.length; i++) {
appendCase(parent, testCases[i], param.isDisable, setParamCallback); appendCase(parent, testCases[i], param.isDisable, setParamCallback);
@ -235,17 +236,17 @@ export function appendCaseNodes(parent, testCases, param, setParamCallback) {
} }
/** /**
* 去掉临时节点 * 去掉已有节点
* @param parent * @param parent
*/ */
function wipeTmp(node) { function clearChildren(node) {
let children = node.children; let children = node.children;
if (children) { if (children) {
for (let i = 0; i < children.length; i++) { for (let i = 0; i < children.length; i++) {
let item = children[i]; let item = children[i];
if (item.data.type === 'tmp') { if (item.data.type !== 'node') {
window.minder.removeNode(item); window.minder.removeNode(item);
break; i--;
} }
} }
} }
@ -334,3 +335,23 @@ export function priorityDisableCheck() {
} }
return false; return false;
} }
export function handleAfterSave(pNode, param) {
let children = pNode.children;
if (children) {
for (let i = 0; i < children.length; i++) {
let item = children[i];
if (item.data.id === null || (item.data.id && item.data.id.length < 20)) {
pNode.data.loaded = false;
loadNode(pNode, param, getTestCasesForMinder);
return;
}
if (item.data.changed) {
item.data.changed = false;
}
if (item.data.type === 'node') {
handleAfterSave(item, param);
}
}
}
}