primevue-mirror/components/lib/organizationchart/OrganizationChart.vue

154 lines
3.7 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-05-10 08:07:14 +00:00
<div class="p-organizationchart p-component" v-bind="ptm('root')">
<OrganizationChartNode
:node="value"
:templates="$slots"
@node-toggle="onNodeToggle"
:collapsedKeys="d_collapsedKeys"
:collapsible="collapsible"
@node-click="onNodeClick"
:selectionMode="selectionMode"
:selectionKeys="selectionKeys"
:pt="pt"
/>
2022-09-06 12:03:37 +00:00
</div>
</template>
<script>
2023-05-10 08:07:14 +00:00
import BaseComponent from 'primevue/basecomponent';
2022-09-06 12:03:37 +00:00
import OrganizationChartNode from './OrganizationChartNode.vue';
export default {
name: 'OrganizationChart',
2023-05-10 08:07:14 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
emits: ['node-unselect', 'node-select', 'update:selectionKeys', 'node-expand', 'node-collapse', 'update:collapsedKeys'],
props: {
value: {
type: null,
default: null
},
selectionKeys: {
type: null,
default: null
},
selectionMode: {
type: String,
default: null
},
collapsible: {
type: Boolean,
default: false
},
collapsedKeys: {
type: null,
default: null
}
},
data() {
return {
d_collapsedKeys: this.collapsedKeys || {}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
},
watch: {
collapsedKeys(newValue) {
this.d_collapsedKeys = newValue;
}
},
methods: {
onNodeClick(node) {
const key = node.key;
if (this.selectionMode) {
2022-09-14 11:26:01 +00:00
let _selectionKeys = this.selectionKeys ? { ...this.selectionKeys } : {};
2022-09-06 12:03:37 +00:00
if (_selectionKeys[key]) {
delete _selectionKeys[key];
this.$emit('node-unselect', node);
2022-09-14 11:26:01 +00:00
} else {
2022-09-06 12:03:37 +00:00
if (this.selectionMode === 'single') {
_selectionKeys = {};
}
_selectionKeys[key] = true;
this.$emit('node-select', node);
}
this.$emit('update:selectionKeys', _selectionKeys);
}
},
onNodeToggle(node) {
const key = node.key;
if (this.d_collapsedKeys[key]) {
delete this.d_collapsedKeys[key];
this.$emit('node-expand', node);
2022-09-14 11:26:01 +00:00
} else {
2022-09-06 12:03:37 +00:00
this.d_collapsedKeys[key] = true;
this.$emit('node-collapse', node);
}
2022-09-14 11:26:01 +00:00
this.d_collapsedKeys = { ...this.d_collapsedKeys };
2022-09-06 12:03:37 +00:00
this.$emit('update:collapsedKeys', this.d_collapsedKeys);
}
},
components: {
2022-09-14 11:26:01 +00:00
OrganizationChartNode: OrganizationChartNode
2022-09-06 12:03:37 +00:00
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>
<style>
.p-organizationchart-table {
border-spacing: 0;
border-collapse: separate;
margin: 0 auto;
}
.p-organizationchart-table > tbody > tr > td {
text-align: center;
vertical-align: top;
2022-09-14 11:26:01 +00:00
padding: 0 0.75rem;
2022-09-06 12:03:37 +00:00
}
.p-organizationchart-node-content {
display: inline-block;
position: relative;
}
.p-organizationchart-node-content .p-node-toggler {
position: absolute;
2022-09-14 11:26:01 +00:00
bottom: -0.75rem;
margin-left: -0.75rem;
2022-09-06 12:03:37 +00:00
z-index: 2;
left: 50%;
user-select: none;
cursor: pointer;
width: 1.5rem;
height: 1.5rem;
text-decoration: none;
}
.p-organizationchart-node-content .p-node-toggler .p-node-toggler-icon {
position: relative;
2022-09-14 11:26:01 +00:00
top: 0.25rem;
2022-09-06 12:03:37 +00:00
}
.p-organizationchart-line-down {
margin: 0 auto;
height: 20px;
width: 1px;
}
.p-organizationchart-line-right {
border-radius: 0px;
}
2022-09-14 11:26:01 +00:00
.p-organizationchart-line-left {
2022-09-06 12:03:37 +00:00
border-radius: 0;
}
.p-organizationchart-selectable-node {
cursor: pointer;
}
</style>