|
@@ -413,6 +413,7 @@
|
|
|
>隐藏表单
|
|
|
</el-button>
|
|
|
<el-button
|
|
|
+ v-if="isNodeType"
|
|
|
size="mini"
|
|
|
type="danger"
|
|
|
@click="handleDelete(scope.$index, scope.row)"
|
|
@@ -498,10 +499,11 @@
|
|
|
class="mg-l-10"
|
|
|
type="primary"
|
|
|
@click="handleEditFormula(scope.$index, scope.row)"
|
|
|
+ v-if="isNodeType"
|
|
|
>编辑元素公式
|
|
|
</el-link>
|
|
|
|
|
|
- <el-dropdown @command="handleCommand($event,scope.row)">
|
|
|
+ <el-dropdown @command="handleCommand($event,scope.row)" v-if="isNodeType">
|
|
|
<el-button type="text" class="mg-l-10">
|
|
|
表单同步<i class="el-icon-arrow-down el-icon--right"></i>
|
|
|
</el-button>
|
|
@@ -525,6 +527,7 @@
|
|
|
class="mg-l-10"
|
|
|
type="danger"
|
|
|
@click="handleDelete(scope.$index, scope.row)"
|
|
|
+ v-if="isNodeType"
|
|
|
>删除表单
|
|
|
</el-link>
|
|
|
</template>
|
|
@@ -3073,55 +3076,181 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
// 重新加载整棵树
|
|
|
+// async reloadEntireTree() {
|
|
|
+// this.isNodeType = false;
|
|
|
+
|
|
|
+// // 1. 保存当前选中节点key和路径
|
|
|
+// const tree = this.$refs.treeByType;
|
|
|
+// if (!tree) return;
|
|
|
+
|
|
|
+// const currentKey = tree.getCurrentKey();
|
|
|
+// let nodePath = [];
|
|
|
+// if (currentKey) {
|
|
|
+// const currentNode = tree.getNode(currentKey);
|
|
|
+// if (currentNode) {
|
|
|
+// // 获取选中节点的所有父节点路径
|
|
|
+// let parent = currentNode.parent;
|
|
|
+// while (parent && parent.level > 0) {
|
|
|
+// nodePath.unshift(parent.data.id);
|
|
|
+// parent = parent.parent;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// // 2. 清空缓存并记录所有已展开节点(用于后续重置)
|
|
|
+// const previouslyExpandedNodes = [];
|
|
|
+// const collectExpandedNodes = (node) => {
|
|
|
+// if (node.expanded && node.level > 0) {
|
|
|
+// previouslyExpandedNodes.push(node.data.id);
|
|
|
+// }
|
|
|
+// if (node.childNodes) {
|
|
|
+// node.childNodes.forEach(collectExpandedNodes);
|
|
|
+// }
|
|
|
+// };
|
|
|
+// collectExpandedNodes(tree.store.root);
|
|
|
+
|
|
|
+// this.cachedNodes.clear();
|
|
|
+
|
|
|
+// // 3. 清空根节点子节点
|
|
|
+// const rootNode = tree.store.root;
|
|
|
+// const rootId = rootNode.childNodes[0].data.id || 'root';
|
|
|
+// await this.$nextTick();
|
|
|
+// tree.updateKeyChildren(rootId, []);
|
|
|
+
|
|
|
+// // 4. 强制重新加载根节点
|
|
|
+// const root = tree.getNode(rootId);
|
|
|
+// if (root) {
|
|
|
+// root.loaded = false;
|
|
|
+// root.expand(); // 这会触发loadNodeByType
|
|
|
+// }
|
|
|
+
|
|
|
+// // 5. 等待树重新加载完成
|
|
|
+// await new Promise(resolve => {
|
|
|
+// const checkLoaded = () => {
|
|
|
+// if (root.loaded) {
|
|
|
+// resolve();
|
|
|
+// } else {
|
|
|
+// setTimeout(checkLoaded, 50);
|
|
|
+// }
|
|
|
+// };
|
|
|
+// checkLoaded();
|
|
|
+// });
|
|
|
+
|
|
|
+// // 6. 重置其他节点的加载状态(使其下次展开时重新加载)
|
|
|
+// previouslyExpandedNodes.forEach(nodeId => {
|
|
|
+// // 跳过当前选中节点的路径节点
|
|
|
+// if (!nodePath.includes(nodeId)) {
|
|
|
+// const node = tree.getNode(nodeId);
|
|
|
+// if (node) {
|
|
|
+// node.loaded = false; // 标记为未加载
|
|
|
+// node.expanded = false; // 关闭节点
|
|
|
+// // 从缓存中移除(如果存在)
|
|
|
+// this.cachedNodes.delete(nodeId);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+
|
|
|
+// // 7. 恢复选中节点路径的展开状态
|
|
|
+// this.defaultExpandedKeysType = [...nodePath];
|
|
|
+// for (const key of nodePath) {
|
|
|
+// const node = tree.getNode(key);
|
|
|
+// if (node && !node.expanded) {
|
|
|
+// node.expand();
|
|
|
+// await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// // 8. 恢复选中状态
|
|
|
+// if (currentKey) {
|
|
|
+// tree.setCurrentKey(currentKey);
|
|
|
+// await this.$nextTick();
|
|
|
+
|
|
|
+// const currentNode = tree.getNode(currentKey);
|
|
|
+// if (currentNode) {
|
|
|
+// this.currentNodeData = currentNode.data;
|
|
|
+// const highlightedEl = document.querySelector('.el-tree--highlight-current .is-current');
|
|
|
+// this.formData = highlightedEl ?
|
|
|
+// [{...this.currentNodeData, tableName: this.currentNodeData.title}] :
|
|
|
+// [];
|
|
|
+// } else {
|
|
|
+// this.formData = [];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// },
|
|
|
async reloadEntireTree() {
|
|
|
this.isNodeType = false;
|
|
|
|
|
|
- // 1. 保存当前选中节点key和路径
|
|
|
+ // 1. 获取树组件引用和当前选中节点
|
|
|
const tree = this.$refs.treeByType;
|
|
|
if (!tree) return;
|
|
|
|
|
|
const currentKey = tree.getCurrentKey();
|
|
|
- let nodePath = [];
|
|
|
+ const currentPath = [];
|
|
|
+
|
|
|
+ // 2. 收集当前选中节点的路径和所有展开节点
|
|
|
+ const allExpandedNodes = [];
|
|
|
+
|
|
|
+ const traverseTree = (node) => {
|
|
|
+ if (node.expanded && node.level > 0) {
|
|
|
+ allExpandedNodes.push({
|
|
|
+ id: node.data.id,
|
|
|
+ node: node
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (node.childNodes) {
|
|
|
+ node.childNodes.forEach(traverseTree);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ traverseTree(tree.store.root);
|
|
|
+
|
|
|
+ // 3. 获取选中节点的完整路径
|
|
|
if (currentKey) {
|
|
|
const currentNode = tree.getNode(currentKey);
|
|
|
if (currentNode) {
|
|
|
- // 获取选中节点的所有父节点路径
|
|
|
let parent = currentNode.parent;
|
|
|
while (parent && parent.level > 0) {
|
|
|
- nodePath.unshift(parent.data.id);
|
|
|
+ currentPath.unshift(parent.data.id);
|
|
|
parent = parent.parent;
|
|
|
}
|
|
|
+ currentPath.push(currentKey); // 包含当前节点本身
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 2. 清空缓存并记录所有已展开节点(用于后续重置)
|
|
|
- const previouslyExpandedNodes = [];
|
|
|
- const collectExpandedNodes = (node) => {
|
|
|
- if (node.expanded && node.level > 0) {
|
|
|
- previouslyExpandedNodes.push(node.data.id);
|
|
|
- }
|
|
|
- if (node.childNodes) {
|
|
|
- node.childNodes.forEach(collectExpandedNodes);
|
|
|
+ // 4. 清空缓存
|
|
|
+ this.cachedNodes.clear();
|
|
|
+
|
|
|
+ // 5. 强制重新加载当前路径上的所有节点
|
|
|
+ for (const nodeId of currentPath) {
|
|
|
+ const node = tree.getNode(nodeId);
|
|
|
+ if (node) {
|
|
|
+ node.loaded = false; // 标记为需要重新加载
|
|
|
+ // 从缓存中移除
|
|
|
+ this.cachedNodes.delete(nodeId);
|
|
|
}
|
|
|
- };
|
|
|
- collectExpandedNodes(tree.store.root);
|
|
|
+ }
|
|
|
|
|
|
- this.cachedNodes.clear();
|
|
|
+ // 6. 关闭所有非当前路径的展开节点
|
|
|
+ allExpandedNodes.forEach(({id, node}) => {
|
|
|
+ if (!currentPath.includes(id)) {
|
|
|
+ node.expanded = false;
|
|
|
+ node.loaded = false; // 标记为需要重新加载
|
|
|
+ this.cachedNodes.delete(id);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- // 3. 清空根节点子节点
|
|
|
+ // 7. 重新加载根节点
|
|
|
const rootNode = tree.store.root;
|
|
|
const rootId = rootNode.childNodes[0].data.id || 'root';
|
|
|
await this.$nextTick();
|
|
|
tree.updateKeyChildren(rootId, []);
|
|
|
|
|
|
- // 4. 强制重新加载根节点
|
|
|
const root = tree.getNode(rootId);
|
|
|
if (root) {
|
|
|
root.loaded = false;
|
|
|
- root.expand(); // 这会触发loadNodeByType
|
|
|
+ root.expand();
|
|
|
}
|
|
|
|
|
|
- // 5. 等待树重新加载完成
|
|
|
+ // 8. 等待树重新加载完成
|
|
|
await new Promise(resolve => {
|
|
|
const checkLoaded = () => {
|
|
|
if (root.loaded) {
|
|
@@ -3133,44 +3262,43 @@ async reloadEntireTree() {
|
|
|
checkLoaded();
|
|
|
});
|
|
|
|
|
|
- // 6. 重置其他节点的加载状态(使其下次展开时重新加载)
|
|
|
- previouslyExpandedNodes.forEach(nodeId => {
|
|
|
- // 跳过当前选中节点的路径节点
|
|
|
- if (!nodePath.includes(nodeId)) {
|
|
|
- const node = tree.getNode(nodeId);
|
|
|
- if (node) {
|
|
|
- node.loaded = false; // 标记为未加载
|
|
|
- node.expanded = false; // 关闭节点
|
|
|
- // 从缓存中移除(如果存在)
|
|
|
- this.cachedNodes.delete(nodeId);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 7. 恢复选中节点路径的展开状态
|
|
|
- this.defaultExpandedKeysType = [...nodePath];
|
|
|
- for (const key of nodePath) {
|
|
|
- const node = tree.getNode(key);
|
|
|
+ // 9. 重新展开当前路径
|
|
|
+ this.defaultExpandedKeysType = [...currentPath];
|
|
|
+ for (const nodeId of currentPath) {
|
|
|
+ const node = tree.getNode(nodeId);
|
|
|
if (node && !node.expanded) {
|
|
|
node.expand();
|
|
|
- await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
+ // 等待节点加载
|
|
|
+ await new Promise(resolve => {
|
|
|
+ const checkNodeLoaded = () => {
|
|
|
+ if (node.loaded) {
|
|
|
+ resolve();
|
|
|
+ } else {
|
|
|
+ setTimeout(checkNodeLoaded, 50);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ checkNodeLoaded();
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 8. 恢复选中状态
|
|
|
+ // 10. 恢复选中状态
|
|
|
if (currentKey) {
|
|
|
- tree.setCurrentKey(currentKey);
|
|
|
- await this.$nextTick();
|
|
|
-
|
|
|
+ // 检查节点是否仍然存在
|
|
|
const currentNode = tree.getNode(currentKey);
|
|
|
if (currentNode) {
|
|
|
+ tree.setCurrentKey(currentKey);
|
|
|
this.currentNodeData = currentNode.data;
|
|
|
- const highlightedEl = document.querySelector('.el-tree--highlight-current .is-current');
|
|
|
- this.formData = highlightedEl ?
|
|
|
- [{...this.currentNodeData, tableName: this.currentNodeData.title}] :
|
|
|
- [];
|
|
|
+ this.formData = [{
|
|
|
+ ...this.currentNodeData,
|
|
|
+ tableName: this.currentNodeData.title
|
|
|
+ }];
|
|
|
} else {
|
|
|
+ // 节点已被删除
|
|
|
+ this.currentNodeKey = null;
|
|
|
+ this.currentNodeData = null;
|
|
|
this.formData = [];
|
|
|
+ // this.$message.warning('当前选中节点已被删除');
|
|
|
}
|
|
|
}
|
|
|
},
|