fix(app): filter merge

This commit is contained in:
chenos 2021-01-01 17:35:28 +08:00
parent 89650750b1
commit 97136c62ba
2 changed files with 17 additions and 2 deletions

View File

@ -32,6 +32,7 @@ export function SimpleTable(props: SimpleTableProps) {
selectedRowKeys: srk, selectedRowKeys: srk,
} = props; } = props;
const { rowKey = 'id', name: viewName, actionDefaultParams = {}, fields = [], rowViewName, actions = [], paginated = true, defaultPerPage = 10 } = schema; const { rowKey = 'id', name: viewName, actionDefaultParams = {}, fields = [], rowViewName, actions = [], paginated = true, defaultPerPage = 10 } = schema;
const { filter: defaultFilter = {} } = actionDefaultParams;
const { sourceKey = 'id' } = activeTab.field||{}; const { sourceKey = 'id' } = activeTab.field||{};
const drawerRef = useRef<any>(); const drawerRef = useRef<any>();
const [filterCount, setFilterCount] = useState(0); const [filterCount, setFilterCount] = useState(0);
@ -43,9 +44,15 @@ export function SimpleTable(props: SimpleTableProps) {
page: paginated ? current : 1, page: paginated ? current : 1,
perPage: paginated ? pageSize : -1, perPage: paginated ? pageSize : -1,
sorter, sorter,
filter, // filter,
viewName, viewName,
...actionDefaultParams, ...actionDefaultParams,
filter: {
and: [
defaultFilter,
filter,
].filter(obj => obj && Object.keys(obj).length)
}
}) })
.then(({data = [], meta = {}}) => { .then(({data = [], meta = {}}) => {
return { return {

View File

@ -34,6 +34,8 @@ export function Table(props: TableProps) {
// const { data, mutate } = useRequest(() => api.resource(name).list({ // const { data, mutate } = useRequest(() => api.resource(name).list({
// associatedKey, // associatedKey,
// })); // }));
const { filter: defaultFilter = {} } = actionDefaultParams;
const [filterCount, setFilterCount] = useState(0); const [filterCount, setFilterCount] = useState(0);
const name = associatedName ? `${associatedName}.${resourceName}` : resourceName; const name = associatedName ? `${associatedName}.${resourceName}` : resourceName;
const { data, loading, pagination, mutate, refresh, run, params } = useRequest((params = {}, ...args) => { const { data, loading, pagination, mutate, refresh, run, params } = useRequest((params = {}, ...args) => {
@ -44,9 +46,15 @@ export function Table(props: TableProps) {
page: paginated ? current : 1, page: paginated ? current : 1,
perPage: paginated ? pageSize : -1, perPage: paginated ? pageSize : -1,
sorter, sorter,
filter, // filter,
viewName, viewName,
...actionDefaultParams, ...actionDefaultParams,
filter: {
and: [
defaultFilter,
filter,
].filter(obj => obj && Object.keys(obj).length)
}
// ...args2, // ...args2,
}) })
.then(({data = [], meta = {}}) => { .then(({data = [], meta = {}}) => {