@cloudbase/weda-ui 0.2.17 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/package.json +6 -3
- package/src/configs/components/calendar.json +4 -1
- package/src/configs/components/chart/bar.json +19 -6
- package/src/configs/components/chart/line.json +19 -6
- package/src/configs/components/chart/pie.json +14 -4
- package/src/configs/components/chart/statisticsCard.json +61 -13
- package/src/configs/components/container.json +7 -2
- package/src/configs/components/dataView.json +21 -6
- package/src/configs/components/form/checkbox.json +97 -5
- package/src/configs/components/form/radio.json +96 -4
- package/src/configs/components/form/select.json +245 -11
- package/src/configs/components/graphicCard.json +84 -73
- package/src/configs/components/image.json +7 -2
- package/src/configs/components/link.json +19 -3
- package/src/configs/components/listView.json +63 -17
- package/src/configs/components/modal.json +37 -5
- package/src/configs/components/navLayout.json +87 -75
- package/src/configs/components/navigationBar.json +59 -0
- package/src/configs/components/richtextview.json +4 -1
- package/src/configs/components/scrollVeiw.json +74 -22
- package/src/configs/components/swiper.json +4 -1
- package/src/configs/components/tabs.json +51 -8
- package/src/configs/components/text.json +33 -25
- package/src/configs/components/wxOpenApi/phone.json +141 -0
- package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
- package/src/configs/components/wxOpenApi/share.json +167 -0
- package/src/configs/components/wxOpenApi/userInfo.json +174 -0
- package/src/configs/index.js +11 -0
- package/src/mp/components/chart/bar/index.js +6 -2
- package/src/mp/components/chart/common/core/eChartBar.js +9 -8
- package/src/mp/components/chart/common/core/eChartBase.js +20 -16
- package/src/mp/components/chart/common/core/eChartLine.js +6 -5
- package/src/mp/components/chart/line/index.js +10 -6
- package/src/mp/components/chart/pie/index.js +6 -2
- package/src/mp/components/chart/statisticsCard/index.js +33 -6
- package/src/mp/components/dataView/index.json +1 -1
- package/src/mp/components/form/checkbox/index.js +41 -2
- package/src/mp/components/form/checkbox/index.wxml +1 -1
- package/src/mp/components/form/input/index.js +1 -1
- package/src/mp/components/form/location/index.js +43 -2
- package/src/mp/components/form/radio/index.js +34 -1
- package/src/mp/components/form/select/index.js +360 -40
- package/src/mp/components/form/select/index.wxml +17 -2
- package/src/mp/components/form/select/region/index.js +98 -0
- package/src/mp/components/form/uploader/index.js +39 -27
- package/src/mp/components/form/uploaderFile/index.js +10 -6
- package/src/mp/components/listView/index.js +33 -27
- package/src/mp/components/listView/index.wxml +1 -1
- package/src/mp/components/listView/index.wxss +5 -0
- package/src/mp/components/navigationBar/index.js +193 -0
- package/src/mp/components/navigationBar/index.json +6 -0
- package/src/mp/components/navigationBar/index.wxml +88 -0
- package/src/mp/components/navigationBar/index.wxss +1257 -0
- package/src/mp/components/tabs/index.js +7 -2
- package/src/mp/components/tabs/index.wxml +2 -1
- package/src/mp/components/text/index.js +0 -25
- package/src/mp/components/text/index.wxml +3 -3
- package/src/mp/components/wxOpenApi/phone/index.js +117 -0
- package/src/mp/components/{internals/listView → wxOpenApi/phone}/index.json +0 -0
- package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/share/index.js +117 -0
- package/src/mp/components/wxOpenApi/share/index.json +4 -0
- package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
- package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
- package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
- package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
- package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
- package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
- package/src/mp/index.json +7 -2
- package/src/mp/style/weda-ui.wxss +2 -0
- package/src/mp/utils/destr.js +48 -0
- package/src/mp/utils/platform.js +10 -0
- package/src/mp/utils/tcb.js +44 -0
- package/src/web/components/button/index.css +8 -1
- package/src/web/components/button/index.tsx +3 -2
- package/src/web/components/chart/bar/index.tsx +40 -39
- package/src/web/components/chart/common/core/eChartBar.js +7 -6
- package/src/web/components/chart/common/core/eChartBase.ts +20 -16
- package/src/web/components/chart/common/core/eChartLine.js +8 -6
- package/src/web/components/chart/line/index.tsx +40 -39
- package/src/web/components/chart/statisticsCard/index.tsx +29 -8
- package/src/web/components/form/checkbox/index.tsx +55 -23
- package/src/web/components/form/radio/index.tsx +84 -53
- package/src/web/components/form/select/h5.tsx +388 -72
- package/src/web/components/form/select/index.css +10 -0
- package/src/web/components/form/select/index.tsx +404 -144
- package/src/web/components/form/select/region/index.ts +122 -31
- package/src/web/components/form/select/time.jsx +89 -0
- package/src/web/components/form/select/year.tsx +170 -0
- package/src/web/components/form/uploader/uploader.h5.tsx +9 -2
- package/src/web/components/form/uploader/uploader.pc.tsx +4 -4
- package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +13 -7
- package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +13 -5
- package/src/web/components/image/image.tsx +1 -1
- package/src/web/components/image/index.tsx +1 -1
- package/src/web/components/index.js +7 -0
- package/src/web/components/link/index.tsx +6 -3
- package/src/web/components/listView/index.css +4 -0
- package/src/web/components/listView/index.tsx +6 -1
- package/src/web/components/modal/index.tsx +3 -1
- package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
- package/src/web/components/navigationBar/common.tsx +198 -0
- package/src/web/components/navigationBar/h5Menu.tsx +179 -0
- package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
- package/src/web/components/navigationBar/index.css +762 -0
- package/src/web/components/navigationBar/index.tsx +231 -0
- package/src/web/components/navigationBar/type.d.ts +111 -0
- package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
- package/src/web/components/phone/index.css +0 -0
- package/src/web/components/phone/index.tsx +22 -0
- package/src/web/components/phoneCode/index.css +0 -0
- package/src/web/components/phoneCode/index.tsx +22 -0
- package/src/web/components/richTextView/index.tsx +3 -5
- package/src/web/components/share/index.css +0 -0
- package/src/web/components/share/index.tsx +38 -0
- package/src/web/components/tabs/index.tsx +2 -0
- package/src/web/components/tabs/tabs.h5.tsx +43 -33
- package/src/web/components/tabs/tabs.pc.tsx +23 -10
- package/src/web/components/text/index.tsx +6 -14
- package/src/web/components/userInfo/index.css +0 -0
- package/src/web/components/userInfo/index.tsx +30 -0
- package/src/web/utils/platform.js +9 -0
- package/src/web/utils/tcb.js +26 -0
- package/src/web/weda-ui.css +2 -0
- package/src/mp/components/internals/listView/arrow-right-line.svg +0 -3
- package/src/mp/components/internals/listView/index.js +0 -286
- package/src/mp/components/internals/listView/index.wxml +0 -40
- package/src/mp/components/internals/listView/index.wxss +0 -150
- package/src/mp/components/internals/listView/more-line.svg +0 -3
- package/src/web/components/form/select/region/cities.ts +0 -2410
- package/src/web/components/form/select/region/provinces.ts +0 -240
- package/src/web/components/form/select/region/regions.ts +0 -20645
|
@@ -10,7 +10,7 @@ export interface PropTypes extends ModalProps {
|
|
|
10
10
|
isDefaultButton: boolean,
|
|
11
11
|
emit?: unknownFunction,
|
|
12
12
|
events: Record<string, unknownFunction>,
|
|
13
|
-
|
|
13
|
+
size: ModalProps['size'],
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export default function WeDaModal(_props: PropTypes) {
|
|
@@ -22,6 +22,7 @@ export default function WeDaModal(_props: PropTypes) {
|
|
|
22
22
|
customContent,
|
|
23
23
|
isDefaultButton,
|
|
24
24
|
emit,
|
|
25
|
+
size,
|
|
25
26
|
events,
|
|
26
27
|
...props
|
|
27
28
|
} = _props;
|
|
@@ -29,6 +30,7 @@ export default function WeDaModal(_props: PropTypes) {
|
|
|
29
30
|
return (
|
|
30
31
|
<ConfigProvider classPrefix="wedatea2td">
|
|
31
32
|
<Modal
|
|
33
|
+
size={size}
|
|
32
34
|
className={classNames('weda-ui', 'lcap-modal', 'container', className)}
|
|
33
35
|
visible={visible}
|
|
34
36
|
onClose={() => {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M2.95898 11.5405L3.87822 12.4597L8.33784 8.0001L3.87822 3.54048L2.95898 4.45972L6.49936 8.0001L2.95898 11.5405ZM7.95892 11.5405L8.87815 12.4597L13.3378 8.0001L8.87815 3.54048L7.95892 4.45972L11.4993 8.0001L7.95892 11.5405Z" fill="black" fill-opacity="0.26"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IMenuItem, INavigationStyle } from './type';
|
|
3
|
+
import { isUrl } from '../../utils/platform';
|
|
4
|
+
import { IconFont } from 'tdesign-icons-react';
|
|
5
|
+
const CLASS_PREFIX = 'weda-menu';
|
|
6
|
+
|
|
7
|
+
// 标题
|
|
8
|
+
export const renderTitle = (navigationStyle: INavigationStyle) => {
|
|
9
|
+
const { title, titleColor, showTitle, titleFontSize } = navigationStyle;
|
|
10
|
+
return (
|
|
11
|
+
showTitle && (
|
|
12
|
+
<span
|
|
13
|
+
data-testid="navigationBar-title"
|
|
14
|
+
style={{
|
|
15
|
+
display: 'inline-block',
|
|
16
|
+
color: titleColor,
|
|
17
|
+
fontSize: titleFontSize,
|
|
18
|
+
}}
|
|
19
|
+
>
|
|
20
|
+
{title}
|
|
21
|
+
</span>
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// 菜单
|
|
27
|
+
export const renderMenuTitle = (
|
|
28
|
+
navigationStyle: INavigationStyle,
|
|
29
|
+
item: Partial<IMenuItem>,
|
|
30
|
+
hasIcon: boolean
|
|
31
|
+
) => {
|
|
32
|
+
const { menuColor, menuFontSize, showMenuIcon } = navigationStyle;
|
|
33
|
+
const { title, level, iconUrl } = item;
|
|
34
|
+
return (
|
|
35
|
+
<span
|
|
36
|
+
className="menu-text"
|
|
37
|
+
style={{
|
|
38
|
+
color: menuColor,
|
|
39
|
+
fontSize: menuFontSize,
|
|
40
|
+
}}
|
|
41
|
+
data-testid="navigationBar-menu"
|
|
42
|
+
>
|
|
43
|
+
{showMenuIcon &&
|
|
44
|
+
level === 0 &&
|
|
45
|
+
hasIcon &&
|
|
46
|
+
renderMenuIcon(iconUrl, navigationStyle)}
|
|
47
|
+
{title}
|
|
48
|
+
</span>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
// 默认logo
|
|
52
|
+
const defaultLogoUrl =
|
|
53
|
+
'https://imgcache.qq.com/qcloud/tcloud_dtc/static/static_source_business/43d3b2b7-445c-4858-8eb0-50ac5d5cc08e.svg';
|
|
54
|
+
|
|
55
|
+
// logo
|
|
56
|
+
export const renderLogo = (
|
|
57
|
+
navigationStyle: INavigationStyle,
|
|
58
|
+
className: string
|
|
59
|
+
) => {
|
|
60
|
+
const { showLogo, logoHeight, logoWidth, logoUrl } = navigationStyle;
|
|
61
|
+
return (
|
|
62
|
+
showLogo && (
|
|
63
|
+
<img
|
|
64
|
+
data-testid="navigationBar-logo"
|
|
65
|
+
className={className}
|
|
66
|
+
style={{ width: `${logoWidth}px`, height: `${logoHeight}px` }}
|
|
67
|
+
src={logoUrl || defaultLogoUrl}
|
|
68
|
+
alt="logo"
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// icon回显
|
|
75
|
+
export const IconShow = ({ onIcon, menuColor, menuFontSize }) => {
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
{onIcon?.includes('td:') ? (
|
|
79
|
+
<IconFont
|
|
80
|
+
name={onIcon?.split(':')[1]}
|
|
81
|
+
className={`${CLASS_PREFIX}__fonticon`}
|
|
82
|
+
style={{ color: menuColor, fontSize: menuFontSize }}
|
|
83
|
+
/>
|
|
84
|
+
) : (
|
|
85
|
+
<div
|
|
86
|
+
className={`${CLASS_PREFIX}__fonticon lcap-icon lcap-icon-${onIcon}`}
|
|
87
|
+
style={{ color: menuColor, fontSize: menuFontSize }}
|
|
88
|
+
></div>
|
|
89
|
+
)}
|
|
90
|
+
</>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
// 菜单图标
|
|
94
|
+
export const renderMenuIcon = (
|
|
95
|
+
iconUrl: string,
|
|
96
|
+
navigationStyle: INavigationStyle
|
|
97
|
+
) => {
|
|
98
|
+
const { menuColor, menuFontSize } = navigationStyle;
|
|
99
|
+
let icon = iconUrl || 'td:view-module';
|
|
100
|
+
if (iconUrl && isUrl(iconUrl)) {
|
|
101
|
+
return (
|
|
102
|
+
<img
|
|
103
|
+
className={`${CLASS_PREFIX}__item-icon`}
|
|
104
|
+
style={{ width: 16, height: 16, marginRight: 4 }}
|
|
105
|
+
src={icon}
|
|
106
|
+
alt="logo"
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
} else {
|
|
110
|
+
return (
|
|
111
|
+
<IconShow
|
|
112
|
+
onIcon={icon}
|
|
113
|
+
menuColor={menuColor}
|
|
114
|
+
menuFontSize={menuFontSize}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// 页面跳转
|
|
121
|
+
export const navigateTo = (menu: IMenuItem) => {
|
|
122
|
+
const { path, linkTargetBlank, linkUrl, type, key } = menu;
|
|
123
|
+
localStorage.setItem('selectedKey', key);
|
|
124
|
+
// 存储跳转页面的id
|
|
125
|
+
if (linkUrl && type === 'link') {
|
|
126
|
+
if (linkTargetBlank) {
|
|
127
|
+
window.open(linkUrl);
|
|
128
|
+
} else {
|
|
129
|
+
window.location.href = linkUrl;
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
app.navigateTo({
|
|
133
|
+
pageId: path?.replace('/', ''),
|
|
134
|
+
packageName: '',
|
|
135
|
+
mode: 'weDa',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
// 菜单是否展开
|
|
140
|
+
export const hasSelectedMenu = (menu: IMenuItem, selectedkey: string) => {
|
|
141
|
+
let opened = false;
|
|
142
|
+
if (menu.key === selectedkey) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
menu?.children?.forEach((i) => {
|
|
146
|
+
if (i.key === selectedkey) {
|
|
147
|
+
opened = true;
|
|
148
|
+
}
|
|
149
|
+
if (i?.children?.length) {
|
|
150
|
+
opened = hasSelectedMenu(i, selectedkey);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return opened;
|
|
154
|
+
};
|
|
155
|
+
// 点击展开/收起菜单
|
|
156
|
+
export const expandMenu = (
|
|
157
|
+
menuData: IMenuItem[],
|
|
158
|
+
menuItem: Partial<IMenuItem>,
|
|
159
|
+
init = false
|
|
160
|
+
) => {
|
|
161
|
+
let menus = JSON.parse(JSON.stringify(menuData));
|
|
162
|
+
return menus.map((i) => {
|
|
163
|
+
if (init) {
|
|
164
|
+
i.opened = hasSelectedMenu(i, menuItem.key);
|
|
165
|
+
} else if (i.key === menuItem.key) {
|
|
166
|
+
i.opened = menuItem.opened;
|
|
167
|
+
}
|
|
168
|
+
if (i.children) {
|
|
169
|
+
return { ...i, children: expandMenu(i?.children, menuItem, init) };
|
|
170
|
+
}
|
|
171
|
+
return i;
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// 根据path查找菜单
|
|
176
|
+
export const findMenuItemByPath = (
|
|
177
|
+
menus: IMenuItem[],
|
|
178
|
+
targetPath: string
|
|
179
|
+
): IMenuItem | null => {
|
|
180
|
+
const queue: IMenuItem[] = [];
|
|
181
|
+
let targetNode: IMenuItem | null = null;
|
|
182
|
+
menus.forEach((node) => queue.push(node));
|
|
183
|
+
|
|
184
|
+
while (queue.length) {
|
|
185
|
+
const node = queue.shift();
|
|
186
|
+
if (!node) return null;
|
|
187
|
+
|
|
188
|
+
if (node.path === targetPath) {
|
|
189
|
+
// 添加节点
|
|
190
|
+
targetNode = node;
|
|
191
|
+
break;
|
|
192
|
+
} else {
|
|
193
|
+
node.children?.forEach((node) => queue.push(node));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return targetNode;
|
|
198
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/* eslint-disable react/jsx-key */
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { Menu, Drawer } from 'tea-component';
|
|
4
|
+
import { IMenuItem, INavigationStyle } from './type';
|
|
5
|
+
import classNames from '../../utils/classnames';
|
|
6
|
+
import {
|
|
7
|
+
renderMenuTitle,
|
|
8
|
+
renderLogo,
|
|
9
|
+
renderTitle,
|
|
10
|
+
navigateTo,
|
|
11
|
+
expandMenu,
|
|
12
|
+
} from './common';
|
|
13
|
+
const CLASS_PREFIX = 'weda-menu';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 移动端导航
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const H5Menu: React.FC<{
|
|
20
|
+
menuData: IMenuItem[];
|
|
21
|
+
navigationStyle: INavigationStyle;
|
|
22
|
+
setMenuData: (menus: IMenuItem[]) => void;
|
|
23
|
+
className: string;
|
|
24
|
+
selected: string;
|
|
25
|
+
setSelected: (selectedKey: string) => void;
|
|
26
|
+
}> = ({
|
|
27
|
+
menuData,
|
|
28
|
+
navigationStyle,
|
|
29
|
+
setMenuData,
|
|
30
|
+
className,
|
|
31
|
+
selected,
|
|
32
|
+
setSelected,
|
|
33
|
+
}) => {
|
|
34
|
+
// 平台
|
|
35
|
+
const cls = classNames({
|
|
36
|
+
[CLASS_PREFIX]: true,
|
|
37
|
+
[className]: className,
|
|
38
|
+
[`${CLASS_PREFIX}-mobile`]: true,
|
|
39
|
+
});
|
|
40
|
+
// h5 弹框
|
|
41
|
+
const [visible, setVisible] = useState<boolean>(false);
|
|
42
|
+
// 菜单背景色
|
|
43
|
+
const menuStyle: React.CSSProperties = {
|
|
44
|
+
background: navigationStyle.menuBackgroundColor || '#fff',
|
|
45
|
+
};
|
|
46
|
+
// 渲染subMenu
|
|
47
|
+
const renderSubMenu = (item: IMenuItem, hasThereNode = false) => {
|
|
48
|
+
const { key, children, opened } = item;
|
|
49
|
+
return children.length > 0 ? (
|
|
50
|
+
<Menu.SubMenu
|
|
51
|
+
className={hasThereNode ? `${CLASS_PREFIX}__submenu` : ''}
|
|
52
|
+
key={key}
|
|
53
|
+
title={renderMenuTitle(navigationStyle, item, true)}
|
|
54
|
+
opened={opened}
|
|
55
|
+
onOpenedChange={(opened) => {
|
|
56
|
+
const menus = expandMenu(menuData, { ...item, opened });
|
|
57
|
+
setMenuData(menus);
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
{children?.map((el: any) => renderSubMenu(el, true))}
|
|
61
|
+
</Menu.SubMenu>
|
|
62
|
+
) : (
|
|
63
|
+
renderMenuItem(item)
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
// 渲染MenuItem
|
|
67
|
+
const renderMenuItem = (item: IMenuItem) => {
|
|
68
|
+
const { key } = item;
|
|
69
|
+
return (
|
|
70
|
+
<Menu.Item
|
|
71
|
+
key={key}
|
|
72
|
+
title={renderMenuTitle(navigationStyle, item, true)}
|
|
73
|
+
selected={item.key === selected}
|
|
74
|
+
onClick={() => {
|
|
75
|
+
if (item.key !== selected) {
|
|
76
|
+
setSelected(item.key);
|
|
77
|
+
navigateTo(item);
|
|
78
|
+
}
|
|
79
|
+
setVisible(false);
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
const renderH5Title = (navigationStyle: INavigationStyle) => (
|
|
85
|
+
<>
|
|
86
|
+
<div className={`${CLASS_PREFIX}__bar-main`}>
|
|
87
|
+
<span className={`${CLASS_PREFIX}__main-logo`}>
|
|
88
|
+
{renderLogo(navigationStyle, `${CLASS_PREFIX}__main-icon`)}
|
|
89
|
+
{renderTitle(navigationStyle)}
|
|
90
|
+
</span>
|
|
91
|
+
</div>
|
|
92
|
+
<div className={`${CLASS_PREFIX}__bar-extra`}>
|
|
93
|
+
{!visible && (
|
|
94
|
+
<i
|
|
95
|
+
className={`${CLASS_PREFIX}__bar-btn`}
|
|
96
|
+
onClick={() => setVisible(true)}
|
|
97
|
+
>
|
|
98
|
+
<svg
|
|
99
|
+
width="24"
|
|
100
|
+
height="24"
|
|
101
|
+
viewBox="0 0 24 24"
|
|
102
|
+
fill="none"
|
|
103
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
104
|
+
>
|
|
105
|
+
<path
|
|
106
|
+
d="M3 4H21V6H3V4ZM3 11H21V13H3V11ZM3 18H21V20H3V18Z"
|
|
107
|
+
fill={navigationStyle.titleColor}
|
|
108
|
+
fillOpacity="0.9"
|
|
109
|
+
/>
|
|
110
|
+
</svg>
|
|
111
|
+
</i>
|
|
112
|
+
)}
|
|
113
|
+
{visible && (
|
|
114
|
+
<i
|
|
115
|
+
className={`${CLASS_PREFIX}__bar-btn--close`}
|
|
116
|
+
onClick={() => setVisible(false)}
|
|
117
|
+
>
|
|
118
|
+
<svg
|
|
119
|
+
width="24"
|
|
120
|
+
height="24"
|
|
121
|
+
viewBox="0 0 24 24"
|
|
122
|
+
fill="none"
|
|
123
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
124
|
+
>
|
|
125
|
+
<path
|
|
126
|
+
fillRule="evenodd"
|
|
127
|
+
clipRule="evenodd"
|
|
128
|
+
d="M10.6219 11.9998L3.88672 5.2646L5.26558 3.88574L12.0008 10.6209L18.736 3.88574L20.1148 5.2646L13.3796 11.9998L20.1148 18.735L18.736 20.1138L12.0008 13.3786L5.26558 20.1138L3.88672 18.735L10.6219 11.9998Z"
|
|
129
|
+
fill={navigationStyle.titleColor}
|
|
130
|
+
fillOpacity="0.9"
|
|
131
|
+
/>
|
|
132
|
+
</svg>
|
|
133
|
+
</i>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
</>
|
|
137
|
+
);
|
|
138
|
+
return (
|
|
139
|
+
<>
|
|
140
|
+
{renderH5Title(navigationStyle)}
|
|
141
|
+
<Drawer
|
|
142
|
+
size={'m'}
|
|
143
|
+
placement={'left'}
|
|
144
|
+
disableAnimation={true}
|
|
145
|
+
outerClickClosable={false}
|
|
146
|
+
visible={visible}
|
|
147
|
+
onClose={() => setVisible(false)}
|
|
148
|
+
className={`${CLASS_PREFIX}__drawer`}
|
|
149
|
+
>
|
|
150
|
+
<div
|
|
151
|
+
className={cls}
|
|
152
|
+
style={{
|
|
153
|
+
display: 'flex',
|
|
154
|
+
flexDirection: 'column',
|
|
155
|
+
position: 'relative',
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
<div
|
|
159
|
+
className={`${CLASS_PREFIX}__wrapper`}
|
|
160
|
+
style={{
|
|
161
|
+
background: navigationStyle?.menuBackgroundColor || '#fff',
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{renderH5Title(navigationStyle)}
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
167
|
+
<Menu className={`${CLASS_PREFIX}__drawer-menu`} style={menuStyle}>
|
|
168
|
+
{menuData?.map((item: any) => {
|
|
169
|
+
return item?.children?.length > 0
|
|
170
|
+
? renderSubMenu(item)
|
|
171
|
+
: renderMenuItem(item);
|
|
172
|
+
})}
|
|
173
|
+
</Menu>
|
|
174
|
+
</Drawer>
|
|
175
|
+
</>
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export default H5Menu;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/* eslint-disable react/jsx-key */
|
|
2
|
+
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
import { NavMenu, List, Dropdown } from 'tea-component';
|
|
4
|
+
import { IMenuItem, INavigationStyle } from './type';
|
|
5
|
+
import { usePlatform } from '../../utils/platform';
|
|
6
|
+
import classNames from '../../utils/classnames';
|
|
7
|
+
import {
|
|
8
|
+
renderMenuTitle,
|
|
9
|
+
renderMenuIcon,
|
|
10
|
+
renderLogo,
|
|
11
|
+
renderTitle,
|
|
12
|
+
navigateTo,
|
|
13
|
+
} from './common';
|
|
14
|
+
const CLASS_PREFIX = 'weda-menu';
|
|
15
|
+
/**
|
|
16
|
+
* pc端横向导航
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const HorizontalMenu: React.FC<{
|
|
20
|
+
menuData: IMenuItem[];
|
|
21
|
+
navigationStyle: INavigationStyle;
|
|
22
|
+
selected: string;
|
|
23
|
+
setSelected: (selectedKey: string) => void;
|
|
24
|
+
}> = ({ menuData, navigationStyle, selected, setSelected }) => {
|
|
25
|
+
// 导航样式
|
|
26
|
+
const { isHorizontal = false, showMenuIcon } = navigationStyle;
|
|
27
|
+
// 菜单背景色
|
|
28
|
+
const menuStyle: React.CSSProperties = {
|
|
29
|
+
background: navigationStyle.menuBackgroundColor || '#fff',
|
|
30
|
+
};
|
|
31
|
+
// 平台
|
|
32
|
+
const platform = usePlatform();
|
|
33
|
+
// 横向导航, 判断是否出现右侧的滚动按钮
|
|
34
|
+
const [showButton, setShowButton] = useState<boolean>(true);
|
|
35
|
+
// 横行导航移动
|
|
36
|
+
const [position, setPosition] = useState({ index: 0, offset: 0 });
|
|
37
|
+
const [menuOffset, setMenuOffset] = useState({});
|
|
38
|
+
const navWrapRef = useRef<HTMLDivElement>();
|
|
39
|
+
|
|
40
|
+
const getMenuOffset = useCallback(() => {
|
|
41
|
+
const parentWidth = navWrapRef?.current?.parentElement?.clientWidth;
|
|
42
|
+
const contentWidth = navWrapRef?.current?.clientWidth;
|
|
43
|
+
const menuItem = navWrapRef?.current?.children;
|
|
44
|
+
let data = { 0: 0, 1: 0 };
|
|
45
|
+
let index = 1;
|
|
46
|
+
for (let i of menuItem) {
|
|
47
|
+
if (data[index] + i?.clientWidth + 8 > parentWidth) {
|
|
48
|
+
index = index + 1;
|
|
49
|
+
data[index] = i?.clientWidth + 8;
|
|
50
|
+
} else {
|
|
51
|
+
data[index] += i?.clientWidth + 8;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
setMenuOffset(data);
|
|
55
|
+
const showButton = contentWidth > parentWidth;
|
|
56
|
+
setShowButton(showButton);
|
|
57
|
+
}, [navWrapRef]);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (platform !== 'h5' && isHorizontal && navWrapRef?.current?.children) {
|
|
61
|
+
getMenuOffset();
|
|
62
|
+
}
|
|
63
|
+
}, [platform, isHorizontal, navWrapRef]);
|
|
64
|
+
|
|
65
|
+
// 渲染下拉菜单
|
|
66
|
+
const renderMenuList = (
|
|
67
|
+
item: IMenuItem[],
|
|
68
|
+
navigationStyle: INavigationStyle
|
|
69
|
+
) => {
|
|
70
|
+
return (
|
|
71
|
+
<List
|
|
72
|
+
type="option"
|
|
73
|
+
className={`${CLASS_PREFIX}__dropdown-menu-list`}
|
|
74
|
+
style={{ background: navigationStyle.menuBackgroundColor }}
|
|
75
|
+
>
|
|
76
|
+
{item?.map((menu) => {
|
|
77
|
+
const { title, children, key } = menu;
|
|
78
|
+
return !children?.length ? (
|
|
79
|
+
<List.Item
|
|
80
|
+
key={key}
|
|
81
|
+
className={`${CLASS_PREFIX}__dropdown-list-item`}
|
|
82
|
+
selected={key === selected}
|
|
83
|
+
onClick={() => {
|
|
84
|
+
if (key !== selected) {
|
|
85
|
+
setSelected(key);
|
|
86
|
+
navigateTo(menu);
|
|
87
|
+
}
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{renderMenuTitle(navigationStyle, { title }, false)}
|
|
91
|
+
</List.Item>
|
|
92
|
+
) : (
|
|
93
|
+
<List.SubMenu
|
|
94
|
+
key={key}
|
|
95
|
+
className={`${CLASS_PREFIX}__dropdown-list-item`}
|
|
96
|
+
label={renderMenuTitle(navigationStyle, { title }, false)}
|
|
97
|
+
>
|
|
98
|
+
{renderMenuList(children, navigationStyle)}
|
|
99
|
+
</List.SubMenu>
|
|
100
|
+
);
|
|
101
|
+
})}
|
|
102
|
+
</List>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<NavMenu
|
|
108
|
+
style={menuStyle}
|
|
109
|
+
className={`${CLASS_PREFIX}__nav`}
|
|
110
|
+
left={
|
|
111
|
+
<>
|
|
112
|
+
<NavMenu.Item type="logo" className={`${CLASS_PREFIX}__nav-logo`}>
|
|
113
|
+
{renderLogo(navigationStyle, `${CLASS_PREFIX}__nav-logo--img`)}
|
|
114
|
+
</NavMenu.Item>
|
|
115
|
+
|
|
116
|
+
<NavMenu.Item className={`${CLASS_PREFIX}__nav-title`}>
|
|
117
|
+
<span className={`${CLASS_PREFIX}__title`}>
|
|
118
|
+
{renderTitle(navigationStyle)}
|
|
119
|
+
</span>
|
|
120
|
+
</NavMenu.Item>
|
|
121
|
+
</>
|
|
122
|
+
}
|
|
123
|
+
right={
|
|
124
|
+
<div className={`${CLASS_PREFIX}__nav-wrap`}>
|
|
125
|
+
{showButton && position.index > 0 && (
|
|
126
|
+
<div
|
|
127
|
+
className={`${CLASS_PREFIX}__nav-shadow leftButton`}
|
|
128
|
+
onClick={() => {
|
|
129
|
+
const result = position.offset + menuOffset[position.index];
|
|
130
|
+
setPosition({ index: position.index - 1, offset: result });
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<div className={`${CLASS_PREFIX}__shadow--icon`}></div>
|
|
134
|
+
<div className={`${CLASS_PREFIX}__shadow`}></div>
|
|
135
|
+
<div className={`${CLASS_PREFIX}__shadow--white`}></div>
|
|
136
|
+
</div>
|
|
137
|
+
)}
|
|
138
|
+
<div className={`${CLASS_PREFIX}__nav-content box`}>
|
|
139
|
+
<div
|
|
140
|
+
ref={navWrapRef}
|
|
141
|
+
className={`${CLASS_PREFIX}__nav-content`}
|
|
142
|
+
style={{ transform: `translate(${position.offset}px, 0px)` }}
|
|
143
|
+
>
|
|
144
|
+
{menuData?.map((i) => (
|
|
145
|
+
<div
|
|
146
|
+
className={classNames(
|
|
147
|
+
`${CLASS_PREFIX}__nav-item`,
|
|
148
|
+
i.key === selected && i.level === 0
|
|
149
|
+
? `${CLASS_PREFIX}__item-open`
|
|
150
|
+
: ''
|
|
151
|
+
)}
|
|
152
|
+
key={i.key}
|
|
153
|
+
onClick={() => {
|
|
154
|
+
if (!i?.children?.length && i.key !== selected) {
|
|
155
|
+
setSelected(i.key);
|
|
156
|
+
navigateTo(i);
|
|
157
|
+
}
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
{showMenuIcon && renderMenuIcon(i?.iconUrl, navigationStyle)}
|
|
161
|
+
{i?.children?.length ? (
|
|
162
|
+
<Dropdown
|
|
163
|
+
trigger={'hover'}
|
|
164
|
+
overlayClassName={`${CLASS_PREFIX}__dropdown`}
|
|
165
|
+
button={renderMenuTitle(navigationStyle, i, false)}
|
|
166
|
+
>
|
|
167
|
+
{renderMenuList(i.children, navigationStyle)}
|
|
168
|
+
</Dropdown>
|
|
169
|
+
) : (
|
|
170
|
+
<NavMenu.Item
|
|
171
|
+
className={`${CLASS_PREFIX}__item-val`}
|
|
172
|
+
selected={i.key === selected}
|
|
173
|
+
>
|
|
174
|
+
{renderMenuTitle(navigationStyle, i, false)}
|
|
175
|
+
</NavMenu.Item>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
))}
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
{showButton && position.index + 2 < Object.keys(menuOffset).length && (
|
|
182
|
+
<div
|
|
183
|
+
className={`${CLASS_PREFIX}__nav-shadow`}
|
|
184
|
+
onClick={() => {
|
|
185
|
+
const result = position.offset - menuOffset[position.index + 1];
|
|
186
|
+
setPosition({ index: position.index + 1, offset: result });
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
<div className={`${CLASS_PREFIX}__shadow`}></div>
|
|
190
|
+
<div className={`${CLASS_PREFIX}__shadow--white`}></div>
|
|
191
|
+
<div className={`${CLASS_PREFIX}__shadow--icon`}></div>
|
|
192
|
+
</div>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export default HorizontalMenu;
|