refactor(form): 使用空值合并运算符 (??) 和 isDef 优化宽度判断逻辑,处理 labelWidth 可能为 0 的情况 (#4086)
This commit is contained in:
parent
4aac1c388c
commit
617e594d8d
|
|
@ -1,7 +1,7 @@
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import { computed, unref } from 'vue';
|
import { computed, unref } from 'vue';
|
||||||
import type { FormProps, FormSchemaInner as FormSchema } from '../types/form';
|
import type { FormProps, FormSchemaInner as FormSchema } from '../types/form';
|
||||||
import { isNumber } from '@/utils/is';
|
import { isDef, isNumber } from '@/utils/is';
|
||||||
|
|
||||||
export function useItemLabelWidth(schemaItemRef: Ref<FormSchema>, propsRef: Ref<FormProps>) {
|
export function useItemLabelWidth(schemaItemRef: Ref<FormSchema>, propsRef: Ref<FormProps>) {
|
||||||
return computed(() => {
|
return computed(() => {
|
||||||
|
|
@ -23,11 +23,11 @@ export function useItemLabelWidth(schemaItemRef: Ref<FormSchema>, propsRef: Ref<
|
||||||
};
|
};
|
||||||
return { labelCol, wrapperCol };
|
return { labelCol, wrapperCol };
|
||||||
}
|
}
|
||||||
let width = labelWidth || globalLabelWidth;
|
let width = labelWidth ?? globalLabelWidth;
|
||||||
const col = { ...globalLabelCol, ...labelCol };
|
const col = { ...globalLabelCol, ...labelCol };
|
||||||
const wrapCol = { ...globWrapperCol, ...wrapperCol };
|
const wrapCol = { ...globWrapperCol, ...wrapperCol };
|
||||||
|
|
||||||
if (width) {
|
if (isDef(width)) {
|
||||||
width = isNumber(width) ? `${width}px` : width;
|
width = isNumber(width) ? `${width}px` : width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue