import type { Ref } from "vue"; import type { FormItemSchema, FormSchema } from "../types/form"; import { computed, unref } from "vue"; import { isNumber } from "../support"; export function useItemLabelWidth( schemaItemRef: Ref, schemaRef: Ref ) { return computed(() => { const schemaItem = unref(schemaItemRef); const { labelCol = {}, wrapperCol = {} } = schemaItem.formItemProps || {}; const { labelWidth, disabledLabelWidth } = schemaItem; const { labelWidth: globalLabelWidth, labelCol: globalLabelCol, wrapperCol: globWrapperCol, } = unref(schemaRef); // 如果labelWidth是全局设置的,则会设置所有项 if ( (!globalLabelWidth && !labelWidth && !globalLabelCol) || disabledLabelWidth ) { labelCol.style = { textAlign: "left", }; return { labelCol, wrapperCol }; } let width = labelWidth || globalLabelWidth; const col = { ...globalLabelCol, ...labelCol }; const wrapCol = { ...globWrapperCol, ...wrapperCol }; if (width) { width = isNumber(width) ? `${width}px` : width; } return { labelCol: { style: { width }, ...col }, wrapperCol: { style: { width: `calc(100% - ${width})` }, ...wrapCol }, }; }); }