From ed4397e112b939eeedafe96ce95db39be1bcfad1 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 7 Jul 2021 22:50:40 +0800 Subject: [PATCH] updates... --- .../blocks/DesignableSchemaField/index.tsx | 12 +- packages/client/src/blocks/action/index.tsx | 42 +- packages/client/src/blocks/form/index.tsx | 32 +- .../client/src/blocks/table/demos/demo1.tsx | 283 ++++++++++++++ packages/client/src/blocks/table/index.md | 317 +-------------- packages/client/src/blocks/table/index.tsx | 368 +++++++++++------- 6 files changed, 582 insertions(+), 472 deletions(-) create mode 100644 packages/client/src/blocks/table/demos/demo1.tsx diff --git a/packages/client/src/blocks/DesignableSchemaField/index.tsx b/packages/client/src/blocks/DesignableSchemaField/index.tsx index 336c0cea4..9e0517f8a 100644 --- a/packages/client/src/blocks/DesignableSchemaField/index.tsx +++ b/packages/client/src/blocks/DesignableSchemaField/index.tsx @@ -40,7 +40,14 @@ import { Menu } from '../menu'; import { Password } from '../password'; import { Radio } from '../radio'; import { Select } from '../select'; -import { Table, useTableCreateAction, useTableDestroyAction } from '../table'; +import { + Table, + useTableRow, + useTableCreateAction, + useTableUpdateAction, + useTableDestroyAction, + useTableFilterAction, +} from '../table'; import { Tabs } from '../tabs'; import { TimePicker } from '../time-picker'; import { Upload } from '../upload'; @@ -61,6 +68,9 @@ export const scope = { useSubmit, useTableCreateAction, useTableDestroyAction, + useTableFilterAction, + useTableRow, + useTableUpdateAction, }; export const components = { diff --git a/packages/client/src/blocks/action/index.tsx b/packages/client/src/blocks/action/index.tsx index 0f71d58d7..95a7a984a 100644 --- a/packages/client/src/blocks/action/index.tsx +++ b/packages/client/src/blocks/action/index.tsx @@ -1,4 +1,4 @@ -import React, { createContext, useContext, useState } from 'react'; +import React, { createContext, useContext, useEffect, useState } from 'react'; import { useForm, FormProvider, @@ -95,14 +95,12 @@ function useDesignableBar() { }; } -const [VisibleProvider, useVisibleContext] = constate( - (props: any = {}) => { - const { initialVisible = false, containerRef = null } = props; - const [visible, setVisible] = useState(initialVisible); +const [VisibleProvider, useVisibleContext] = constate((props: any = {}) => { + const { initialVisible = false, containerRef = null } = props; + const [visible, setVisible] = useState(initialVisible); - return { containerRef, visible, setVisible }; - }, -); + return { containerRef, visible, setVisible }; +}); export { VisibleProvider, useVisibleContext }; @@ -113,11 +111,17 @@ const BaseAction = observer((props: any) => { const { DesignableBar } = useDesignableBar(); const { setVisible } = useVisibleContext(); const schema = useFieldSchema(); + useEffect(() => { + field.componentProps.setVisible = setVisible; + }, []); + + console.log('BaseAction', { field, schema }, field.title) const renderButton = () => ( { + console.log(keys); setSelectedRowKeys(keys); }, }} + dataSource={data?.list} + columns={columns} + onRow={(data) => { + const index = dataSource.indexOf(data); + return { + onClick(e) { + field.query(`.${schema.name}.${index}.action2`).take((f) => { + const setVisible = f.componentProps.setVisible; + setVisible && setVisible(true); + }); + }, + }; + }} /> {actionBars.bottom.map((actionBarSchema) => { return ( @@ -217,12 +315,12 @@ const ArrayTable = (props) => { })} ); -}; +}); export const Table: any = observer((props) => { return ( - + ); }); @@ -238,41 +336,29 @@ Table.ActionBar = observer((props) => { }); Table.Pagination = observer((props) => { - const { response } = useTableContext(); - return ( + const { data, params, run } = useTableContext(); + return data?.total > params?.pageSize && ( { - response.refresh(); - // console.log('useRequest', { page, pageSize }); + run({ page, pageSize }); }} /> ); }); -Table.View = observer(() => { - const schema = useFieldSchema(); - console.log('Table.View', schema); - return ( - - ); +Table.SortHandle = observer((props) => { + const field = useField(); + console.log('SortHandle', field.value); + return ; }); -Table.Field = observer((props) => { - return ( - - - - ); +Table.Index = observer((props) => { + const index = useTableIndex(); + return
#{index + 1}
; });