feat: improve code
This commit is contained in:
parent
ff4d3c5397
commit
9187c15b27
@ -44,7 +44,7 @@ const plugins = [
|
||||
'@nocobase/plugin-users',
|
||||
'@nocobase/plugin-action-logs',
|
||||
// '@nocobase/plugin-file-manager',
|
||||
// '@nocobase/plugin-permissions',
|
||||
'@nocobase/plugin-permissions',
|
||||
// '@nocobase/plugin-automations',
|
||||
// '@nocobase/plugin-china-region',
|
||||
];
|
||||
|
@ -53,6 +53,7 @@ import { TreeSelect } from '../../schemas/tree-select';
|
||||
import { Page } from '../../schemas/page';
|
||||
import { Chart } from '../../schemas/chart';
|
||||
import { useDesignableSwitchContext } from '../../constate/DesignableSwitch';
|
||||
import { action } from '@formily/reactive';
|
||||
|
||||
export const BlockContext = createContext({ dragRef: null });
|
||||
|
||||
@ -63,9 +64,20 @@ interface DesignableContextProps {
|
||||
refresh?: any;
|
||||
}
|
||||
|
||||
export const useAsyncDataSource = (service: any) => (field: any) => {
|
||||
field.loading = true;
|
||||
service(field).then(
|
||||
action((data: any) => {
|
||||
field.dataSource = data;
|
||||
field.loading = false;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
export const SchemaField = createSchemaField({
|
||||
scope: {
|
||||
Table,
|
||||
useAsyncDataSource,
|
||||
},
|
||||
components: {
|
||||
Card,
|
||||
|
@ -50,8 +50,12 @@ export class Resource {
|
||||
|
||||
list(options: ListOptions = {}) {
|
||||
const { defaultAppends = [], appends = [], defaultFilter, filter, ...others } = options;
|
||||
const { resourceName } = this.options;
|
||||
return request(`${resourceName}:list`, {
|
||||
const { associatedKey, associatedName, resourceName } = this.options;
|
||||
let url = `${resourceName}:list`;
|
||||
if (associatedName && associatedKey) {
|
||||
url = `${associatedName}/${associatedKey}/${resourceName}:list`;
|
||||
}
|
||||
return request(url, {
|
||||
method: 'get',
|
||||
params: {
|
||||
filter: decodeURIComponent(JSON.stringify({ and: [defaultFilter, filter].filter(Boolean) })),
|
||||
|
@ -68,6 +68,7 @@ const FormMain = (props: any) => {
|
||||
});
|
||||
const path = useSchemaPath();
|
||||
const scope = useContext(SchemaExpressionScopeContext);
|
||||
const options = useContext(SchemaOptionsContext);
|
||||
const displayed = useDisplayedMapContext();
|
||||
const { collection } = useCollectionContext();
|
||||
useEffect(() => {
|
||||
@ -81,6 +82,7 @@ const FormMain = (props: any) => {
|
||||
<FormProvider form={form}>
|
||||
{schema['x-decorator'] === 'Form' ? (
|
||||
<SchemaField
|
||||
components={options.components}
|
||||
scope={scope}
|
||||
schema={{
|
||||
type: 'object',
|
||||
|
@ -93,10 +93,10 @@ export interface ITableRowContext {
|
||||
}
|
||||
|
||||
const TableContext = createContext<ITableContext>({} as any);
|
||||
const TableRowContext = createContext<ITableRowContext>(null);
|
||||
export const TableRowContext = createContext<ITableRowContext>(null);
|
||||
const CollectionFieldContext = createContext(null);
|
||||
|
||||
const useTable = () => {
|
||||
export const useTable = () => {
|
||||
return useContext(TableContext);
|
||||
};
|
||||
|
||||
@ -364,6 +364,7 @@ const useTableColumns = () => {
|
||||
|
||||
if (
|
||||
designable &&
|
||||
schema['x-designable-bar'] &&
|
||||
schema['x-designable-bar'] !== 'Table.SimpleDesignableBar'
|
||||
) {
|
||||
columns.push({
|
||||
|
Loading…
Reference in New Issue
Block a user