mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:46:54 +00: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();
|
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.use(associated);
|
||||||
api.resourcer.registerActionHandlers({...actions.common, ...actions.associate});
|
api.resourcer.registerActionHandlers({...actions.common, ...actions.associate});
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export function SimpleTable(props: SimpleTableProps) {
|
|||||||
associatedName,
|
associatedName,
|
||||||
associatedKey,
|
associatedKey,
|
||||||
} = props;
|
} = 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 { sourceKey = 'id' } = activeTab.field||{};
|
||||||
const drawerRef = useRef<any>();
|
const drawerRef = useRef<any>();
|
||||||
const name = associatedName ? `${associatedName}.${resourceName}` : resourceName;
|
const name = associatedName ? `${associatedName}.${resourceName}` : resourceName;
|
||||||
@ -37,6 +37,7 @@ export function SimpleTable(props: SimpleTableProps) {
|
|||||||
perPage: paginated ? pageSize : -1,
|
perPage: paginated ? pageSize : -1,
|
||||||
sorter,
|
sorter,
|
||||||
filter,
|
filter,
|
||||||
|
viewName,
|
||||||
})
|
})
|
||||||
.then(({data = [], meta = {}}) => {
|
.then(({data = [], meta = {}}) => {
|
||||||
return {
|
return {
|
||||||
|
@ -6,24 +6,6 @@ import { request, useRequest } from 'umi';
|
|||||||
import api from '@/api-client';
|
import api from '@/api-client';
|
||||||
import { components, fields2columns } from './SortableTable';
|
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 {
|
export interface TableProps {
|
||||||
schema?: any;
|
schema?: any;
|
||||||
activeTab?: any;
|
activeTab?: any;
|
||||||
@ -41,7 +23,7 @@ export function Table(props: TableProps) {
|
|||||||
associatedName,
|
associatedName,
|
||||||
associatedKey,
|
associatedKey,
|
||||||
} = props;
|
} = 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({
|
// const { data, mutate } = useRequest(() => api.resource(name).list({
|
||||||
// associatedKey,
|
// associatedKey,
|
||||||
// }));
|
// }));
|
||||||
@ -55,6 +37,7 @@ export function Table(props: TableProps) {
|
|||||||
perPage: paginated ? pageSize : -1,
|
perPage: paginated ? pageSize : -1,
|
||||||
sorter,
|
sorter,
|
||||||
filter,
|
filter,
|
||||||
|
viewName,
|
||||||
// ...args2,
|
// ...args2,
|
||||||
})
|
})
|
||||||
.then(({data = [], meta = {}}) => {
|
.then(({data = [], meta = {}}) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user