mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-01 11:47:51 +08:00
fix: add view filter to action params
This commit is contained in:
parent
a342c30175
commit
8739ea79d2
@ -58,6 +58,27 @@ api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
}
|
||||
await next();
|
||||
});
|
||||
|
||||
api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
const { resourceName, viewName, filter } = ctx.action.params;
|
||||
// TODO: 需要补充默认视图的情况
|
||||
let view: any;
|
||||
if (viewName) {
|
||||
view = await ctx.db.getModel('views').findOne({
|
||||
where: {
|
||||
collection_name: resourceName,
|
||||
name: viewName,
|
||||
}
|
||||
});
|
||||
const viewFilter = view.get('filter');
|
||||
if (viewFilter) {
|
||||
const args = [viewFilter, filter].filter(Boolean);
|
||||
ctx.action.setParam('filter', {and: args});
|
||||
console.log(ctx.action.params.filter);
|
||||
}
|
||||
}
|
||||
await next();
|
||||
});
|
||||
api.resourcer.use(associated);
|
||||
api.resourcer.registerActionHandlers({...actions.common, ...actions.associate});
|
||||
|
||||
|
@ -25,7 +25,7 @@ export function SimpleTable(props: SimpleTableProps) {
|
||||
associatedName,
|
||||
associatedKey,
|
||||
} = props;
|
||||
const { rowKey = 'id', fields = [], rowViewName, actions = [], paginated = true, defaultPerPage = 10 } = schema;
|
||||
const { rowKey = 'id', name: viewName, fields = [], rowViewName, actions = [], paginated = true, defaultPerPage = 10 } = schema;
|
||||
const { sourceKey = 'id' } = activeTab.field||{};
|
||||
const drawerRef = useRef<any>();
|
||||
const name = associatedName ? `${associatedName}.${resourceName}` : resourceName;
|
||||
@ -37,6 +37,7 @@ export function SimpleTable(props: SimpleTableProps) {
|
||||
perPage: paginated ? pageSize : -1,
|
||||
sorter,
|
||||
filter,
|
||||
viewName,
|
||||
})
|
||||
.then(({data = [], meta = {}}) => {
|
||||
return {
|
||||
|
@ -6,24 +6,6 @@ import { request, useRequest } from 'umi';
|
||||
import api from '@/api-client';
|
||||
import { components, fields2columns } from './SortableTable';
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '姓名',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
},
|
||||
{
|
||||
title: '年龄',
|
||||
dataIndex: 'age',
|
||||
key: 'age',
|
||||
},
|
||||
{
|
||||
title: '住址',
|
||||
dataIndex: 'address',
|
||||
key: 'address',
|
||||
},
|
||||
];
|
||||
|
||||
export interface TableProps {
|
||||
schema?: any;
|
||||
activeTab?: any;
|
||||
@ -41,7 +23,7 @@ export function Table(props: TableProps) {
|
||||
associatedName,
|
||||
associatedKey,
|
||||
} = props;
|
||||
const { fields, defaultTabName, rowKey = 'id', actions = [], paginated = true, defaultPerPage = 10 } = schema;
|
||||
const { name: viewName, fields, defaultTabName, rowKey = 'id', actions = [], paginated = true, defaultPerPage = 10 } = schema;
|
||||
// const { data, mutate } = useRequest(() => api.resource(name).list({
|
||||
// associatedKey,
|
||||
// }));
|
||||
@ -55,6 +37,7 @@ export function Table(props: TableProps) {
|
||||
perPage: paginated ? pageSize : -1,
|
||||
sorter,
|
||||
filter,
|
||||
viewName,
|
||||
// ...args2,
|
||||
})
|
||||
.then(({data = [], meta = {}}) => {
|
||||
|
Loading…
Reference in New Issue
Block a user