2021-07-09 01:41:03 +08:00
|
|
|
|
/*
|
|
|
|
|
* @Author: yehuozhili
|
|
|
|
|
* @Date: 2021-02-04 10:32:45
|
|
|
|
|
* @LastEditors: yehuozhili
|
2021-07-12 21:01:11 +08:00
|
|
|
|
* @LastEditTime: 2021-07-12 17:12:35
|
2021-07-11 13:56:35 +08:00
|
|
|
|
* @FilePath: \dooringx\packages\dooringx-lib\src\components\leftConfig.tsx
|
2021-07-09 01:41:03 +08:00
|
|
|
|
*/
|
|
|
|
|
import React, { ReactNode, useEffect, useMemo, useState } from 'react';
|
|
|
|
|
import { Input, Menu } from 'antd';
|
|
|
|
|
import { dragEventResolve, LeftRegistComponentMapItem } from '../core/crossDrag';
|
|
|
|
|
import UserConfig from '../config';
|
|
|
|
|
import { DoubleLeftOutlined, DoubleRightOutlined, SearchOutlined } from '@ant-design/icons';
|
|
|
|
|
|
|
|
|
|
import styles from '../index.less';
|
|
|
|
|
|
2021-08-12 11:06:46 +08:00
|
|
|
|
declare type modeType = 'horizontal' | 'vertical';
|
2021-07-09 01:41:03 +08:00
|
|
|
|
interface LeftConfigProps {
|
|
|
|
|
config: UserConfig;
|
2021-08-12 14:21:39 +08:00
|
|
|
|
showName?: Boolean;
|
2021-08-11 19:52:28 +08:00
|
|
|
|
footerConfig?: ReactNode;
|
2021-08-12 11:06:46 +08:00
|
|
|
|
mode?: modeType | undefined;
|
2021-07-09 01:41:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* 注册加载左侧组件方法,由于异步拉取,所以要异步加载
|
|
|
|
|
* 不同tab页可以使用不同type区分
|
2021-08-12 14:21:39 +08:00
|
|
|
|
* @param {*} props -LeftConfigProps options可选项:showName:是否显示displayName; mode:'horizontal' | 'vertical' icon与文案展示方向 ;footerConfig:底部功能配置ReactNode类型;
|
2021-07-09 01:41:03 +08:00
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
function LeftConfig(props: LeftConfigProps) {
|
|
|
|
|
const [menuSelect, setMenuSelect] = useState('0');
|
|
|
|
|
const [leftRender, setLeftRender] = useState<ReactNode | null>(null);
|
|
|
|
|
const leftMapRenderListCategory = useMemo(() => {
|
|
|
|
|
return props.config.getConfig().leftRenderListCategory;
|
|
|
|
|
}, [props.config]);
|
|
|
|
|
|
|
|
|
|
const [search, setSearch] = useState('');
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
let cache: LeftRegistComponentMapItem[] = [];
|
|
|
|
|
const type = leftMapRenderListCategory[parseInt(menuSelect, 10)]?.type;
|
|
|
|
|
const isCustom = leftMapRenderListCategory[parseInt(menuSelect, 10)]?.custom;
|
|
|
|
|
if (!isCustom) {
|
|
|
|
|
const config = props.config.getConfig();
|
|
|
|
|
cache = config.leftAllRegistMap.filter((k) => k.type === type);
|
|
|
|
|
cache.forEach((v) => props.config.asyncRegistComponent(v.component));
|
|
|
|
|
setLeftRender(
|
2021-07-10 19:35:06 +08:00
|
|
|
|
<div className={`${styles.leftco} yh-leftcomp`}>
|
2021-07-09 01:41:03 +08:00
|
|
|
|
<div
|
2021-07-12 15:32:21 +08:00
|
|
|
|
className="yh-left-top-wrapper"
|
2021-07-09 01:41:03 +08:00
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
padding: '10px',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
2021-07-10 19:35:06 +08:00
|
|
|
|
width: 120,
|
2021-07-09 01:41:03 +08:00
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
|
height: 32,
|
|
|
|
|
lineHeight: '32px',
|
|
|
|
|
marginRight: '10px',
|
|
|
|
|
fontSize: '14px',
|
|
|
|
|
fontFamily: 'PingFangSC-Medium, PingFang SC',
|
|
|
|
|
fontWeight: 600,
|
|
|
|
|
userSelect: 'none',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{leftMapRenderListCategory[parseInt(menuSelect, 10)].displayName}
|
|
|
|
|
</div>
|
|
|
|
|
<Input
|
2021-07-12 15:32:21 +08:00
|
|
|
|
className="yh-left-top-input"
|
2021-07-09 01:41:03 +08:00
|
|
|
|
style={{
|
|
|
|
|
borderRadius: '40px',
|
|
|
|
|
}}
|
|
|
|
|
allowClear
|
|
|
|
|
value={search}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSearch(e.target.value);
|
|
|
|
|
}}
|
|
|
|
|
prefix={<SearchOutlined />}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{search &&
|
|
|
|
|
search !== '' &&
|
|
|
|
|
cache
|
|
|
|
|
.reduce<LeftRegistComponentMapItem[]>((prev, next) => {
|
|
|
|
|
//筛选搜索条件,name或者displayName存在即显示
|
|
|
|
|
if (next.displayName.includes(search) || next.component.includes(search)) {
|
|
|
|
|
prev.push(next);
|
|
|
|
|
}
|
|
|
|
|
return prev;
|
|
|
|
|
}, [])
|
|
|
|
|
.map((v, index) => (
|
2021-07-12 15:32:21 +08:00
|
|
|
|
<div
|
|
|
|
|
className={`${styles.coitem} yh-left-item-wrap`}
|
|
|
|
|
key={index}
|
|
|
|
|
{...dragEventResolve(v)}
|
|
|
|
|
>
|
|
|
|
|
<div className={`${styles.redbox} yh-left-item-img-wrap`}>
|
2021-07-11 13:56:35 +08:00
|
|
|
|
{v.imgCustom ? v.imgCustom : <img src={v.img} alt="component"></img>}
|
2021-07-09 01:41:03 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
lineHeight: '20px',
|
|
|
|
|
height: '20px',
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{v.displayName}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
{(!search || search === '') &&
|
|
|
|
|
cache.map((v, index) => (
|
2021-07-12 15:32:21 +08:00
|
|
|
|
<div
|
|
|
|
|
className={`${styles.coitem} yh-left-item-wrap`}
|
|
|
|
|
key={index}
|
|
|
|
|
{...dragEventResolve(v)}
|
|
|
|
|
>
|
|
|
|
|
<div className={`${styles.redbox} yh-left-item-img-wrap`}>
|
2021-07-11 13:56:35 +08:00
|
|
|
|
{v.imgCustom ? v.imgCustom : <img src={v.img} alt="component"></img>}
|
2021-07-09 01:41:03 +08:00
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
lineHeight: '20px',
|
|
|
|
|
height: '20px',
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{v.displayName}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
const render = leftMapRenderListCategory[parseInt(menuSelect, 10)]?.customRender;
|
|
|
|
|
setLeftRender(<div className={styles.leftco}>{render}</div>);
|
|
|
|
|
}
|
|
|
|
|
}, [menuSelect, props.config, leftMapRenderListCategory, search]);
|
|
|
|
|
|
2021-07-12 21:01:11 +08:00
|
|
|
|
const [isCollapse, setCollapse] = useState(props.config.getCollapse());
|
|
|
|
|
const [renderCollapse, setRenderCollaspe] = useState(props.config.getCollapse());
|
2021-07-09 01:41:03 +08:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div style={{ display: 'flex', height: '100%' }}>
|
|
|
|
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
|
|
<Menu style={{ flex: 1 }} defaultSelectedKeys={[menuSelect]} mode="vertical">
|
|
|
|
|
{leftMapRenderListCategory.map((v, i) => {
|
|
|
|
|
return (
|
2021-08-11 19:52:28 +08:00
|
|
|
|
<Menu.Item
|
|
|
|
|
key={i}
|
|
|
|
|
onClick={() => setMenuSelect(i + '')}
|
|
|
|
|
icon={v.icon}
|
2021-08-12 11:06:46 +08:00
|
|
|
|
className={props.mode === 'vertical' ? `${styles.menuStyle}` : ''}
|
2021-08-11 19:52:28 +08:00
|
|
|
|
>
|
2021-08-12 14:21:39 +08:00
|
|
|
|
{props.showName && v.displayName}
|
2021-08-11 19:52:28 +08:00
|
|
|
|
</Menu.Item>
|
2021-07-09 01:41:03 +08:00
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Menu>
|
2021-08-11 19:52:28 +08:00
|
|
|
|
<div className={`${styles.menu_footer}`}>{props.footerConfig}</div>
|
2021-07-09 01:41:03 +08:00
|
|
|
|
<Menu selectedKeys={[]}>
|
|
|
|
|
<Menu.Item
|
|
|
|
|
key="1"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
setCollapse((pre) => {
|
|
|
|
|
if (pre) {
|
|
|
|
|
setTimeout(() => {
|
2021-07-12 21:01:11 +08:00
|
|
|
|
props.config.collapsed = false;
|
2021-07-09 01:41:03 +08:00
|
|
|
|
setRenderCollaspe(false);
|
2021-07-12 21:01:11 +08:00
|
|
|
|
props.config.getStore().forceUpdate();
|
2021-07-09 01:41:03 +08:00
|
|
|
|
}, 300);
|
|
|
|
|
return !pre;
|
|
|
|
|
} else {
|
2021-07-12 21:01:11 +08:00
|
|
|
|
props.config.collapsed = true;
|
2021-07-09 01:41:03 +08:00
|
|
|
|
setRenderCollaspe(true);
|
2021-07-12 21:01:11 +08:00
|
|
|
|
props.config.getStore().forceUpdate();
|
2021-07-09 01:41:03 +08:00
|
|
|
|
return !pre;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
className={styles.menu_footer}
|
|
|
|
|
icon={isCollapse ? <DoubleRightOutlined /> : <DoubleLeftOutlined />}
|
|
|
|
|
></Menu.Item>
|
|
|
|
|
</Menu>
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
className={`${styles.yhLeftrender} ant-menu scrollbar`}
|
|
|
|
|
style={{
|
|
|
|
|
width: isCollapse ? 0 : 270,
|
|
|
|
|
paddingRight: isCollapse ? 0 : 7, // 这个是滚动条宽度
|
|
|
|
|
overflowX: 'hidden',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{!renderCollapse && leftRender}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default LeftConfig;
|