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