支持展开到指定层级

This commit is contained in:
wanglin2 2022-09-23 17:41:38 +08:00
parent 5a5062ecaf
commit 5d4cf8a3c3
2 changed files with 43 additions and 6 deletions

View File

@ -143,6 +143,9 @@ class Render {
// 收起所有节点 // 收起所有节点
this.unexpandAllNode = this.unexpandAllNode.bind(this) this.unexpandAllNode = this.unexpandAllNode.bind(this)
this.mindMap.command.add('UNEXPAND_ALL', this.unexpandAllNode) this.mindMap.command.add('UNEXPAND_ALL', this.unexpandAllNode)
// 展开到指定层级
this.expandToLevel = this.expandToLevel.bind(this)
this.mindMap.command.add('UNEXPAND_TO_LEVEL', this.expandToLevel)
// 设置节点数据 // 设置节点数据
this.setNodeData = this.setNodeData.bind(this) this.setNodeData = this.setNodeData.bind(this)
this.mindMap.command.add('SET_NODE_DATA', this.setNodeData) this.mindMap.command.add('SET_NODE_DATA', this.setNodeData)
@ -803,6 +806,19 @@ class Render {
}, null, true, 0, 0) }, null, true, 0, 0)
} }
/**
* javascript comment
* @Author: 王林25
* @Date: 2022-09-23 16:31:27
* @Desc: 展开到指定层级
*/
expandToLevel(level) {
walk(this.renderTree, null, (node, parent, isRoot, layerIndex) => {
node.data.expand = layerIndex < level
}, null, true, 0, 0)
this.mindMap.reRender()
}
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2022-08-14 09:18:40 * @Date: 2022-08-14 09:18:40

View File

@ -1,6 +1,6 @@
<template> <template>
<div <div
class="contextmenuContainer" class="contextmenuContainer listBox"
v-if="isShow" v-if="isShow"
:style="{ left: left + 'px', top: top + 'px' }" :style="{ left: left + 'px', top: top + 'px' }"
> >
@ -62,6 +62,12 @@
<div class="item" @click="exec('RETURN_CENTER')">回到中心</div> <div class="item" @click="exec('RETURN_CENTER')">回到中心</div>
<div class="item" @click="exec('EXPAND_ALL')">展开所有</div> <div class="item" @click="exec('EXPAND_ALL')">展开所有</div>
<div class="item" @click="exec('UNEXPAND_ALL')">收起所有</div> <div class="item" @click="exec('UNEXPAND_ALL')">收起所有</div>
<div class="item">
展开到
<div class="subItems listBox">
<div class="item" v-for="(item, index) in expandList" :key="item" @click="exec('UNEXPAND_TO_LEVEL', false, index + 1)">{{item}}</div>
</div>
</div>
<div class="item" @click="exec('RESET_LAYOUT')"> <div class="item" @click="exec('RESET_LAYOUT')">
一键整理布局 一键整理布局
<span class="desc">Ctrl + L</span> <span class="desc">Ctrl + L</span>
@ -93,7 +99,8 @@ export default {
type: "", type: "",
isMousedown: false, isMousedown: false,
mosuedownX: 0, mosuedownX: 0,
mosuedownY: 0 mosuedownY: 0,
expandList: ['一级主题', '二级主题', '三级主题', '四级主题', '五级主题', '六级主题']
}; };
}, },
computed: { computed: {
@ -221,7 +228,7 @@ export default {
* @Date: 2021-07-14 23:27:54 * @Date: 2021-07-14 23:27:54
* @Desc: 执行命令 * @Desc: 执行命令
*/ */
exec(key, disabled) { exec(key, disabled, ...args) {
if (disabled) { if (disabled) {
return; return;
} }
@ -241,7 +248,7 @@ export default {
this.mindMap.view.reset(); this.mindMap.view.reset();
break; break;
default: default:
this.$bus.$emit("execCommand", key); this.$bus.$emit("execCommand", key, ...args);
break; break;
} }
this.hide(); this.hide();
@ -278,20 +285,23 @@ export default {
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.contextmenuContainer { .listBox {
position: fixed;
width: 200px; width: 200px;
background: #fff; background: #fff;
box-shadow: 0 4px 12px 0 hsla(0, 0%, 69%, 0.5); box-shadow: 0 4px 12px 0 hsla(0, 0%, 69%, 0.5);
border-radius: 4px; border-radius: 4px;
padding-top: 16px; padding-top: 16px;
padding-bottom: 16px; padding-bottom: 16px;
}
.contextmenuContainer {
position: fixed;
font-size: 14px; font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC; font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400; font-weight: 400;
color: #1a1a1a; color: #1a1a1a;
.item { .item {
position: relative;
height: 28px; height: 28px;
line-height: 28px; line-height: 28px;
padding: 0 16px; padding: 0 16px;
@ -305,6 +315,10 @@ export default {
&:hover { &:hover {
background: #f5f5f5; background: #f5f5f5;
.subItems {
visibility: visible;
}
} }
&.disabled { &.disabled {
@ -320,6 +334,13 @@ export default {
.desc { .desc {
color: #999; color: #999;
} }
.subItems {
position: absolute;
left: 100%;
top: 0;
visibility: hidden;
}
} }
} }
</style> </style>