feat: improve demo

This commit is contained in:
chenos 2022-01-21 09:38:34 +08:00
parent 48722c7c99
commit 84f3ed1564

View File

@ -2,7 +2,14 @@ import { FormItem } from '@formily/antd';
import { ArrayField } from '@formily/core';
import { useField } from '@formily/react';
import { action } from '@formily/reactive';
import { APIClient, APIClientProvider, Cascader, SchemaComponent, SchemaComponentProvider } from '@nocobase/client';
import {
APIClient,
APIClientProvider,
Cascader,
SchemaComponent,
SchemaComponentProvider,
useAPIClient
} from '@nocobase/client';
import MockAdapter from 'axios-mock-adapter';
import React from 'react';
@ -35,9 +42,9 @@ const useAsyncDataSource = (api: APIClient) => (field) => {
);
};
const useLoadData = (api: APIClient) => {
return () => {
const useLoadData = () => {
// hook 写在这里
const api = useAPIClient();
const field = useField<ArrayField>();
return (selectedOptions) => {
const targetOption = selectedOptions[selectedOptions.length - 1];
@ -58,7 +65,6 @@ const useLoadData = (api: APIClient) => {
field.dataSource = [...field.dataSource];
}, 500);
};
};
};
const schema = {
@ -73,7 +79,7 @@ const schema = {
changeOnSelectLast: false,
labelInValue: true,
maxLevel: 3,
useLoadData: '{{useLoadData(apiClient)}}',
useLoadData: '{{useLoadData}}',
// fieldNames: {
// label: 'name',
// value: 'code',