feat: improve code

This commit is contained in:
chenos 2021-08-11 00:08:55 +08:00
parent ff4d3c5397
commit 9187c15b27
5 changed files with 24 additions and 5 deletions

View File

@ -44,7 +44,7 @@ const plugins = [
'@nocobase/plugin-users', '@nocobase/plugin-users',
'@nocobase/plugin-action-logs', '@nocobase/plugin-action-logs',
// '@nocobase/plugin-file-manager', // '@nocobase/plugin-file-manager',
// '@nocobase/plugin-permissions', '@nocobase/plugin-permissions',
// '@nocobase/plugin-automations', // '@nocobase/plugin-automations',
// '@nocobase/plugin-china-region', // '@nocobase/plugin-china-region',
]; ];

View File

@ -53,6 +53,7 @@ import { TreeSelect } from '../../schemas/tree-select';
import { Page } from '../../schemas/page'; import { Page } from '../../schemas/page';
import { Chart } from '../../schemas/chart'; import { Chart } from '../../schemas/chart';
import { useDesignableSwitchContext } from '../../constate/DesignableSwitch'; import { useDesignableSwitchContext } from '../../constate/DesignableSwitch';
import { action } from '@formily/reactive';
export const BlockContext = createContext({ dragRef: null }); export const BlockContext = createContext({ dragRef: null });
@ -63,9 +64,20 @@ interface DesignableContextProps {
refresh?: any; 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({ export const SchemaField = createSchemaField({
scope: { scope: {
Table, Table,
useAsyncDataSource,
}, },
components: { components: {
Card, Card,

View File

@ -50,8 +50,12 @@ export class Resource {
list(options: ListOptions = {}) { list(options: ListOptions = {}) {
const { defaultAppends = [], appends = [], defaultFilter, filter, ...others } = options; const { defaultAppends = [], appends = [], defaultFilter, filter, ...others } = options;
const { resourceName } = this.options; const { associatedKey, associatedName, resourceName } = this.options;
return request(`${resourceName}:list`, { let url = `${resourceName}:list`;
if (associatedName && associatedKey) {
url = `${associatedName}/${associatedKey}/${resourceName}:list`;
}
return request(url, {
method: 'get', method: 'get',
params: { params: {
filter: decodeURIComponent(JSON.stringify({ and: [defaultFilter, filter].filter(Boolean) })), filter: decodeURIComponent(JSON.stringify({ and: [defaultFilter, filter].filter(Boolean) })),

View File

@ -68,6 +68,7 @@ const FormMain = (props: any) => {
}); });
const path = useSchemaPath(); const path = useSchemaPath();
const scope = useContext(SchemaExpressionScopeContext); const scope = useContext(SchemaExpressionScopeContext);
const options = useContext(SchemaOptionsContext);
const displayed = useDisplayedMapContext(); const displayed = useDisplayedMapContext();
const { collection } = useCollectionContext(); const { collection } = useCollectionContext();
useEffect(() => { useEffect(() => {
@ -81,6 +82,7 @@ const FormMain = (props: any) => {
<FormProvider form={form}> <FormProvider form={form}>
{schema['x-decorator'] === 'Form' ? ( {schema['x-decorator'] === 'Form' ? (
<SchemaField <SchemaField
components={options.components}
scope={scope} scope={scope}
schema={{ schema={{
type: 'object', type: 'object',

View File

@ -93,10 +93,10 @@ export interface ITableRowContext {
} }
const TableContext = createContext<ITableContext>({} as any); const TableContext = createContext<ITableContext>({} as any);
const TableRowContext = createContext<ITableRowContext>(null); export const TableRowContext = createContext<ITableRowContext>(null);
const CollectionFieldContext = createContext(null); const CollectionFieldContext = createContext(null);
const useTable = () => { export const useTable = () => {
return useContext(TableContext); return useContext(TableContext);
}; };
@ -364,6 +364,7 @@ const useTableColumns = () => {
if ( if (
designable && designable &&
schema['x-designable-bar'] &&
schema['x-designable-bar'] !== 'Table.SimpleDesignableBar' schema['x-designable-bar'] !== 'Table.SimpleDesignableBar'
) { ) {
columns.push({ columns.push({