@cloudbase/weda-ui 0.2.16 → 1.0.24

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.
Files changed (194) hide show
  1. package/README.md +41 -169
  2. package/package.json +23 -11
  3. package/src/configs/components/calendar.json +4 -1
  4. package/src/configs/components/chart/bar.json +724 -0
  5. package/src/configs/components/chart/line.json +679 -0
  6. package/src/configs/components/chart/pie.json +497 -0
  7. package/src/configs/components/chart/statisticsCard.json +61 -13
  8. package/src/configs/components/container.json +7 -2
  9. package/src/configs/components/dataView.json +21 -6
  10. package/src/configs/components/form/checkbox.json +97 -5
  11. package/src/configs/components/form/radio.json +96 -4
  12. package/src/configs/components/form/select.json +245 -11
  13. package/src/configs/components/graphicCard.json +84 -73
  14. package/src/configs/components/image.json +7 -2
  15. package/src/configs/components/link.json +19 -3
  16. package/src/configs/components/listView.json +65 -18
  17. package/src/configs/components/lottery.json +151 -0
  18. package/src/configs/components/modal.json +37 -5
  19. package/src/configs/components/navLayout.json +87 -75
  20. package/src/configs/components/navigationBar.json +59 -0
  21. package/src/configs/components/richtextview.json +4 -1
  22. package/src/configs/components/scrollVeiw.json +74 -22
  23. package/src/configs/components/swiper.json +4 -1
  24. package/src/configs/components/tabs.json +51 -8
  25. package/src/configs/components/text.json +33 -25
  26. package/src/configs/components/wxOpenApi/phone.json +141 -0
  27. package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
  28. package/src/configs/components/wxOpenApi/share.json +167 -0
  29. package/src/configs/components/wxOpenApi/userInfo.json +174 -0
  30. package/src/configs/index.js +20 -0
  31. package/src/index.js +2 -0
  32. package/src/mp/components/button/index.wxml +1 -2
  33. package/src/mp/components/chart/bar/index.js +258 -0
  34. package/src/mp/components/chart/bar/index.json +6 -0
  35. package/src/mp/components/chart/bar/index.wxml +3 -0
  36. package/src/mp/components/chart/bar/index.wxss +9 -0
  37. package/src/mp/components/chart/common/config/bar.js +50 -0
  38. package/src/mp/components/chart/common/config/global.js +16 -0
  39. package/src/mp/components/chart/common/config/line.js +48 -0
  40. package/src/mp/components/chart/common/config/pie.js +36 -0
  41. package/src/mp/components/chart/common/core/eChartBar.js +263 -0
  42. package/src/mp/components/chart/common/core/eChartBase.js +375 -0
  43. package/src/mp/components/chart/common/core/eChartLine.js +229 -0
  44. package/src/mp/components/chart/common/core/eChartPie.js +166 -0
  45. package/src/mp/components/chart/common/lib/echarts.min.js +18 -0
  46. package/src/mp/components/chart/ec-canvas/ec-canvas.js +277 -0
  47. package/src/mp/components/chart/ec-canvas/ec-canvas.json +4 -0
  48. package/src/mp/components/chart/ec-canvas/ec-canvas.wxml +4 -0
  49. package/src/mp/components/chart/ec-canvas/ec-canvas.wxss +4 -0
  50. package/src/mp/components/chart/ec-canvas/wx-canvas.js +107 -0
  51. package/src/mp/components/chart/line/index.js +247 -0
  52. package/src/mp/components/chart/line/index.json +6 -0
  53. package/src/mp/components/chart/line/index.wxml +3 -0
  54. package/src/mp/components/chart/line/index.wxss +9 -0
  55. package/src/mp/components/chart/pie/index.js +182 -0
  56. package/src/mp/components/chart/pie/index.json +6 -0
  57. package/src/mp/components/chart/pie/index.wxml +4 -0
  58. package/src/mp/components/chart/pie/index.wxss +9 -0
  59. package/src/mp/components/chart/statisticsCard/index.js +33 -6
  60. package/src/mp/components/form/checkbox/index.js +41 -2
  61. package/src/mp/components/form/checkbox/index.wxml +1 -1
  62. package/src/mp/components/form/form/index.wxml +1 -2
  63. package/src/mp/components/form/input/index.js +1 -1
  64. package/src/mp/components/form/location/index.js +43 -2
  65. package/src/mp/components/form/radio/index.js +38 -0
  66. package/src/mp/components/form/select/index.js +348 -40
  67. package/src/mp/components/form/select/index.wxml +21 -6
  68. package/src/mp/components/form/select/region/index.js +101 -0
  69. package/src/mp/components/form/textarea/index.wxml +6 -5
  70. package/src/mp/components/form/uploader/index.js +76 -44
  71. package/src/mp/components/form/uploader/index.wxml +15 -3
  72. package/src/mp/components/form/uploaderFile/index.js +61 -29
  73. package/src/mp/components/graphicCard/index.js +26 -28
  74. package/src/mp/components/listView/index.js +52 -64
  75. package/src/mp/components/listView/index.wxml +2 -2
  76. package/src/mp/components/listView/index.wxss +5 -0
  77. package/src/mp/components/lottery/index.js +270 -0
  78. package/src/mp/components/lottery/index.json +4 -0
  79. package/src/mp/components/lottery/index.wxml +43 -0
  80. package/src/mp/components/lottery/index.wxss +317 -0
  81. package/src/mp/components/navLayout/index.js +3 -3
  82. package/src/mp/components/navigationBar/index.js +193 -0
  83. package/src/mp/components/navigationBar/index.json +6 -0
  84. package/src/mp/components/navigationBar/index.wxml +88 -0
  85. package/src/mp/components/navigationBar/index.wxss +1257 -0
  86. package/src/mp/components/tabs/index.js +7 -2
  87. package/src/mp/components/tabs/index.wxml +2 -1
  88. package/src/mp/components/text/index.js +0 -25
  89. package/src/mp/components/text/index.wxml +3 -3
  90. package/src/mp/components/wxOpenApi/phone/index.js +117 -0
  91. package/src/mp/components/wxOpenApi/phone/index.json +4 -0
  92. package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
  93. package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
  94. package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
  95. package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
  96. package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
  97. package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
  98. package/src/mp/components/wxOpenApi/share/index.js +117 -0
  99. package/src/mp/components/wxOpenApi/share/index.json +4 -0
  100. package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
  101. package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
  102. package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
  103. package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
  104. package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
  105. package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
  106. package/src/mp/index.json +10 -1
  107. package/src/mp/style/weda-ui.wxss +2 -0
  108. package/src/mp/utils/constant.js +15 -0
  109. package/src/mp/utils/destr.js +48 -0
  110. package/src/mp/utils/lodash.js +2 -0
  111. package/src/mp/utils/platform.js +25 -0
  112. package/src/mp/utils/tcb.js +44 -0
  113. package/src/setupTests.js +2 -1
  114. package/src/web/components/button/index.css +8 -1
  115. package/src/web/components/button/index.tsx +3 -2
  116. package/src/web/components/chart/bar/index.tsx +140 -0
  117. package/src/web/components/chart/common/config/bar.js +49 -0
  118. package/src/web/components/chart/common/config/global.js +16 -0
  119. package/src/web/components/chart/common/config/line.js +50 -0
  120. package/src/web/components/chart/common/config/pie.js +37 -0
  121. package/src/web/components/chart/common/core/eChartBar.js +265 -0
  122. package/src/web/components/chart/common/core/eChartBase.ts +383 -0
  123. package/src/web/components/chart/common/core/eChartLine.js +231 -0
  124. package/src/web/components/chart/common/core/eChartPie.js +170 -0
  125. package/src/web/components/chart/common/core/type.ts +34 -0
  126. package/src/web/components/chart/common/echart.css +106 -0
  127. package/src/web/components/chart/common/echarts.ts +33 -0
  128. package/src/web/components/chart/common/useChart.tsx +69 -0
  129. package/src/web/components/chart/line/index.tsx +136 -0
  130. package/src/web/components/chart/pie/index.tsx +99 -0
  131. package/src/web/components/chart/statisticsCard/index.tsx +29 -8
  132. package/src/web/components/form/checkbox/index.tsx +61 -23
  133. package/src/web/components/form/formcell/index.tsx +10 -5
  134. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +3 -3
  135. package/src/web/components/form/location/components/LocationPC/location.PC.jsx +2 -2
  136. package/src/web/components/form/radio/index.tsx +90 -53
  137. package/src/web/components/form/select/h5.tsx +371 -72
  138. package/src/web/components/form/select/index.css +10 -0
  139. package/src/web/components/form/select/index.tsx +392 -145
  140. package/src/web/components/form/select/region/index.ts +122 -31
  141. package/src/web/components/form/select/time.jsx +90 -0
  142. package/src/web/components/form/select/year.tsx +170 -0
  143. package/src/web/components/form/tips/index.css +4 -0
  144. package/src/web/components/form/tips/index.tsx +4 -3
  145. package/src/web/components/form/uploader/uploader.h5.tsx +28 -19
  146. package/src/web/components/form/uploader/uploader.pc.tsx +17 -20
  147. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +48 -44
  148. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +28 -26
  149. package/src/web/components/graphicCard/index.css +1 -5
  150. package/src/web/components/graphicCard/index.tsx +4 -3
  151. package/src/web/components/image/image.tsx +1 -1
  152. package/src/web/components/image/index.tsx +1 -1
  153. package/src/web/components/index.js +13 -2
  154. package/src/web/components/link/index.tsx +6 -3
  155. package/src/web/components/listView/index.css +4 -0
  156. package/src/web/components/listView/index.tsx +10 -18
  157. package/src/web/components/lottery/index.css +327 -0
  158. package/src/web/components/lottery/index.tsx +567 -0
  159. package/src/web/components/lottery/lotteryUtil.ts +130 -0
  160. package/src/web/components/modal/index.tsx +3 -1
  161. package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
  162. package/src/web/components/navigationBar/common.tsx +198 -0
  163. package/src/web/components/navigationBar/h5Menu.tsx +179 -0
  164. package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
  165. package/src/web/components/navigationBar/index.css +762 -0
  166. package/src/web/components/navigationBar/index.tsx +231 -0
  167. package/src/web/components/navigationBar/type.d.ts +111 -0
  168. package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
  169. package/src/web/components/phone/index.css +0 -0
  170. package/src/web/components/phone/index.tsx +22 -0
  171. package/src/web/components/phoneCode/index.css +0 -0
  172. package/src/web/components/phoneCode/index.tsx +22 -0
  173. package/src/web/components/richTextView/index.tsx +3 -5
  174. package/src/web/components/share/index.css +0 -0
  175. package/src/web/components/share/index.tsx +38 -0
  176. package/src/web/components/tabs/index.tsx +2 -0
  177. package/src/web/components/tabs/tabs.h5.tsx +43 -33
  178. package/src/web/components/tabs/tabs.pc.tsx +23 -10
  179. package/src/web/components/text/index.tsx +6 -14
  180. package/src/web/components/userInfo/index.css +0 -0
  181. package/src/web/components/userInfo/index.tsx +30 -0
  182. package/src/web/utils/{constant.js → constant.ts} +17 -2
  183. package/src/web/utils/lodash.ts +2 -0
  184. package/src/web/utils/platform.js +10 -1
  185. package/src/web/utils/tcb.js +20 -6
  186. package/src/web/weda-ui.css +2 -0
  187. package/CHANGELOG.md +0 -240
  188. package/src/.DS_Store +0 -0
  189. package/src/configs/.DS_Store +0 -0
  190. package/src/mp/.gitignore +0 -10
  191. package/src/web/.DS_Store +0 -0
  192. package/src/web/components/form/select/region/cities.ts +0 -2410
  193. package/src/web/components/form/select/region/provinces.ts +0 -240
  194. 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;