mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 14:56:00 +00:00
feat: default appends for table component
This commit is contained in:
parent
6d7a811d56
commit
8f58e3ec27
@ -9,6 +9,7 @@ export interface ResourceOptions {
|
||||
|
||||
export interface GetOptions {
|
||||
resourceKey?: any;
|
||||
defaultAppends?: any[];
|
||||
appends?: string[];
|
||||
}
|
||||
|
||||
@ -19,6 +20,8 @@ export interface SaveOptions {
|
||||
export interface ListOptions {
|
||||
defaultFilter?: any;
|
||||
filter?: any;
|
||||
defaultAppends?: any[];
|
||||
appends?: string[];
|
||||
}
|
||||
|
||||
export class Resource {
|
||||
@ -46,12 +49,13 @@ export class Resource {
|
||||
}
|
||||
|
||||
list(options: ListOptions = {}) {
|
||||
const { defaultFilter, filter, ...others } = options;
|
||||
const { defaultAppends = [], appends = [], defaultFilter, filter, ...others } = options;
|
||||
const { resourceName } = this.options;
|
||||
return request(`${resourceName}:list`, {
|
||||
method: 'get',
|
||||
params: {
|
||||
filter: decodeURIComponent(JSON.stringify({ and: [defaultFilter, filter].filter(Boolean) })),
|
||||
'fields[appends]': defaultAppends.concat(appends).join(','),
|
||||
...others,
|
||||
},
|
||||
});
|
||||
@ -63,8 +67,12 @@ export class Resource {
|
||||
if (!resourceKey) {
|
||||
return Promise.resolve({ data: {} });
|
||||
}
|
||||
const { defaultAppends = [], appends = [], ...others } = options;
|
||||
return request(`${resourceName}:get/${resourceKey}`, {
|
||||
params: options,
|
||||
params: {
|
||||
...others,
|
||||
'fields[appends]': defaultAppends.concat(appends).join(','),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -397,6 +397,7 @@ function generateCardItemSchema(component) {
|
||||
rowKey: 'id',
|
||||
// dragSort: true,
|
||||
showIndex: true,
|
||||
defaultAppends: ['user', 'collection'],
|
||||
refreshRequestOnChange: true,
|
||||
pagination: {
|
||||
pageSize: 10,
|
||||
@ -503,7 +504,7 @@ function generateCardItemSchema(component) {
|
||||
properties: {
|
||||
[uid()]: {
|
||||
type: 'void',
|
||||
title: '查看',
|
||||
title: '查看数据',
|
||||
'x-read-pretty': true,
|
||||
'x-decorator': 'Form',
|
||||
'x-decorator-props': {
|
||||
@ -559,7 +560,7 @@ function generateCardItemSchema(component) {
|
||||
properties: {
|
||||
'field.uiSchema.title': {
|
||||
type: 'string',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-decorator': 'FormilyFormItem',
|
||||
'x-component': 'Input',
|
||||
},
|
||||
},
|
||||
@ -571,7 +572,7 @@ function generateCardItemSchema(component) {
|
||||
properties: {
|
||||
before: {
|
||||
type: 'string',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-decorator': 'FormilyFormItem',
|
||||
'x-component': 'Values',
|
||||
},
|
||||
},
|
||||
@ -583,7 +584,7 @@ function generateCardItemSchema(component) {
|
||||
properties: {
|
||||
after: {
|
||||
type: 'string',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-decorator': 'FormilyFormItem',
|
||||
'x-component': 'Values',
|
||||
},
|
||||
},
|
||||
|
@ -672,6 +672,9 @@ const TableProvider = (props: any) => {
|
||||
} else {
|
||||
defaultParams['sort'] = (props.defaultSort || []).join(',');
|
||||
}
|
||||
if (props.defaultAppends) {
|
||||
defaultParams['defaultAppends'] = props.defaultAppends;
|
||||
}
|
||||
if (props.defaultFilter) {
|
||||
defaultParams['defaultFilter'] = props.defaultFilter;
|
||||
}
|
||||
@ -2059,8 +2062,7 @@ Table.useActionLogDetailsResource = ({ onSuccess }) => {
|
||||
});
|
||||
const service = useRequest(
|
||||
(params?: any) => {
|
||||
console.log('Table.useResource', params);
|
||||
return resource.get({ ...params, 'fields[appends]': 'changes' });
|
||||
return resource.get({ ...params, appends: 'changes' });
|
||||
},
|
||||
{
|
||||
formatResult: (result) => result?.data,
|
||||
|
Loading…
Reference in New Issue
Block a user