<template>
<div>组织管理 {{ store.$state.num }}</div>
<a-tree v-model:expandedKeys="expandedKeys" v-model:selectedKeys="selectedKeys" v-model:checkedKeys="checkedKeys"
checkable :tree-data="treeData" @rightClick="handleContextMenu">
<template #title="{ title, key }">
<span v-if="key === '0-0-1-0'" style="color: #1890ff">{{ title }}</span>
<template v-else>{{ title }}</template>
</template>
</a-tree>
<teleport to="body">
<div class="flex f-direction-column " :style="getStyle">
<span>111</span>
<span>222</span>
<span>333</span>
<span>444</span>
</div>
</teleport>
</template>
<script setup lang="ts">
import { ref, reactive, toRefs, onMounted } from 'vue'
import { useStore } from '@/store/index'
import type { TreeProps } from 'ant-design-vue';
const store = useStore()
const treeData: TreeProps['treeData'] = [
{
title: 'parent 1',
key: '1',
children: [
{
title: 'parent 1-0',
key: '2',
children: [
{ title: 'leaf', key: '3', },
{ title: 'leaf', key: '4' },
],
},
{
title: 'parent 1-1',
key: '5',
children: [{ key: '6', title: 'sss' }],
},
],
},
];
const getStyle = ref({
backgroundColor: 'red',
width: '100px',
position: 'absolute',
top: -100,
left: 0,
})
const expandedKeys = ref<string[]>(['1','2','5']);
const selectedKeys = ref<string[]>([]);
const checkedKeys = ref<string[]>([]);
const contextMenuPosition = ref<{ x: number; y: number }>({ x: 0, y: 0 });
const handleContextMenu = (event) => {
console.log('event', event)
const rect = event.event.target.getBoundingClientRect();
console.log('rect', rect)
getStyle.value.top = rect.top + rect.height - 40 + 'px'
getStyle.value.left = rect.left + rect.width + 20 + 'px'
console.log('getStyle', getStyle.value)
};
</script>
<style scoped lang="less"></style>
2024-11-27 树形图点击右键
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- <<博客迁移,原文是我51cto博客http://11095961.blog.51cto.com/11085961...
- svg 绘制树形图, 功能点有:1.初始化居中2.可拖拽3.点击某个节点也会以这个节点居中4.悬浮某个节点出现to...
- 在某些需求下需要用到树形图来表达数据结构,我使用的是echarts,关于echart树形图的基础配置和使用这里就不...
- Tree View; Mind map; Think map; tree map; 树状图;思维导图;组织结构图;...