组织结构图可视化分层组织数据。
import OrganizationChart from 'primevue/organizationchart';
组织结构图需要一个 TreeNode 实例集合作为 value。
阿根廷 | |||||||||||||||||||||||||||||||||||||||
|
|
<OrganizationChart :value="data">
<template #default="slotProps">
<span>{{ slotProps.node.label }}</span>
</template>
</OrganizationChart>
OrganizationChartNode 的 type 属性用于将模板映射到节点。如果未定义,则使用默认模板。
<OrganizationChart :value="data" collapsible>
<template #country="slotProps">
<div class="flex flex-col items-center">
<img :alt="slotProps.node.label" src="https://primefaces.org/cdn/primevue/images/flag/flag_placeholder.png" :class="`w-2rem flag flag-${slotProps.node.data}`" />
<div class="mt-4 font-medium text-lg">{{ slotProps.node.label }}</div>
</div>
</template>
<template #default="slotProps">
<span>{{slotProps.node.data.label}}</span>
</template>
</OrganizationChart>
通过将 selectionMode 定义为“single”或“multiple”,并使用 v-model 指令指定 selectionKeys 来启用选择。请注意,如果节点实例上的 selectable 为 false,则可以禁用特定节点的选择。
<OrganizationChart v-model:selectionKeys="selection" :value="data" collapsible selectionMode="multiple">
<template #person="slotProps">
<div class="flex flex-col">
<div class="flex flex-col items-center">
<img :alt="slotProps.node.data.name" :src="slotProps.node.data.image" class="mb-4 w-12 h-12" />
<span class="font-bold mb-2">{{ slotProps.node.data.name }}</span>
<span>{{ slotProps.node.data.title }}</span>
</div>
</div>
</template>
<template #default="slotProps">
<span>{{ slotProps.node.label }}</span>
</template>
</OrganizationChart>
使用 TreeNode 的 styleClass 和 style 选项配置特定节点的样式。
<OrganizationChart :value="data" collapsible>
<template #person="slotProps">
<div class="flex flex-col">
<div class="flex flex-col items-center">
<img :alt="slotProps.node.data.name" :src="slotProps.node.data.image" class="mb-4 w-12 h-12" />
<span class="font-bold mb-2">{{ slotProps.node.data.name }}</span>
<span>{{ slotProps.node.data.title }}</span>
</div>
</div>
</template>
<template #default="slotProps">
<span>{{ slotProps.node.label }}</span>
</template>
</OrganizationChart>
组件目前使用基于表格的实现,并且不提供高水平的屏幕阅读器支持,计划使用 aria 角色和属性对齐到树形小部件的嵌套列表实现替换,以便在即将发布的版本中获得高水平的阅读器支持。
按键 | 功能 |
---|---|
tab | 在图表内的可聚焦元素之间移动焦点。 |
enter | 切换节点的展开状态。 |
空格 | 切换节点的展开状态。 |