refactor(form): 使用空值合并运算符 (??) 和 isDef 优化宽度判断逻辑,处理 labelWidth 可能为 0 的情况 (#4086)

This commit is contained in:
张阿文 2024-08-08 20:50:32 +08:00 committed by GitHub
parent 4aac1c388c
commit 617e594d8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
import type { Ref } from 'vue';
import { computed, unref } from 'vue';
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>) {
return computed(() => {
@ -23,11 +23,11 @@ export function useItemLabelWidth(schemaItemRef: Ref<FormSchema>, propsRef: Ref<
};
return { labelCol, wrapperCol };
}
let width = labelWidth || globalLabelWidth;
let width = labelWidth ?? globalLabelWidth;
const col = { ...globalLabelCol, ...labelCol };
const wrapCol = { ...globWrapperCol, ...wrapperCol };
if (width) {
if (isDef(width)) {
width = isNumber(width) ? `${width}px` : width;
}