@cloudbase/weda-ui 0.2.15 → 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.
Files changed (250) hide show
  1. package/README.md +41 -169
  2. package/package.json +28 -15
  3. package/src/configs/components/calendar.json +78 -0
  4. package/src/configs/components/carousel.json +273 -0
  5. package/src/configs/components/chart/bar.json +724 -0
  6. package/src/configs/components/chart/line.json +679 -0
  7. package/src/configs/components/chart/pie.json +497 -0
  8. package/src/configs/components/chart/statisticsCard.json +379 -0
  9. package/src/configs/components/container.json +7 -2
  10. package/src/configs/components/dataView.json +154 -0
  11. package/src/configs/components/form/checkbox.json +97 -5
  12. package/src/configs/components/form/location.json +152 -0
  13. package/src/configs/components/form/radio.json +96 -4
  14. package/src/configs/components/form/select.json +245 -11
  15. package/src/configs/components/form/uploaderFile.json +2 -1
  16. package/src/configs/components/graphicCard.json +410 -0
  17. package/src/configs/components/image.json +7 -2
  18. package/src/configs/components/link.json +20 -4
  19. package/src/configs/components/listView.json +277 -0
  20. package/src/configs/components/modal.json +37 -5
  21. package/src/configs/components/navLayout.json +362 -0
  22. package/src/configs/components/navigationBar.json +59 -0
  23. package/src/configs/components/richtextview.json +4 -1
  24. package/src/configs/components/scrollVeiw.json +74 -22
  25. package/src/configs/components/swiper.json +6 -3
  26. package/src/configs/components/tabs.json +51 -8
  27. package/src/configs/components/text.json +33 -25
  28. package/src/configs/components/wxOpenApi/phone.json +141 -0
  29. package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
  30. package/src/configs/components/wxOpenApi/share.json +167 -0
  31. package/src/configs/components/wxOpenApi/userInfo.json +174 -0
  32. package/src/configs/index.js +34 -0
  33. package/src/mp/components/button/index.js +12 -13
  34. package/src/mp/components/button/index.wxml +1 -1
  35. package/src/mp/components/calendar/arrowright--line.svg +11 -0
  36. package/src/mp/components/calendar/index.js +238 -0
  37. package/src/mp/components/calendar/index.json +4 -0
  38. package/src/mp/components/calendar/index.wxml +37 -0
  39. package/src/mp/components/calendar/index.wxss +178 -0
  40. package/src/mp/components/carousel/index.js +88 -0
  41. package/src/mp/components/carousel/index.json +7 -0
  42. package/src/mp/components/carousel/index.wxml +6 -0
  43. package/src/mp/components/chart/bar/index.js +258 -0
  44. package/src/mp/components/chart/bar/index.json +6 -0
  45. package/src/mp/components/chart/bar/index.wxml +3 -0
  46. package/src/mp/components/chart/bar/index.wxss +9 -0
  47. package/src/mp/components/chart/common/config/bar.js +50 -0
  48. package/src/mp/components/chart/common/config/global.js +16 -0
  49. package/src/mp/components/chart/common/config/line.js +48 -0
  50. package/src/mp/components/chart/common/config/pie.js +36 -0
  51. package/src/mp/components/chart/common/core/eChartBar.js +263 -0
  52. package/src/mp/components/chart/common/core/eChartBase.js +375 -0
  53. package/src/mp/components/chart/common/core/eChartLine.js +229 -0
  54. package/src/mp/components/chart/common/core/eChartPie.js +166 -0
  55. package/src/mp/components/chart/common/lib/echarts.min.js +18 -0
  56. package/src/mp/components/chart/ec-canvas/ec-canvas.js +277 -0
  57. package/src/mp/components/chart/ec-canvas/ec-canvas.json +4 -0
  58. package/src/mp/components/chart/ec-canvas/ec-canvas.wxml +4 -0
  59. package/src/mp/components/chart/ec-canvas/ec-canvas.wxss +4 -0
  60. package/src/mp/components/chart/ec-canvas/wx-canvas.js +107 -0
  61. package/src/mp/components/chart/line/index.js +247 -0
  62. package/src/mp/components/chart/line/index.json +6 -0
  63. package/src/mp/components/chart/line/index.wxml +3 -0
  64. package/src/mp/components/chart/line/index.wxss +9 -0
  65. package/src/mp/components/chart/pie/index.js +182 -0
  66. package/src/mp/components/chart/pie/index.json +6 -0
  67. package/src/mp/components/chart/pie/index.wxml +4 -0
  68. package/src/mp/components/chart/pie/index.wxss +9 -0
  69. package/src/mp/components/chart/statisticsCard/index.js +253 -0
  70. package/src/mp/components/chart/statisticsCard/index.json +4 -0
  71. package/src/mp/components/chart/statisticsCard/index.wxml +9 -0
  72. package/src/mp/components/chart/statisticsCard/index.wxss +45 -0
  73. package/src/mp/components/dataView/index.js +34 -0
  74. package/src/mp/components/dataView/index.json +7 -0
  75. package/src/mp/components/dataView/index.wxml +15 -0
  76. package/src/mp/components/dataView/index.wxss +0 -0
  77. package/src/mp/components/form/checkbox/index.js +41 -2
  78. package/src/mp/components/form/checkbox/index.wxml +1 -1
  79. package/src/mp/components/form/input/index.js +1 -1
  80. package/src/mp/components/form/location/components/mapChoose/index.js +201 -0
  81. package/src/mp/components/form/location/components/mapChoose/index.json +4 -0
  82. package/src/mp/components/form/location/components/mapChoose/index.wxml +42 -0
  83. package/src/mp/components/form/location/components/mapChoose/index.wxss +188 -0
  84. package/src/mp/components/form/location/index.js +382 -0
  85. package/src/mp/components/form/location/index.json +6 -0
  86. package/src/mp/components/form/location/index.wxml +25 -0
  87. package/src/mp/components/form/location/index.wxss +91 -0
  88. package/src/mp/components/form/radio/index.js +38 -0
  89. package/src/mp/components/form/select/index.js +360 -40
  90. package/src/mp/components/form/select/index.wxml +21 -6
  91. package/src/mp/components/form/select/region/index.js +98 -0
  92. package/src/mp/components/form/textarea/index.wxml +6 -5
  93. package/src/mp/components/form/uploader/index.js +84 -48
  94. package/src/mp/components/form/uploader/index.wxml +15 -3
  95. package/src/mp/components/form/uploaderFile/index.js +106 -27
  96. package/src/mp/components/graphicCard/chevron-right.svg +3 -0
  97. package/src/mp/components/graphicCard/index.js +203 -0
  98. package/src/mp/components/graphicCard/index.json +4 -0
  99. package/src/mp/components/graphicCard/index.wxml +29 -0
  100. package/src/mp/components/graphicCard/index.wxss +157 -0
  101. package/src/mp/components/image/index.js +0 -1
  102. package/src/mp/components/listView/arrow-right-line.svg +3 -0
  103. package/src/mp/components/listView/index.js +285 -0
  104. package/src/mp/components/listView/index.json +4 -0
  105. package/src/mp/components/listView/index.wxml +40 -0
  106. package/src/mp/components/listView/index.wxss +155 -0
  107. package/src/mp/components/listView/more-line.svg +3 -0
  108. package/src/mp/components/navLayout/index.js +123 -0
  109. package/src/mp/components/navLayout/index.json +7 -0
  110. package/src/mp/components/navLayout/index.wxml +25 -0
  111. package/src/mp/components/navLayout/index.wxss +1193 -0
  112. package/src/mp/components/navigationBar/index.js +193 -0
  113. package/src/mp/components/navigationBar/index.json +6 -0
  114. package/src/mp/components/navigationBar/index.wxml +88 -0
  115. package/src/mp/components/navigationBar/index.wxss +1257 -0
  116. package/src/mp/components/swiper/index.wxml +2 -0
  117. package/src/mp/components/tabs/index.js +7 -2
  118. package/src/mp/components/tabs/index.wxml +2 -1
  119. package/src/mp/components/text/index.js +0 -25
  120. package/src/mp/components/text/index.wxml +3 -3
  121. package/src/mp/components/wxOpenApi/phone/index.js +117 -0
  122. package/src/mp/components/wxOpenApi/phone/index.json +4 -0
  123. package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
  124. package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
  125. package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
  126. package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
  127. package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
  128. package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
  129. package/src/mp/components/wxOpenApi/share/index.js +117 -0
  130. package/src/mp/components/wxOpenApi/share/index.json +4 -0
  131. package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
  132. package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
  133. package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
  134. package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
  135. package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
  136. package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
  137. package/src/mp/index.json +18 -2
  138. package/src/mp/style/weda-ui.wxss +2 -0
  139. package/src/mp/utils/debounce.js +133 -0
  140. package/src/mp/utils/destr.js +48 -0
  141. package/src/mp/utils/dr_square_point.js +25 -0
  142. package/src/mp/utils/platform.js +25 -0
  143. package/src/mp/utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js +1336 -0
  144. package/src/mp/utils/spark-md5.js +776 -0
  145. package/src/mp/utils/tcb.js +62 -0
  146. package/src/setupTests.js +2 -1
  147. package/src/web/components/button/index.css +8 -1
  148. package/src/web/components/button/index.tsx +3 -2
  149. package/src/web/components/calendar/index.css +382 -0
  150. package/src/web/components/calendar/index.jsx +312 -0
  151. package/src/web/components/calendar/util.js +90 -0
  152. package/src/web/components/carousel/index.css +119 -0
  153. package/src/web/components/carousel/index.tsx +417 -0
  154. package/src/web/components/chart/bar/index.tsx +140 -0
  155. package/src/web/components/chart/common/config/bar.js +49 -0
  156. package/src/web/components/chart/common/config/global.js +16 -0
  157. package/src/web/components/chart/common/config/line.js +50 -0
  158. package/src/web/components/chart/common/config/pie.js +37 -0
  159. package/src/web/components/chart/common/core/eChartBar.js +265 -0
  160. package/src/web/components/chart/common/core/eChartBase.ts +383 -0
  161. package/src/web/components/chart/common/core/eChartLine.js +231 -0
  162. package/src/web/components/chart/common/core/eChartPie.js +170 -0
  163. package/src/web/components/chart/common/core/type.ts +34 -0
  164. package/src/web/components/chart/common/echart.css +106 -0
  165. package/src/web/components/chart/common/echarts.ts +33 -0
  166. package/src/web/components/chart/common/useChart.tsx +69 -0
  167. package/src/web/components/chart/line/index.tsx +136 -0
  168. package/src/web/components/chart/pie/index.tsx +99 -0
  169. package/src/web/components/chart/statisticsCard/index.css +62 -0
  170. package/src/web/components/chart/statisticsCard/index.tsx +307 -0
  171. package/src/web/components/chart/statisticsCard/interface.ts +14 -0
  172. package/src/web/components/dataView/index.tsx +20 -0
  173. package/src/web/components/dataView/interface.ts +6 -0
  174. package/src/web/components/form/checkbox/index.tsx +55 -23
  175. package/src/web/components/form/location/common/mapChoose.css +178 -0
  176. package/src/web/components/form/location/common/mapChoose.jsx +343 -0
  177. package/src/web/components/form/location/common/mapView.jsx +190 -0
  178. package/src/web/components/form/location/common/propsConfig.js +54 -0
  179. package/src/web/components/form/location/common/selectModal.css +44 -0
  180. package/src/web/components/form/location/common/selectModal.jsx +82 -0
  181. package/src/web/components/form/location/common/useLocationInfo.js +100 -0
  182. package/src/web/components/form/location/components/LocationH5/index.css +243 -0
  183. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +403 -0
  184. package/src/web/components/form/location/components/LocationPC/Header.jsx +109 -0
  185. package/src/web/components/form/location/components/LocationPC/index.css +44 -0
  186. package/src/web/components/form/location/components/LocationPC/location.PC.jsx +323 -0
  187. package/src/web/components/form/location/constants.js +4 -0
  188. package/src/web/components/form/location/index.css +0 -0
  189. package/src/web/components/form/location/index.jsx +25 -0
  190. package/src/web/components/form/radio/index.tsx +84 -53
  191. package/src/web/components/form/select/h5.tsx +389 -71
  192. package/src/web/components/form/select/index.css +10 -0
  193. package/src/web/components/form/select/index.tsx +404 -144
  194. package/src/web/components/form/select/region/index.ts +122 -31
  195. package/src/web/components/form/select/time.jsx +90 -0
  196. package/src/web/components/form/select/year.tsx +170 -0
  197. package/src/web/components/form/uploader/uploader.h5.tsx +19 -4
  198. package/src/web/components/form/uploader/uploader.pc.tsx +8 -7
  199. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +132 -113
  200. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +16 -11
  201. package/src/web/components/graphicCard/index.css +159 -0
  202. package/src/web/components/graphicCard/index.tsx +310 -0
  203. package/src/web/components/image/image.tsx +1 -2
  204. package/src/web/components/image/index.tsx +1 -1
  205. package/src/web/components/index.js +24 -2
  206. package/src/web/components/link/index.tsx +6 -3
  207. package/src/web/components/listView/arrow-right-line.svg +3 -0
  208. package/src/web/components/listView/index.css +143 -0
  209. package/src/web/components/listView/index.tsx +359 -0
  210. package/src/web/components/listView/interface.ts +98 -0
  211. package/src/web/components/modal/index.tsx +3 -1
  212. package/src/web/components/navLayout/index.css +332 -0
  213. package/src/web/components/navLayout/index.tsx +247 -0
  214. package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
  215. package/src/web/components/navigationBar/common.tsx +198 -0
  216. package/src/web/components/navigationBar/h5Menu.tsx +179 -0
  217. package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
  218. package/src/web/components/navigationBar/index.css +762 -0
  219. package/src/web/components/navigationBar/index.tsx +231 -0
  220. package/src/web/components/navigationBar/type.d.ts +111 -0
  221. package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
  222. package/src/web/components/phone/index.css +0 -0
  223. package/src/web/components/phone/index.tsx +22 -0
  224. package/src/web/components/phoneCode/index.css +0 -0
  225. package/src/web/components/phoneCode/index.tsx +22 -0
  226. package/src/web/components/richTextView/index.tsx +3 -5
  227. package/src/web/components/share/index.css +0 -0
  228. package/src/web/components/share/index.tsx +38 -0
  229. package/src/web/components/tabs/index.tsx +4 -2
  230. package/src/web/components/tabs/tabs.h5.tsx +50 -37
  231. package/src/web/components/tabs/tabs.pc.tsx +23 -10
  232. package/src/web/components/text/index.tsx +6 -14
  233. package/src/web/components/uploaderFileView/index.css +9 -9
  234. package/src/web/components/uploaderFileView/index.jsx +32 -23
  235. package/src/web/components/userInfo/index.css +0 -0
  236. package/src/web/components/userInfo/index.tsx +30 -0
  237. package/src/web/types.d.ts +15 -14
  238. package/src/web/utils/debounce.js +98 -0
  239. package/src/web/utils/platform.js +40 -0
  240. package/src/web/utils/tcb.js +49 -0
  241. package/src/web/utils/tmap.js +4 -0
  242. package/src/web/weda-ui.css +2 -0
  243. package/CHANGELOG.md +0 -240
  244. package/src/.DS_Store +0 -0
  245. package/src/configs/.DS_Store +0 -0
  246. package/src/mp/.gitignore +0 -10
  247. package/src/web/.DS_Store +0 -0
  248. package/src/web/components/form/select/region/cities.ts +0 -2410
  249. package/src/web/components/form/select/region/provinces.ts +0 -240
  250. package/src/web/components/form/select/region/regions.ts +0 -20645
@@ -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;