Skip to content

Commit

Permalink
useFormItem 解决过早调用时,类型不匹配问题
Browse files Browse the repository at this point in the history
  • Loading branch information
think-gem committed Dec 4, 2024
1 parent 09a8772 commit 12c4329
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/hooks/component/useFormItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ export function useRuleFormItem<T extends Recordable>(
if (!value) return undefined;
if (props.labelInValue) {
const values: Recordable = [];
if (isMultiple.value && !(value instanceof Array)) {
if (isMultiple.value && !(value instanceof Object) && !(value instanceof Array)) {
console.log(value);
const vals = (value as string)?.split(',');
const lbls = (props.labelValue as string)?.split(',');
const labs = (props.labelValue as string)?.split(',');
for (const i in vals) {
values.push({ value: vals && vals[i], label: lbls && lbls[i] });
values.push({ value: vals && vals[i], label: labs && labs[i] });
}
value = values as T[keyof T];
} else if (!isObject(value) && !(value instanceof Array)) {
} else if (!isObject(value) && !(value instanceof Object) && !(value instanceof Array)) {
value = { value: String(value), label: props.labelValue };
} else if (value instanceof Array) {
for (const i in value) {
Expand All @@ -87,7 +88,7 @@ export function useRuleFormItem<T extends Recordable>(
value = values as T[keyof T];
}
}
} else if (isMultiple.value && !(value instanceof Array)) {
} else if (isMultiple.value && !(value instanceof Object) && !(value instanceof Array)) {
value = (value as string).split(',');
} else if (isDictType.value && isNumber(value)) {
value = String(value);
Expand Down

0 comments on commit 12c4329

Please sign in to comment.