|
|
|
|
@ -27,6 +27,10 @@ const props = defineProps({
|
|
|
|
|
disableRoot: { |
|
|
|
|
type: Boolean, |
|
|
|
|
default: false |
|
|
|
|
}, |
|
|
|
|
onlySecondLevel: { |
|
|
|
|
type: Boolean, |
|
|
|
|
default: false |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
@ -37,9 +41,8 @@ const treeProps = computed(() => ({
|
|
|
|
|
label: 'shortName', |
|
|
|
|
value: 'id', |
|
|
|
|
disabled: (data, node) => { |
|
|
|
|
// debugger |
|
|
|
|
if (!props.disableRoot) return false |
|
|
|
|
if (!node) return false |
|
|
|
|
if (!props.disableRoot) return false |
|
|
|
|
return node.level === 1 |
|
|
|
|
} |
|
|
|
|
})) |
|
|
|
|
@ -53,19 +56,24 @@ watch(departs, () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getData() { |
|
|
|
|
const baseData = props.departData |
|
|
|
|
? [props.departData] |
|
|
|
|
: (!props.showRoot && departs.length && departs[0].id === ROOT_DEPART_ID |
|
|
|
|
? departs[0].children |
|
|
|
|
: departs) |
|
|
|
|
|
|
|
|
|
if(props.departData){ |
|
|
|
|
console.log(props.departData) |
|
|
|
|
data.value=[] |
|
|
|
|
data.value.push(props.departData) |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
if (!props.showRoot && departs.length && departs[0].id === ROOT_DEPART_ID) { |
|
|
|
|
data.value = departs[0].children |
|
|
|
|
} else { |
|
|
|
|
data.value = departs |
|
|
|
|
} |
|
|
|
|
data.value = props.onlySecondLevel ? trimChildren(baseData, 1) : baseData |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function trimChildren(list, level) { |
|
|
|
|
if (!Array.isArray(list)) return [] |
|
|
|
|
return list.map(item => ({ |
|
|
|
|
...item, |
|
|
|
|
children: level >= 2 ? [] : trimChildren(item.children, level + 1) |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|
<style lang="scss" scoped> |
|
|
|
|
|