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