fix: useParseDefaultValue (#3264)

This commit is contained in:
katherinehhh 2023-12-26 10:43:12 +08:00 committed by GitHub
parent 894e1c8bf8
commit 641ca2dcca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 13 deletions

View File

@ -115,19 +115,27 @@ const useParseDefaultValue = () => {
_run(); _run();
// 实现联动的效果,当依赖的变量变化时(如 `$nForm` 变量),重新解析默认值 // 实现联动的效果,当依赖的变量变化时(如 `$nForm` 变量),重新解析默认值
const dispose = reaction(() => { const dispose = reaction(
const obj = { [variableName]: variable?.ctx || {} }; () => {
const path = getPath(fieldSchema.default); const obj = { [variableName]: variable?.ctx || {} };
const value = getValuesByPath(obj, path); const path = getPath(fieldSchema.default);
const value = getValuesByPath(obj, path);
// fix https://nocobase.height.app/T-2212
if (value === undefined) {
// 返回一个随机值,确保能触发 run 函数
return Math.random();
}
// fix https://nocobase.height.app/T-2212 return value;
if (value === undefined) { },
// 返回一个随机值,确保能触发 run 函数 _run,
return Math.random(); {
} equals: (oldValue, newValue) => {
field.setValue(newValue);
return value; return oldValue === newValue;
}, run); },
},
);
return dispose; return dispose;
} }

View File

@ -49,7 +49,7 @@ export {
useInheritsTableColumnInitializerFields, useInheritsTableColumnInitializerFields,
useRecordCollectionDataSourceItems, useRecordCollectionDataSourceItems,
useRemoveGridFormItem, useRemoveGridFormItem,
useTableColumnInitializerFields useTableColumnInitializerFields,
} from './utils'; } from './utils';
export class SchemaInitializerPlugin extends Plugin { export class SchemaInitializerPlugin extends Plugin {