| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <template>
- <view class="tree-node">
- <view
- :class="['node-row', { 'is-dept': isDept, 'is-user': isUser }]"
- @click="handleClick"
- >
- <view class="toggle-icon" v-if="isDept">
- <u-icon :name="expanded ? 'arrow-down' : 'arrow-right'" size="16" color="#999" />
- </view>
- <view class="toggle-icon" v-else>
- <text class="user-dot">●</text>
- </view>
- <text class="node-label">{{ nodeLabel }}</text>
- <u-icon v-if="isUser && nodeId === selectedId" name="checkmark" color="#34D399" size="18" />
- </view>
- <view v-if="isDept && expanded" class="node-children">
- <template v-for="child in nodeChildren">
- <employee-tree-node
- :key="child.id"
- :node="child"
- :expanded-ids="expandedIds"
- :selected-id="selectedId"
- @toggle="$emit('toggle', $event)"
- @select="$emit('select', $event)"
- />
- </template>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'EmployeeTreeNode',
- props: {
- node: {
- type: Object,
- required: true
- },
- expandedIds: {
- type: [Array, Set],
- default: () => []
- },
- selectedId: {
- type: [String, Number],
- default: null
- }
- },
- computed: {
- isDept() {
- const hasChildren = this.node.children && this.node.children.length > 0
- return hasChildren || this.node.nodeType === 'dept'
- },
- isUser() {
- return !this.isDept
- },
- nodeId() {
- return this.node.userId || this.node.id
- },
- nodeLabel() {
- return this.node.nickName || this.node.label || this.node.userName || this.node.name || ''
- },
- nodeChildren() {
- return this.node.children || []
- },
- expanded() {
- if (this.expandedIds instanceof Set) {
- return this.expandedIds.has(this.node.id)
- }
- return this.expandedIds.includes(this.node.id)
- }
- },
- methods: {
- handleClick() {
- if (this.isDept) {
- this.$emit('toggle', this.node.id)
- } else {
- this.$emit('select', {
- userId: this.nodeId,
- nickName: this.nodeLabel
- })
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .tree-node {
- width: 100%;
- }
- .node-row {
- display: flex;
- align-items: center;
- padding: 20rpx 32rpx 20rpx 16rpx;
- gap: 12rpx;
- &.is-dept {
- padding-left: 16rpx;
- }
- }
- .toggle-icon {
- width: 40rpx;
- height: 40rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .user-dot {
- font-size: 16rpx;
- color: #999;
- }
- .node-label {
- flex: 1;
- font-size: 28rpx;
- color: #333;
- }
- .node-children {
- padding-left: 32rpx;
- }
- </style>
|