Commit 7d1553b7 authored by 前端-许佳敏's avatar 前端-许佳敏

拆分formily逻辑

parent fd970a17
export const FORM_FILTER_PATH = 'FORM_FILTER_PATH'
\ No newline at end of file
import { useValueLinkageEffect, ISchemaFormActions, ISchemaFormAsyncActions } from "@formily/antd"
/**
* @param origin 触发联动的字段路径
* @param target 关联的字段路径
*/
export const useStateFilterSearchLinkageEffect = (context, actions: ISchemaFormActions | ISchemaFormAsyncActions, origin: string, target: string) => {
const { setFieldState, reset } = actions
context('onFieldChange', origin).subscribe(state => {
setFieldState(target, fieldState => {
fieldState.visible = state.filterSearch
})
})
}
\ No newline at end of file
import { createFormActions, FormEffectHooks } from '@formily/antd'
import { useLinkageUtils } from '@/utils/formEffectUtils'
/**
* 定义表单副作用的集合
*/
const { onFieldValueChange$ } = FormEffectHooks
export const usePublicSelectEffects = context => {
const linkage = useLinkageUtils()
onFieldValueChange$('select').subscribe(({ value }) => {
linkage.visible(value)
})
}
\ No newline at end of file
import { createFormActions, FormPath } from '@formily/antd'
export const useLinkageUtils = () => {
const { setFieldState } = createFormActions()
const linkage = (key, defaultValue?) => (path, value?) =>
setFieldState(path, state => {
FormPath.setIn(state, key, value !== undefined ? value : defaultValue)
})
return {
hide: linkage('visible', false),
show: linkage('visible', true),
visible: linkage('visible'),
enum: linkage('props.enum', []),
loading: linkage('loading', true),
loaded: linkage('loading', false),
value: linkage('value')
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment