diff --git a/packages/app/package.json b/packages/app/package.json index 35fa9e671..189739ab2 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -43,6 +43,7 @@ "react-drag-listview": "^0.1.8", "react-image-lightbox": "^5.1.1", "react-sortable-hoc": "^1.11.0", + "react-to-print": "^2.12.3", "styled-components": "^5.2.1", "umi": "^3.2.23", "yorkie": "^2.0.0" diff --git a/packages/app/src/components/pages/AdminLoader/Actions/index.tsx b/packages/app/src/components/pages/AdminLoader/Actions/index.tsx index 0d4ef7048..1aa97f42c 100644 --- a/packages/app/src/components/pages/AdminLoader/Actions/index.tsx +++ b/packages/app/src/components/pages/AdminLoader/Actions/index.tsx @@ -5,11 +5,17 @@ import { PlusOutlined, SelectOutlined, DeleteOutlined, + PrinterOutlined, + ExportOutlined, } from '@ant-design/icons'; import Drawer from '@/components/pages/AdminLoader/Drawer'; import View from '@/components/pages/AdminLoader/View'; import get from 'lodash/get'; import set from 'lodash/set'; +import ReactToPrint from 'react-to-print'; +import api from '@/api-client'; + +const ACTIONS = new Map(); export function Create(props) { const { size, onFinish, schema = {}, associatedKey, ...restProps } = props; @@ -284,20 +290,62 @@ export function Filter(props) { ); } +export function Print(props) { + const { schema = {}, contentRef } = props; + const { title, buttonProps = {} } = schema; + return ( + ( + + )} + content={() => contentRef.current} + pageStyle={` + @page { + margin: 1cm; + } + table { page-break-inside:auto } + tr { page-break-inside:avoid; page-break-after:auto } + `} + documentTitle={' '} + /> + ); +} + +export function Export(props) { + const { schema = {}, onFinish } = props; + const { title, buttonProps = {} } = schema; + return ( + + ); +} + export function Actions(props) { const { onTrigger = {}, actions = [], style, ...restProps } = props; return ( actions.length > 0 && (
- {actions.map(action => ( -
- -
- ))} + {actions.map( + action => + ACTIONS.has(action.type) && ( +
+ +
+ ), + )}
) ); @@ -305,8 +353,6 @@ export function Actions(props) { export default Actions; -const ACTIONS = new Map(); - export function registerAction(type: string, Action: any) { ACTIONS.set(type, Action); } @@ -328,3 +374,5 @@ registerAction('update', Update); registerAction('create', Create); registerAction('destroy', Destroy); registerAction('filter', Filter); +registerAction('print', Print); +registerAction('export', Export); diff --git a/packages/app/src/components/pages/AdminLoader/View/Descriptions.tsx b/packages/app/src/components/pages/AdminLoader/View/Descriptions.tsx index 4fb992cc9..454030fa6 100644 --- a/packages/app/src/components/pages/AdminLoader/View/Descriptions.tsx +++ b/packages/app/src/components/pages/AdminLoader/View/Descriptions.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useRef } from 'react'; import './style.less'; import { Helmet } from 'umi'; import { Spin } from '@nocobase/client'; @@ -24,7 +24,6 @@ import Field from '@/components/views/Field'; import { Form } from './Form'; import { configResponsive, useResponsive } from 'ahooks'; import { InfoCircleOutlined } from '@ant-design/icons'; -import scopes from '@/components/views/Form/scopes'; configResponsive({ small: 0, @@ -84,6 +83,7 @@ export function Descriptions(props) { 'fields[appends]': appends, }); }); + const contentRef = useRef(); if (loading) { return ; } @@ -97,6 +97,7 @@ export function Descriptions(props) { }; } const groups = toGroups(fields); + return (
- {groups.map(group => ( - - {group.title}{' '} - {group.tooltip && ( - +
+ {groups.map(group => ( + + {group.title}{' '} + {group.tooltip && ( + + + + )} + + ) + } + column={1} + > + {group.children.map((field: any) => { + const label = field.tooltip ? ( + <> + {field.title || field.name}  + - )} - - ) - } - column={1} - > - {group.children.map((field: any) => { - const label = field.tooltip ? ( - <> - {field.title || field.name}  - - - - - ) : ( - field.title || field.name - ); - return ( - - - - ); - })} - - ))} + + ) : ( + field.title || field.name + ); + return ( + + + + ); + })} + + ))} +
); } diff --git a/packages/plugin-pages/src/collections/views_actions_v2.ts b/packages/plugin-pages/src/collections/views_actions_v2.ts index a53d6b4fe..7d06deb47 100644 --- a/packages/plugin-pages/src/collections/views_actions_v2.ts +++ b/packages/plugin-pages/src/collections/views_actions_v2.ts @@ -25,6 +25,8 @@ export default { title: '操作类型', dataSource: [ { label: '筛选', value: 'filter' }, + { label: '打印', value: 'print' }, + { label: '导出', value: 'export' }, { label: '新增', value: 'create' }, { label: '编辑', value: 'update' }, { label: '删除', value: 'destroy' },