Skip to content

Commit

Permalink
feat: 增加 antVersion 配置属性,用来处理 ant v4 与 v5 不兼容性属性问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lhbxs committed Dec 19, 2023
1 parent f28d58c commit b8b191c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/form-render/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ npm i form-render --save
* defaultShowCode: true
*/
import React from 'react';
import { version } from 'antd';
import FormRender, { useForm } from 'form-render';
import schema from './schema/simple';

console.log(version, 'xxxxx')

export default () => {
const form = useForm();

Expand Down
2 changes: 2 additions & 0 deletions packages/form-render/src/form-core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ const FormCore:FC<FRProps> = (props) => {
id,
className,
validateTrigger,
antVersion,
} = transformProps({ ...props, ...schemProps });

useEffect(() => {
form.__initStore(store);
setTimeout(initial, 0);
(window as any).antVersion = antVersion;
}, []);

useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion packages/form-render/src/models/transformProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const transformProps = (props: any) => {
disabled,
className,
validateTrigger,
antVersion,
...otherProps
} = props;

Expand Down Expand Up @@ -76,7 +77,8 @@ const transformProps = (props: any) => {
fieldCol,
maxWidth,
className,
validateTrigger
validateTrigger,
antVersion
};
};

Expand Down
10 changes: 7 additions & 3 deletions packages/form-render/src/widgets/listDrawer/drawerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ const DrawerForm = (props: any) => {
onClose();
};

const drawerProps = {
visible: true,
let drawerProps: any = {
open: true
};
if ((window as any).antVersion === 'v4') {
drawerProps = {
visible: true
};
}

return (
<Drawer
{...drawerProps}
width={600}
title={t('operate')}
open={true}
onClose={handleClose}
extra={
<Space>
Expand Down
3 changes: 1 addition & 2 deletions packages/form-render/src/widgets/listDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const TableList: React.FC<Props> = (props: any) => {
readOnly,
widgets,
pagination,



operateBtnType,
addBtnProps,
delConfirmProps,
Expand Down
14 changes: 12 additions & 2 deletions packages/form-render/src/widgets/listTable/tableCell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useRef } from 'react';
import { Popover } from 'antd';
import { Popover, version } from 'antd';

const TableCell = (props: any) => {
const { renderCore, schema, dataIndex, ...otherProps } = props;
Expand All @@ -19,6 +19,16 @@ const TableCell = (props: any) => {
if (!schema.properties[dataIndex].onStatusChange) {
schema.properties[dataIndex].onStatusChange = onStatusChange;
}

const popoverVisible = visible && errorMsg;
let popoverProps: any = {
open: popoverVisible
};
if ((window as any).antVersion === 'v4') {
popoverProps = {
visible: popoverVisible
};
}

return (
<div
Expand All @@ -36,7 +46,7 @@ const TableCell = (props: any) => {
overlayClassName='fr-popover-error'
content={errorMsg}
placement='topRight'
open={visible && errorMsg}
{...popoverProps}
>
{renderCore({ ...otherProps, schema })}
</Popover>
Expand Down
12 changes: 11 additions & 1 deletion packages/form-render/src/widgets/listVirtual/virtualCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ const VirtualCell = (props: any) => {
if (!schema.properties[dataIndex].onStatusChange) {
schema.properties[dataIndex].onStatusChange = onStatusChange;
}

const popoverVisible = visible && errorMsg;
let popoverProps: any = {
open: popoverVisible
};
if ((window as any).antVersion === 'v4') {
popoverProps = {
visible: popoverVisible
};
}

return (
<div
Expand All @@ -35,7 +45,7 @@ const VirtualCell = (props: any) => {
overlayClassName='fr-popover-error'
content={errorMsg}
placement='topRight'
open={visible && errorMsg}
{...popoverProps}
>
{renderCore({ ...otherProps, schema })}
</Popover>
Expand Down

0 comments on commit b8b191c

Please sign in to comment.