Merge branch 'feat/updateTreeTransferAdapterToMingMou' into develop

This commit is contained in:
NICE CODE BY DEV 2024-07-04 16:04:19 +08:00
commit 490cc9ae4a
5 changed files with 190 additions and 42 deletions

View File

@ -6,21 +6,78 @@ import './index.less'
const componentName = 'zhst-biz-treeTransfer' const componentName = 'zhst-biz-treeTransfer'
export interface TreeTransferProps { export interface TreeTransferProps {
/**
* @description
* @array []
*/
titles?: string[] | ReactNode[] titles?: string[] | ReactNode[]
/**
* @description
*/
bordered?: boolean
/**
* @description
* antd-treeData
*/
dataSource: TreeDataNode[] dataSource: TreeDataNode[]
/**
* @description
*/
treeProps?: TreeProps treeProps?: TreeProps
/**
*
*/
showLeftSearch?: boolean showLeftSearch?: boolean
/**
* @description
*/
searchInputProps?: InputProps searchInputProps?: InputProps
/**
* @description
*/
targetItems: TreeDataNode[]; targetItems: TreeDataNode[];
/**
* @description id
*/
checkedKeys: string[]; checkedKeys: string[];
/**
* @description
*/
showFilter?: boolean; showFilter?: boolean;
/**
* @description
*/
showLeftPanelFooter?: boolean; showLeftPanelFooter?: boolean;
/**
* @description
*/
leftPanelFooterRender?: ReactNode | string; leftPanelFooterRender?: ReactNode | string;
/**
* @description
*/
showRightPanelFooter?: boolean; showRightPanelFooter?: boolean;
/**
*
* @param events
* @returns
*/
rightPanelFooterRender?: (events: { onOk: TreeTransferProps['onOk'], onReset: TreeTransferProps['onReset'] }) => ReactNode | string; rightPanelFooterRender?: (events: { onOk: TreeTransferProps['onOk'], onReset: TreeTransferProps['onReset'] }) => ReactNode | string;
/**
* @description
*/
leftPanelWidth?: string | number; leftPanelWidth?: string | number;
/**
* @description
*/
rightPanelWidth?: string | number; rightPanelWidth?: string | number;
/**
* @description
*/
leftPanelScrollY?: number; leftPanelScrollY?: number;
/**
* @description
*/
middleIcon?: ReactNode | string
rightPanelScrollY?: number; rightPanelScrollY?: number;
tabsItems?: TabsProps['items'] tabsItems?: TabsProps['items']
showLeftTabs?: boolean showLeftTabs?: boolean
@ -47,16 +104,16 @@ const TreeTransfer: React.FC<TreeTransferProps> = ({
dataSource, dataSource,
treeProps, treeProps,
titles = ['可选择的范围', '已选择的范围'], titles = ['可选择的范围', '已选择的范围'],
bordered,
searchInputProps, searchInputProps,
showLeftSearch = true, showLeftSearch = true,
leftPanelScrollY = 300, leftPanelScrollY = 300,
treeBackgroundColor = '#FCFCFC',
leftPanelWidth = 500, leftPanelWidth = 500,
rightPanelScrollY = 422, rightPanelScrollY = 422,
rightPanelWidth = 300, rightPanelWidth = 300,
targetItems = [], targetItems = [],
checkedKeys = [], checkedKeys = [],
showFilter = true, showFilter = false,
showLeftPanelFooter, showLeftPanelFooter,
showRightPanelFooter = true, showRightPanelFooter = true,
customLeftPanelContent, customLeftPanelContent,
@ -64,6 +121,7 @@ const TreeTransfer: React.FC<TreeTransferProps> = ({
rightPanelFooterRender, rightPanelFooterRender,
showLeftTabs, showLeftTabs,
leftTabsProps, leftTabsProps,
middleIcon,
activeTabKey, activeTabKey,
tabsItems = [ tabsItems = [
{ {
@ -94,12 +152,21 @@ const TreeTransfer: React.FC<TreeTransferProps> = ({
return ( return (
<div className={componentName}> <div className={componentName}>
<div className={`${componentName}-left`} <div className={`${componentName}-left`}
style={{ width: typeof leftPanelWidth === 'number' ? leftPanelWidth + 'px' : leftPanelWidth }} style={{
width: parseInt(String(leftPanelWidth)) + 'px',
border: bordered ? `1px solid ${token.colorBorder}` : 'unset',
}}
> >
<div <div
className={`${componentName}-left_card`} className={`${componentName}-left_card`}
style={{ backgroundColor: token.colorBgContainer }}
> >
<div className={`${componentName}-left_card_title`}>{titles?.[0]}</div> <div
className={`${componentName}-left_card_title`}
style={{ backgroundColor: '#f7f7f7' }}
>
{titles?.[0]}
</div>
{showLeftTabs && ( {showLeftTabs && (
<Tabs <Tabs
activeKey={activeTabKey} activeKey={activeTabKey}
@ -131,28 +198,17 @@ const TreeTransfer: React.FC<TreeTransferProps> = ({
</div> </div>
)} )}
{customLeftPanelContent?.(dataSource) || ( {customLeftPanelContent?.(dataSource) || (
<ConfigProvider <Tree
theme={{ className={`${componentName}-left_card-tree`}
components: { blockNode
// @ts-ignore checkable
Tree: { height={leftPanelScrollY}
colorBgContainer: treeBackgroundColor checkedKeys={checkedKeys}
} treeData={dataSource}
} onCheck={(keys: any, info: any) => onTreeCheck?.(keys, info)}
}} onSelect={(keys: any, info: any) => onTreeSelect?.(keys, info)}
> {...treeProps}
<Tree />
className={`${componentName}-left_card-tree`}
blockNode
checkable
height={leftPanelScrollY}
checkedKeys={checkedKeys}
treeData={dataSource}
onCheck={(keys: any, info: any) => onTreeCheck?.(keys, info)}
onSelect={(keys: any, info: any) => onTreeSelect?.(keys, info)}
{...treeProps}
/>
</ConfigProvider>
)} )}
{showLeftPanelFooter && ( {showLeftPanelFooter && (
<div className={`${componentName}-left_card-footer`}> <div className={`${componentName}-left_card-footer`}>
@ -162,15 +218,22 @@ const TreeTransfer: React.FC<TreeTransferProps> = ({
</div> </div>
</div> </div>
<div className={`${componentName}-middle`}> <div className={`${componentName}-middle`}>
<IconFont icon="icon-zhankai" /> {middleIcon || <IconFont icon="icon-zhankai" />}
</div> </div>
<div className={`${componentName}-right`} <div className={`${componentName}-right`}
style={{ width: typeof rightPanelWidth === 'number' ? rightPanelWidth + 'px' : rightPanelWidth }} style={{
width: parseInt(String(rightPanelWidth)) + 'px',
border: bordered ? `1px solid ${token.colorBorder}` : 'unset',
}}
> >
<div <div
className={`${componentName}-right_card`} className={`${componentName}-right_card`}
style={{ backgroundColor: token.colorBgContainer }}
> >
<div className={`${componentName}-right_card_title`} >{titles?.[1]}</div> <div
className={`${componentName}-right_card_title`}
style={{ backgroundColor: '#f7f7f7' }}
>{titles?.[1]}</div>
<div <div
className={`${componentName}-right_card__items`} className={`${componentName}-right_card__items`}
style={{ height: typeof rightPanelScrollY === 'number' ? rightPanelScrollY + 'px' : rightPanelScrollY}} style={{ height: typeof rightPanelScrollY === 'number' ? rightPanelScrollY + 'px' : rightPanelScrollY}}

View File

@ -0,0 +1,71 @@
import React, { useState } from 'react';
import { TreeTransfer } from '@zhst/biz';
import { TreeDataNode } from 'antd';
import { TreeProps } from 'antd/lib';
import { boxDataSource } from './mock'
const App: React.FC = () => {
const [targetItems, setTargetItems] = useState<TreeDataNode[]>([]);
const [checkedKeys, setCheckedKeys] = useState<string[]>([]);
const onTreeCheck: TreeProps['onCheck'] = (keys: any, info) => {
let _targetItems: TreeDataNode[] = []
setCheckedKeys(keys)
info.checkedNodes.forEach(o => {
o.isLeaf && _targetItems.push(o)
})
setTargetItems(_targetItems)
}
/**
*
* @param key
* @param param1
*/
const onItemDelete = (key: any, { keys = [] }: any) => {
setCheckedKeys(pre => {
const newKeys = pre.filter(_key => _key !== key)
console.log('newKeys', newKeys, keys)
return newKeys
})
setTargetItems(pre => pre.filter(o => o.key !== key))
}
const onOk = (data: any) => {
console.log('data', data)
}
const onReset = () => {
setCheckedKeys([])
setTargetItems([])
}
return (
<div style={{ padding: 24 }}>
<TreeTransfer
leftPanelWidth={800}
rightPanelWidth={500}
bordered
titles={[
<div style={{ textAlign: 'left' }}>(123)</div>,
(
<div onClick={onReset} style={{ textAlign: 'left' }}>(123)<a style={{ float: 'right' }}></a></div>
),
]}
showRightPanelFooter={false}
dataSource={boxDataSource}
targetItems={targetItems}
checkedKeys={checkedKeys}
onTreeCheck={onTreeCheck}
onItemDelete={onItemDelete}
onOk={onOk}
onReset={onReset}
searchInputProps={{
onChange: e => console.log('123123')
}}
/>
</div>
)
};
export default App;

View File

@ -2,6 +2,8 @@
display: flex; display: flex;
align-items: center; align-items: center;
&-left { &-left {
border-radius: 8px;
overflow: hidden;
&_card { &_card {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -33,13 +35,17 @@
&_search { &_search {
display: flex; display: flex;
margin: 8px; margin: 16px 20px;
&_input { &_input {
margin-right: 8px; flex: 1;
}
&_filters {
margin-left: 8px;
} }
} }
&-tree { &-tree {
margin: 0 20px;
} }
&-footer { &-footer {
@ -60,6 +66,8 @@
} }
&-right { &-right {
border-radius: 8px;
overflow: hidden;
&_card { &_card {
position: relative; position: relative;
min-height: 544px; min-height: 544px;
@ -74,10 +82,8 @@
&__items { &__items {
width: 100%; width: 100%;
height: calc(100% - 105px);
font-size: 14px; font-size: 14px;
overflow-y: scroll; overflow-y: scroll;
max-height: 422px;
box-sizing: border-box; box-sizing: border-box;
&::-webkit-scrollbar { &::-webkit-scrollbar {

View File

@ -16,6 +16,7 @@ group:
<code src="./demo/withFilter.tsx">加载filter按钮</code> <code src="./demo/withFilter.tsx">加载filter按钮</code>
<code src="./demo/withMap.tsx">和地图组件搭配使用</code> <code src="./demo/withMap.tsx">和地图组件搭配使用</code>
<code src="./demo/withModal.tsx">和Modal组合使用</code> <code src="./demo/withModal.tsx">和Modal组合使用</code>
<code src="./demo/mingmou.tsx">明眸同款</code>
## API ## API

View File

@ -1,5 +1,6 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Button, Modal } from 'antd'; import { Button, Modal } from '@zhst/meta';
import { px2remTransformer, StyleProvider } from '@ant-design/cssinjs';
const App: React.FC = () => { const App: React.FC = () => {
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
@ -16,16 +17,22 @@ const App: React.FC = () => {
setIsModalOpen(false); setIsModalOpen(false);
}; };
const px2rem = px2remTransformer({
rootValue: 12, // 32px = 1rem; @default 16
});
return ( return (
<> <>
<Button type="primary" onClick={showModal}> <StyleProvider transformers={[px2rem]} hashPriority='high'>
Open Modal <Button type="primary" onClick={showModal}>
</Button> Open Modal
<Modal title="Basic Modal" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}> </Button>
<p>Some contents...</p> <Modal title="Basic Modal" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}>
<p>Some contents...</p> <p>Some contents...</p>
<p>Some contents...</p> <p>Some contents...</p>
</Modal> <p>Some contents...</p>
</Modal>
</StyleProvider>
</> </>
); );
}; };