From 6d7a811d561019008adb3cd46ce4cbae81eeeaf0 Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 9 Aug 2021 10:40:40 +0800 Subject: [PATCH] feat: filter support custom fields --- packages/client/src/schemas/add-new/index.tsx | 58 ++++++- .../src/schemas/table/SimpleDesignableBar.tsx | 150 ++++++++++++++++-- packages/client/src/schemas/table/index.tsx | 22 ++- 3 files changed, 212 insertions(+), 18 deletions(-) diff --git a/packages/client/src/schemas/add-new/index.tsx b/packages/client/src/schemas/add-new/index.tsx index 79977c3f6..4f38c5f2b 100644 --- a/packages/client/src/schemas/add-new/index.tsx +++ b/packages/client/src/schemas/add-new/index.tsx @@ -415,6 +415,57 @@ function generateCardItemSchema(component) { 'x-component-props': { fieldNames: [], }, + properties: { + column1: { + type: 'void', + title: '操作类型', + 'x-component': 'Filter.Column', + 'x-component-props': { + operations: [ + { + label: '等于', + value: 'eq', + selected: true, + schema: { 'x-component': 'Select' }, + }, + { + label: '不等于', + value: 'ne', + schema: { 'x-component': 'Select' }, + }, + { + label: '包含', + value: 'in', + schema: { + 'x-component': 'Select', + 'x-component-props': { mode: 'tags' }, + }, + }, + { + label: '不包含', + value: 'notIn', + schema: { + 'x-component': 'Select', + 'x-component-props': { mode: 'tags' }, + }, + }, + { label: '非空', value: '$notNull', noValue: true }, + { label: '为空', value: '$null', noValue: true }, + ], + }, + properties: { + type: { + type: 'string', + 'x-component': 'Select', + enum: [ + { label: '新增数据', value: 'create' }, + { label: '更新数据', value: 'update' }, + { label: '删除数据', value: 'destroy' }, + ], + }, + }, + }, + }, }, }, }, @@ -456,7 +507,8 @@ function generateCardItemSchema(component) { 'x-read-pretty': true, 'x-decorator': 'Form', 'x-decorator-props': { - useResource: '{{ Table.useActionLogDetailsResource }}', + useResource: + '{{ Table.useActionLogDetailsResource }}', }, 'x-component': 'Action.Drawer', 'x-component-props': { @@ -806,7 +858,9 @@ AddNew.CardItem = observer((props: any) => { 操作日志 - 新建模板 + + 新建模板 + } diff --git a/packages/client/src/schemas/table/SimpleDesignableBar.tsx b/packages/client/src/schemas/table/SimpleDesignableBar.tsx index 4db46f291..97109ea7f 100644 --- a/packages/client/src/schemas/table/SimpleDesignableBar.tsx +++ b/packages/client/src/schemas/table/SimpleDesignableBar.tsx @@ -17,12 +17,13 @@ import { SchemaField, useDesignable, removeSchema, + updateSchema, } from '../'; import get from 'lodash/get'; -import { Button, Dropdown, Menu, Space } from 'antd'; +import { Button, Dropdown, Menu, Select, Space } from 'antd'; import { MenuOutlined, DragOutlined } from '@ant-design/icons'; import cls from 'classnames'; -import { FormLayout } from '@formily/antd'; +import { FormDialog, FormLayout } from '@formily/antd'; import './style.less'; import AddNew from '../add-new'; import { DraggableBlockContext } from '../../components/drag-and-drop'; @@ -31,6 +32,7 @@ import constate from 'constate'; import { useEffect } from 'react'; import { uid } from '@formily/shared'; import { getSchemaPath } from '../../components/schema-renderer'; +import { set } from 'lodash'; export const SimpleDesignableBar = observer((props) => { const field = useField(); @@ -40,6 +42,8 @@ export const SimpleDesignableBar = observer((props) => { if (!designable) { return null; } + const defaultPageSize = + field?.componentProps?.pagination?.defaultPageSize || 10; return (
{ }} overlay={ - {/* { - field.readPretty = true; + { + const { defaultFilter } = await FormDialog( + '设置筛选范围', + () => { + return ( + + + + ); + }, + ).open({ + initialValues: { + defaultFilter: + field?.componentProps?.defaultFilter || {}, + }, + }); + schema['x-component-props']['defaultFilter'] = + defaultFilter; + field.componentProps.defaultFilter = defaultFilter; + await updateSchema(schema); }} > - 编辑表单配置 - */} - {/* */} + 设置筛选范围 + + + 每页默认显示{' '} + {' '} + 条 + + { diff --git a/packages/client/src/schemas/table/index.tsx b/packages/client/src/schemas/table/index.tsx index e41f61f3d..478d3c265 100644 --- a/packages/client/src/schemas/table/index.tsx +++ b/packages/client/src/schemas/table/index.tsx @@ -362,7 +362,10 @@ const useTableColumns = () => { }), ); - if (designable && schema['x-designable-bar'] !== 'Table.SimpleDesignableBar') { + if ( + designable && + schema['x-designable-bar'] !== 'Table.SimpleDesignableBar' + ) { columns.push({ title: , dataIndex: 'addnew', @@ -1209,9 +1212,11 @@ Table.Filter = observer((props: any) => { const count = Object.values(obj).filter((i) => Array.isArray(i) ? i.length : i, ).length; - const icon = props.icon || 'FilterOutlined'; - + const properties = fieldsToFilterColumns(fields, { fieldNames }); + schema.mapProperties((p) => { + properties[p.name] = p; + }); return ( { filter: { type: 'object', 'x-component': 'Filter', - properties: fieldsToFilterColumns(fields, { fieldNames }), + properties, }, }, }} @@ -2026,7 +2031,10 @@ Table.useResource = ({ onSuccess, manual = true }) => { resourceName: collection?.name || props.collectionName, resourceKey: ctx.record[props.rowKey], }); - console.log('collection?.name || props.collectionName', collection?.name || props.collectionName) + console.log( + 'collection?.name || props.collectionName', + collection?.name || props.collectionName, + ); const service = useRequest( (params?: any) => { console.log('Table.useResource', params); @@ -2052,7 +2060,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, 'fields[appends]': 'changes' }); }, { formatResult: (result) => result?.data, @@ -2085,4 +2093,4 @@ Table.useTableUpdateAction = useTableUpdateAction; Table.useTableDestroyAction = useTableDestroyAction; Table.useTableIndex = useTableIndex; Table.useTableRowRecord = useTableRowRecord; -Table.SimpleDesignableBar = SimpleDesignableBar; \ No newline at end of file +Table.SimpleDesignableBar = SimpleDesignableBar;