import {computed, ExtractPropTypes, reactive} from "@peryl/react-compose"; import {iTreeCore} from "../../../TreeCore/createTreeCore"; import {iPlcTreeScopeSlotsType, PlcTreeButtonSize, PlcTreePropsOptions} from "./PlcTree.utils"; /** * 处理树列自动宽度 * @author 韦胜健 * @date 2022.11.19 19:15 */ export function usePlcTreeAutoWidth( { treeCore, props, scopeSlots, }: { treeCore: iTreeCore, props: ExtractPropTypes, scopeSlots: iPlcTreeScopeSlotsType, } ) { const state = reactive({ // 当前是否拖拽过列宽 hasDragColumnWidth: false, }); /** * 计算当前展示的数据中,层级最深的层数 * @author 韦胜健 * @date 2022.11.19 19:16 */ const maxShowLevel = computed(() => treeCore.flatNodeComputedData.value.reduce((prev, item) => Math.max(prev, item.level), 0)); /** * 动态列宽,当展开收起的时候,自动更新列宽 * @author 韦胜健 * @date 2020/8/24 9:35 */ const width = computed(() => { const padding = 24; const expand = PlcTreeButtonSize; const check = props.multiple ? PlcTreeButtonSize : 0; const draggable = props.draggable ? PlcTreeButtonSize : 0; const content = (props.field || scopeSlots.content.isExist()) ? props.contentWidth : 0; // 每一层都增加一个左边距 (expand + check) * level,所以每一层都加上这个宽度 const level = maxShowLevel.value; // 最后最大层的宽度 return (expand * level) + (content + expand + check + draggable) + padding; }); return { width }; }