From 4bc2df296d5d1ef93198dc8445966b74dbd6451f Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 21 Dec 2020 10:41:12 +0800 Subject: [PATCH] feat: add actionDefaultParams to views --- packages/app/src/components/views/Details.tsx | 4 ++-- packages/app/src/components/views/Form/DrawerForm.tsx | 5 ++++- packages/app/src/components/views/SimpleTable.tsx | 3 ++- packages/app/src/components/views/Table.tsx | 3 ++- packages/plugin-pages/src/actions/getView.ts | 4 ++++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/app/src/components/views/Details.tsx b/packages/app/src/components/views/Details.tsx index c97a63d1a9..010c50d681 100644 --- a/packages/app/src/components/views/Details.tsx +++ b/packages/app/src/components/views/Details.tsx @@ -17,13 +17,13 @@ export function Details(props: any) { associatedKey, resourceKey, } = props; - const { actions = [], fields = [] } = props.schema; + const { actions = [], actionDefaultParams = {}, fields = [] } = props.schema; const { data = {}, loading, refresh } = useRequest(() => { const name = associatedName ? `${associatedName}.${resourceName}` : resourceName; return api.resource(name).get({ resourceKey, associatedKey, - 'fields[appends]': fields.filter(field => get(field, 'interface') === 'subTable').map(field => field.name).join(',') + ...actionDefaultParams, }); }); console.log(props); diff --git a/packages/app/src/components/views/Form/DrawerForm.tsx b/packages/app/src/components/views/Form/DrawerForm.tsx index 9fb251e5f2..5be26b1de7 100644 --- a/packages/app/src/components/views/Form/DrawerForm.tsx +++ b/packages/app/src/components/views/Form/DrawerForm.tsx @@ -12,7 +12,9 @@ import { registerFormFields, FormValidator, setValidationLanguage, + FormEffectHooks, } from '@formily/antd'; +import { merge } from '@formily/shared'; import { QuestionCircleOutlined } from '@ant-design/icons'; import { useRequest } from 'umi'; import api from '@/api-client'; @@ -30,6 +32,7 @@ export const DrawerForm = forwardRef((props: any, ref) => { onFinish, } = props; console.log(associatedKey); + const { title, actionDefaultParams = {}, fields: properties ={} } = props.schema||{}; const [resourceKey, setResourceKey] = useState(props.resourceKey); const [visible, setVisible] = useState(false); const name = associatedName ? `${associatedName}.${resourceName}` : resourceName; @@ -38,6 +41,7 @@ export const DrawerForm = forwardRef((props: any, ref) => { return api.resource(name).get({ resourceKey, associatedKey, + ...actionDefaultParams, }); }, { manual: true, @@ -47,7 +51,6 @@ export const DrawerForm = forwardRef((props: any, ref) => { getData: run, })); const actions = createFormActions(); - const { title, fields: properties ={} } = props.schema||{}; console.log({onFinish}); return ( (); const name = associatedName ? `${associatedName}.${resourceName}` : resourceName; @@ -38,6 +38,7 @@ export function SimpleTable(props: SimpleTableProps) { sorter, filter, viewName, + ...actionDefaultParams, }) .then(({data = [], meta = {}}) => { return { diff --git a/packages/app/src/components/views/Table.tsx b/packages/app/src/components/views/Table.tsx index 18d32ac3be..66eaf74496 100644 --- a/packages/app/src/components/views/Table.tsx +++ b/packages/app/src/components/views/Table.tsx @@ -23,7 +23,7 @@ export function Table(props: TableProps) { associatedName, associatedKey, } = props; - const { name: viewName, fields, defaultTabName, rowKey = 'id', actions = [], paginated = true, defaultPerPage = 10 } = schema; + const { name: viewName, fields, actionDefaultParams = {}, defaultTabName, rowKey = 'id', actions = [], paginated = true, defaultPerPage = 10 } = schema; // const { data, mutate } = useRequest(() => api.resource(name).list({ // associatedKey, // })); @@ -38,6 +38,7 @@ export function Table(props: TableProps) { sorter, filter, viewName, + ...actionDefaultParams, // ...args2, }) .then(({data = [], meta = {}}) => { diff --git a/packages/plugin-pages/src/actions/getView.ts b/packages/plugin-pages/src/actions/getView.ts index ed8b773e69..77506d1c2d 100644 --- a/packages/plugin-pages/src/actions/getView.ts +++ b/packages/plugin-pages/src/actions/getView.ts @@ -192,9 +192,13 @@ export default async (ctx, next) => { } else { title = `创建${title}`; } + const actionDefaultParams:any = {}; + const appends = fields.filter(field => get(field, 'interface') === 'subTable').map(field => field.name).join(','); + actionDefaultParams['fields[appends]'] = appends; ctx.body = { ...view.get(), title, + actionDefaultParams, original: fields, fields: await (transforms[view.type]||transforms.table)(fields, ctx), actions: actions.filter(action => actionNames.includes(action.name)).map(action => ({