Commit c863023c authored by XieZhiXiong's avatar XieZhiXiong

chore: 同步能力中心的代码

parent 012d1d52
......@@ -8,26 +8,30 @@ const { onFormInit$ } = FormEffectHooks
* @param service 触发的异步函数, 需返回一个{label: any, value: any}形式的数组
*/
export const useAsyncInitSelect = (name: string[], service: () => Promise<any>) => {
const { dispatch, setFieldState } = createFormActions()
const linkage = useLinkageUtils()
const { dispatch, setFieldState } = createFormActions();
const linkage = useLinkageUtils();
onFormInit$().subscribe(() => {
setFieldState(name, state => {
FormPath.setIn(state, 'props.x-props.hasFeedback', true)
})
name.forEach(v => linkage.loaded(v))
const nameStr: string = name.toString();
const formPath: string = `*(${nameStr})`;
setFieldState(formPath, state => {
FormPath.setIn(state, 'props.x-props.hasFeedback', true);
});
linkage.loading(formPath);
service().then(res => {
name.forEach(v => {
linkage.loaded(v)
linkage.enum(v, res[v])
})
//请求结束可以dispatch一个自定义事件收尾,方便后续针对该事件做联动
dispatch && dispatch('requestAsyncSelect', {
linkage.enum(v, res[v] || []);
});
// 请求结束可以dispatch一个自定义事件收尾,方便后续针对该事件做联动
dispatch?.('requestAsyncSelect', {
name,
payload: res
})
}).catch(err => {
// linkage.loaded(name)
// linkage.enum(name, [])
})
payload: res,
});
}).finally(() => {
linkage.loaded(formPath);
});
})
}
\ No newline at end of file
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