Demo:1.小地图支持拖拽视图框调整画布位置;2.鼠标移出小地图停止鼠标事件;

This commit is contained in:
街角小林 2024-07-03 09:18:18 +08:00
parent 58baf4c0aa
commit 591e6a5b2a
2 changed files with 49 additions and 4 deletions

View File

@ -12,7 +12,7 @@
ref="mindMapContainer" ref="mindMapContainer"
></div> ></div>
<Count :mindMap="mindMap" v-if="!isZenMode"></Count> <Count :mindMap="mindMap" v-if="!isZenMode"></Count>
<Navigator :mindMap="mindMap"></Navigator> <Navigator v-if="mindMap" :mindMap="mindMap"></Navigator>
<NavigatorToolbar :mindMap="mindMap" v-if="!isZenMode"></NavigatorToolbar> <NavigatorToolbar :mindMap="mindMap" v-if="!isZenMode"></NavigatorToolbar>
<OutlineSidebar :mindMap="mindMap"></OutlineSidebar> <OutlineSidebar :mindMap="mindMap"></OutlineSidebar>
<Style v-if="!isZenMode"></Style> <Style v-if="!isZenMode"></Style>

View File

@ -19,7 +19,13 @@
> >
<img :src="mindMapImg" @mousedown.prevent /> <img :src="mindMapImg" @mousedown.prevent />
</div> </div>
<div class="windowBox" :style="viewBoxStyle"></div> <div
class="windowBox"
:style="viewBoxStyle"
:class="{ withTransition: withTransition }"
@mousedown.stop="onViewBoxMousedown"
@mousemove="onViewBoxMousemove"
></div>
</div> </div>
</template> </template>
@ -49,7 +55,8 @@ export default {
}, },
mindMapImg: '', mindMapImg: '',
width: 0, width: 0,
setSizeTimer: null setSizeTimer: null,
withTransition: true
} }
}, },
computed: { computed: {
@ -65,6 +72,10 @@ export default {
this.$bus.$on('view_data_change', this.data_change) this.$bus.$on('view_data_change', this.data_change)
this.$bus.$on('node_tree_render_end', this.data_change) this.$bus.$on('node_tree_render_end', this.data_change)
window.addEventListener('mouseup', this.onMouseup) window.addEventListener('mouseup', this.onMouseup)
this.mindMap.on(
'mini_map_view_box_position_change',
this.onViewBoxPositionChange
)
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.setSize) window.removeEventListener('resize', this.setSize)
@ -73,6 +84,10 @@ export default {
this.$bus.$off('view_data_change', this.data_change) this.$bus.$off('view_data_change', this.data_change)
this.$bus.$off('node_tree_render_end', this.data_change) this.$bus.$off('node_tree_render_end', this.data_change)
window.removeEventListener('mouseup', this.onMouseup) window.removeEventListener('mouseup', this.onMouseup)
this.mindMap.off(
'mini_map_view_box_position_change',
this.onViewBoxPositionChange
)
}, },
methods: { methods: {
// //
@ -120,6 +135,7 @@ export default {
this.boxHeight = height this.boxHeight = height
}, },
//
drawMiniMap() { drawMiniMap() {
let { let {
getImgUrl, getImgUrl,
@ -138,16 +154,41 @@ export default {
this.svgBoxTop = miniMapBoxTop this.svgBoxTop = miniMapBoxTop
}, },
//
onMousedown(e) { onMousedown(e) {
this.mindMap.miniMap.onMousedown(e) this.mindMap.miniMap.onMousedown(e)
}, },
//
onMousemove(e) { onMousemove(e) {
this.mindMap.miniMap.onMousemove(e) this.mindMap.miniMap.onMousemove(e)
}, },
// window
onMouseup(e) { onMouseup(e) {
if (!this.withTransition) {
this.withTransition = true
}
this.mindMap.miniMap.onMouseup(e) this.mindMap.miniMap.onMouseup(e)
},
//
onViewBoxMousedown(e) {
this.mindMap.miniMap.onViewBoxMousedown(e)
},
//
onViewBoxMousemove(e) {
this.mindMap.miniMap.onViewBoxMousemove(e)
},
//
onViewBoxPositionChange({ left, right, top, bottom }) {
this.withTransition = false
this.viewBoxStyle.left = left
this.viewBoxStyle.right = right
this.viewBoxStyle.top = top
this.viewBoxStyle.bottom = bottom
} }
} }
} }
@ -179,7 +220,11 @@ export default {
.windowBox { .windowBox {
position: absolute; position: absolute;
border: 2px solid rgb(238, 69, 69); border: 2px solid rgb(238, 69, 69);
transition: all 0.3s; background-color: rgba(238, 69, 69, 0.2);
&.withTransition {
transition: all 0.3s;
}
} }
} }
</style> </style>