@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
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import { Checkbox as TeaCheckbox, ConfigProvider } from 'tea-component';
3
3
 
4
4
  import classNames from '../../../utils/classnames';
@@ -8,6 +8,8 @@ import fromEntries from 'object.fromentries';
8
8
  import { usePlatform } from '../../../utils/platform';
9
9
  import { renderDecorator } from '../renderDecorator';
10
10
  import { CommonFormPropsType } from '../types';
11
+ import { callWedaApi } from '../../../utils/tcb';
12
+ import destr from 'destr';
11
13
 
12
14
  export default function Checkbox({
13
15
  // 系统属性
@@ -19,6 +21,8 @@ export default function Checkbox({
19
21
  name = 'formCheckbox',
20
22
  label = '标题',
21
23
  labelVisible = true,
24
+ format = '',
25
+ enumName = '',
22
26
  range = [],
23
27
  layout = 'horizontal',
24
28
  disabled = false,
@@ -40,21 +44,47 @@ export default function Checkbox({
40
44
  'weui-cell_disabled': isH5 && disabled,
41
45
  });
42
46
 
47
+ const [option, setOption] = useState(range);
43
48
  const [checkedItems, setCheckedItems] = React.useState(
44
- platform === 'h5' ? fromEntries(range.map(({ value, checked }) => [value, !!checked]))
45
- : range.filter(({checked}) => checked).map(({value}) => value)
49
+ platform === 'h5' ? fromEntries(option.map(({ value, checked }) => [value, !!checked]))
50
+ : option.filter(({ checked }) => checked).map(({ value }) => value)
46
51
  );
47
52
  // 两次range不同时, 需要刷新checkedItems
48
53
  const prevRangeRef = React.useRef<object[]>();
49
54
  React.useEffect(() => {
50
- if (!isObjectEqual(prevRangeRef.current, range)) {
51
- prevRangeRef.current = range;
55
+ if (!isObjectEqual(prevRangeRef.current, option)) {
56
+ prevRangeRef.current = option;
52
57
  setCheckedItems(
53
- fromEntries(range.map(({ value, checked }) => [value, !!checked]))
58
+ fromEntries(option.map(({ value, checked }) => [value, !!checked]))
54
59
  );
55
60
  }
56
61
  });
57
62
 
63
+ useEffect(() => {
64
+ // 如果绑定字段类型为枚举,且传入自定义选项集的名称则默认使用自定义选项集的内容作为选项
65
+ if (format === 'x-enum' && enumName) {
66
+ fetchData({ OptNameList: [enumName], PageIndex: 1, PageSize: 10 });
67
+ }
68
+ }, []);
69
+
70
+ const fetchData = async (param:
71
+ { OptNameList?: object, PageIndex?: number, PageSize?: number }
72
+ ) => {
73
+ let data = await callWedaApi({
74
+ action: 'DescribeGeneralOptionsDetailList',
75
+ data: param,
76
+ });
77
+ const config = destr(data?.Items?.[0]?.Config) ?? [];
78
+ const enumOption = config.map(item => {
79
+ return {
80
+ label: item.value,
81
+ value: item.key,
82
+ checked: false
83
+ };
84
+ });
85
+ setOption(enumOption);
86
+ };
87
+
58
88
  /**
59
89
  * 在ios h5端, label和input的绑定不生效
60
90
  * 导致 onChange 事件触发有问题, 所以改为监听 onClick 事件
@@ -82,8 +112,8 @@ export default function Checkbox({
82
112
  // 现在低码组件往源码组件传入的id不唯一, 暂时使用hashcode替代
83
113
  const hashcode = React.useMemo(() => getLocalCounter(), []);
84
114
  let checkboxElement;
85
- if(platform === 'h5') {
86
- checkboxElement = range.map(({ label, value }, index) => {
115
+ if (platform === 'h5') {
116
+ checkboxElement = option.map(({ label, value }, index) => {
87
117
  const _id = `checkbox-${hashcode}-${index}`;
88
118
  const _name = `checkbox-${hashcode}-${name}`;
89
119
  return (
@@ -120,17 +150,17 @@ export default function Checkbox({
120
150
  .map(([value]) => value)
121
151
  }
122
152
  onChange={value => {
123
- const newMap = range
124
- .map((opt) => opt.value)
125
- .reduce((acc, cur) => {
126
- const idx = value.indexOf(cur);
127
- if(idx < 0) {
128
- acc[cur] = false;
129
- } else {
130
- acc[cur] = true;
131
- }
132
- return acc;
133
- }, {});
153
+ const newMap = option
154
+ .map((opt) => opt.value)
155
+ .reduce((acc, cur) => {
156
+ const idx = value.indexOf(cur);
157
+ if (idx < 0) {
158
+ acc[cur] = false;
159
+ } else {
160
+ acc[cur] = true;
161
+ }
162
+ return acc;
163
+ }, {});
134
164
  setCheckedItems(newMap);
135
165
  events.change(
136
166
  {
@@ -141,7 +171,7 @@ export default function Checkbox({
141
171
  );
142
172
  }}
143
173
  >
144
- {range.map(({value, label}, index) => {
174
+ {option.map(({ value, label }, index) => {
145
175
  const _id = `checkbox-${hashcode}-${index}`;
146
176
  return (
147
177
  <TeaCheckbox key={_id} name={value} id={_id}>
@@ -149,7 +179,7 @@ export default function Checkbox({
149
179
  </TeaCheckbox>
150
180
  );
151
181
  })}
152
- </TeaCheckbox.Group>
182
+ </TeaCheckbox.Group>
153
183
  </ConfigProvider>
154
184
  );
155
185
  }
@@ -167,5 +197,7 @@ export default function Checkbox({
167
197
  }
168
198
 
169
199
  export interface PropsType extends CommonFormPropsType {
170
- range?: {label: string, value: any; [key: string]: any}[];
171
- }
200
+ range?: { label: string, value: any;[key: string]: any }[];
201
+ format?: string;
202
+ enumName?: string;
203
+ }
@@ -0,0 +1,178 @@
1
+ /* mapChoose组件 */
2
+ .weda-ui_map-choose {
3
+ width: 100%;
4
+ height: 100%;
5
+ }
6
+ .map-choose-pc {
7
+ display: flex;
8
+ }
9
+ .map-choose-pc-left {
10
+ width: 45%;
11
+ position: relative;
12
+ }
13
+ .map-choose-pc-right {
14
+ width: 55%;
15
+ }
16
+ .map-choose-header {
17
+ width: 100%;
18
+ padding: 8px 15px;
19
+ position: relative;
20
+ border-bottom: 1px solid #d3d3d3;
21
+ }
22
+ .map-choose-header_focus {
23
+ padding-right: 60px;
24
+ }
25
+ .map-choose-header_focus .map-choose-header_search_cancel {
26
+ display: block;
27
+ }
28
+ .map-choose-header_focus .map-choose-header_search_place {
29
+ left: 10px;
30
+ transform: translate(0, 0);
31
+ }
32
+ .map-choose-header_search {
33
+ height: 30px;
34
+ background-color: #ebebeb;
35
+ padding-left: 10px;
36
+ padding-right: 10px;
37
+ color: #b4b4b4;
38
+ font-size: 15px;
39
+ line-height: 31px;
40
+ border-radius: 5px;
41
+ overflow: hidden;
42
+ white-space: nowrap;
43
+ text-overflow: ellipsis;
44
+ position: relative;
45
+ }
46
+ .map-choose-header_search_place {
47
+ position: absolute;
48
+ top: 0;
49
+ left: 50%;
50
+ display: flex;
51
+ align-items: center;
52
+ transform: translate(-50%, 0);
53
+ }
54
+ .map-choose-header_search_cancel {
55
+ position: absolute;
56
+ top: 0;
57
+ right: 0;
58
+ width: 55px;
59
+ height: 46px;
60
+ line-height: 46px;
61
+ text-align: center;
62
+ font-size: 16px;
63
+ color: #0079ff;
64
+ background-color: #fff;
65
+ cursor: pointer;
66
+ display: none;
67
+ }
68
+ .map-choose-header_search img {
69
+ width: 16px;
70
+ height: 16px;
71
+ margin-right: 4px;
72
+ }
73
+ .map-choose-header_search input {
74
+ display: block;
75
+ width: 100%;
76
+ padding-top: 6px;
77
+ padding-bottom: 6px;
78
+ border: 0;
79
+ font-size: 14px;
80
+ line-height: 18px;
81
+ background: 0 0;
82
+ position: relative;
83
+ z-index: 1;
84
+ }
85
+
86
+ .map-choose-con {
87
+ width: 100%;
88
+ height: calc(100% - 50px);
89
+ position: relative;
90
+ }
91
+ .map-choose-warp,
92
+ .map-choose-explore {
93
+ width: 100%;
94
+ height: 100%;
95
+ }
96
+ .map-choose-explore-pc {
97
+ height: calc(100% - 47px);
98
+ }
99
+ .map-choose-explore {
100
+ display: none;
101
+ }
102
+ .map-choose-explore_show {
103
+ display: block;
104
+ position: absolute;
105
+ z-index: 1000;
106
+ top: 0;
107
+ left: 0;
108
+ background-color: #fff;
109
+ overflow: hidden;
110
+ }
111
+ .map-choose-explore_show-pc {
112
+ top: 47px;
113
+ }
114
+
115
+ .map-choose-warp_sugges {
116
+ height: 55%;
117
+ width: 100%;
118
+ }
119
+ .map-choose-warp_sugges-pc {
120
+ height: calc(100% - 47px);
121
+ width: 100%;
122
+ }
123
+ .map-choose-warp_sugges ul,
124
+ .map-choose-explore_show ul {
125
+ width: 100%;
126
+ height: 100%;
127
+ padding: 0;
128
+ overflow: scroll;
129
+ overflow-x: hidden;
130
+ }
131
+ .map-choose-warp_sugges li,
132
+ .map-choose-explore_show li {
133
+ width: 100%;
134
+ height: 59px;
135
+ padding-top: 6px;
136
+ position: relative;
137
+ border-bottom: 1px solid #d3d3d3;
138
+ cursor: pointer;
139
+ position: relative;
140
+ }
141
+ .map-choose-warp_sugges li span {
142
+ display: none;
143
+ }
144
+ .map-choose-warp_sugges_choosed span {
145
+ position: absolute;
146
+ right: 20px;
147
+ top: 50%;
148
+ transform: translate(0, -50%);
149
+ width: 16px;
150
+ height: 16px;
151
+ display: block !important;
152
+ background-image: url('https://qcloudimg.tencent-cloud.cn/raw/354c15c0cb845120ac3e9c474e6737b3.png');
153
+ background-size: 100% 100%;
154
+ background-repeat: no-repeat;
155
+ }
156
+ .map-choose-warp_sugges li div,
157
+ .map-choose-explore_show li div {
158
+ text-overflow: ellipsis;
159
+ white-space: nowrap;
160
+ overflow: hidden;
161
+ width: 98%;
162
+ }
163
+ .map-choose-warp_sugges_title,
164
+ .map-choose-explore_title {
165
+ font-size: 14px;
166
+ line-height: 27px;
167
+ color: #333;
168
+ font-weight: 400;
169
+ display: block;
170
+ }
171
+
172
+ .map-choose-explore_show_inSearch {
173
+ display: none;
174
+ }
175
+ .map-choose-explore_show-h5 {
176
+ height: auto;
177
+ min-height: 75vh;
178
+ }
@@ -0,0 +1,343 @@
1
+ import * as React from 'react';
2
+ import * as PropTypes from 'prop-types';
3
+ import classNames from '../../../../utils/classnames';
4
+ import debounce from '../../../../utils/debounce';
5
+ import { tmapApiUrl } from '../constants';
6
+ import { getTMap } from '../../../../utils/tmap';
7
+ import './mapChoose.css';
8
+
9
+ const { useEffect, useState, useRef } = React;
10
+
11
+ export default function MapChoose({
12
+ changeLocation,
13
+ latlng = {
14
+ lat: null,
15
+ lng: null,
16
+ },
17
+ isPC,
18
+ APIKEY = '',
19
+ }) {
20
+ const { lat, lng } = latlng;
21
+
22
+ const mapRef = useRef();
23
+ const markerRef = useRef();
24
+ const centerRef = useRef();
25
+
26
+ const [isSearch, setIsSearch] = useState(false);
27
+ const [searchValue, setSearchValue] = useState('');
28
+ const [chooseLoc, setChooseLoc] = useState({
29
+ location: {
30
+ lat: null,
31
+ lng: null,
32
+ },
33
+ title: '',
34
+ address: '',
35
+ id: '',
36
+ });
37
+ const [exploreList, setExploreList] = useState([]);
38
+ const [searchList, setSearchList] = useState([]);
39
+ const [mapDomName, setMapDomName] = useState(new Date().getTime());
40
+
41
+ useEffect(() => {
42
+ if (!APIKEY || APIKEY == '这里是示例') return;
43
+ function loadScript() {
44
+ const script = document.createElement('script');
45
+ script.type = 'text/javascript';
46
+ script.src = `${tmapApiUrl}?v=2.exp&key=${APIKEY}&callback=init&libraries=service`;
47
+ script.onload = () => {
48
+ initMap();
49
+ };
50
+ script.onerror = (error) => {
51
+ console.log(' load mapchoose error success', APIKEY);
52
+ };
53
+ document.body.appendChild(script);
54
+ }
55
+ if (getTMap()) {
56
+ initMap();
57
+ } else {
58
+ loadScript();
59
+ }
60
+ exploreNear();
61
+ return () => {
62
+ // @ts-ignore
63
+ mapRef.current && mapRef.current.destroy();
64
+ };
65
+ }, [APIKEY]);
66
+
67
+ const initMap = () => {
68
+ if (!getTMap()) return;
69
+ const TMap = getTMap();
70
+ //定义地图中心点坐标
71
+ const center = new TMap.LatLng(lat, lng);
72
+ //定义map变量,调用 TMap.Map() 构造函数创建地图
73
+ mapRef.current = new TMap.Map(
74
+ document.getElementById(`form-map-choose-${mapDomName}`),
75
+ {
76
+ center, //设置地图中心点坐标
77
+ zoom: 16, //设置地图缩放级别
78
+ }
79
+ );
80
+ initMarker(getTMap(), mapRef.current);
81
+ };
82
+
83
+ const initMarker = (TMap, map) => {
84
+ const canLoad = lat && lng && TMap && map;
85
+ if (canLoad) {
86
+ const position = new TMap.LatLng(lat, lng);
87
+ markerRef.current = new TMap.MultiMarker({
88
+ map: mapRef.current,
89
+ styles: {
90
+ pointer: new TMap.MarkerStyle({
91
+ width: 26,
92
+ height: 35,
93
+ }),
94
+ },
95
+ geometries: [
96
+ {
97
+ id: `pointer-origin-${mapDomName}`,
98
+ styleId: 'pointer',
99
+ position,
100
+ },
101
+ {
102
+ id: `pointer-${mapDomName}`,
103
+ styleId: 'pointer',
104
+ position,
105
+ },
106
+ ],
107
+ });
108
+ // 监听中心点变化事件,更新marker的位置
109
+ map.on('center_changed', updateCenter);
110
+ }
111
+ };
112
+
113
+ const updateCenter = () => {
114
+ const TMap = getTMap();
115
+ const canLoad = TMap && lat && lng && mapRef.current;
116
+ if (canLoad) {
117
+ const nowPosition = new TMap.LatLng(lat, lng);
118
+ // @ts-ignore
119
+ let centerPosition = mapRef.current.getCenter();
120
+ centerRef.current = centerPosition;
121
+ // @ts-ignore
122
+ markerRef.current.updateGeometries([
123
+ {
124
+ id: `pointer-origin-${mapDomName}`,
125
+ styleId: 'pointer',
126
+ position: nowPosition,
127
+ },
128
+ {
129
+ id: `pointer-${mapDomName}`,
130
+ styleId: 'pointer',
131
+ // @ts-ignore
132
+ position: mapRef.current.getCenter(),
133
+ },
134
+ ]);
135
+ exploreNear();
136
+ }
137
+ };
138
+
139
+ const handleFocus = (value) => {
140
+ setIsSearch(value);
141
+ };
142
+
143
+ const exploreNear = debounce(() => {
144
+ const { lat, lng } = centerRef.current || latlng;
145
+ let TMap = getTMap();
146
+ let search = new TMap.service.Search({ pageSize: 20 }); // 新建一个地点搜索类
147
+ search
148
+ .explore({
149
+ center: new TMap.LatLng(lat, lng),
150
+ policy: 1,
151
+ radius: 2000,
152
+ pageIndex: 1,
153
+ })
154
+ .then((res) => {
155
+ res.data && setExploreList(res.data);
156
+ });
157
+ }, 500);
158
+
159
+ const chooseLoction = (value, type) => {
160
+ const TMap = getTMap();
161
+ //定义地图中心点坐标
162
+ const center = new TMap.LatLng(value.location.lat, value.location.lng);
163
+ // @ts-ignore
164
+ mapRef.current.setCenter(center);
165
+ setChooseLoc(value);
166
+ changeLocation(value);
167
+ type && cancleSearch();
168
+ };
169
+
170
+ const changeSearchValue = (event) => {
171
+ if (event.target.value) {
172
+ setSearchValue(event.target.value);
173
+ let TMap = getTMap();
174
+ let search = new TMap.service.Search({ pageSize: 10 }); // 新建一个地点搜索类
175
+ search
176
+ .searchNearby({
177
+ keyword: event.target.value,
178
+ center: new TMap.LatLng(lat, lng),
179
+ radius: 2000,
180
+ pageIndex: 1,
181
+ })
182
+ .then((res) => {
183
+ setSearchList(res.data);
184
+ })
185
+ .catch((error) => {
186
+ console.log('error', error);
187
+ });
188
+ } else {
189
+ setSearchValue('');
190
+ setTimeout(() => {
191
+ setSearchList([]);
192
+ }, 300);
193
+ }
194
+ };
195
+
196
+ const cancleSearch = () => {
197
+ handleFocus(false);
198
+ setSearchValue('');
199
+ setSearchList([]);
200
+ };
201
+
202
+ const renderHeader = () => {
203
+ return (
204
+ <div
205
+ className={classNames({
206
+ 'map-choose-header': true,
207
+ 'map-choose-header_focus': isSearch,
208
+ })}
209
+ >
210
+ <div className="map-choose-header_search">
211
+ <input
212
+ type="text"
213
+ onFocus={() => {
214
+ handleFocus(true);
215
+ }}
216
+ onChange={changeSearchValue}
217
+ value={searchValue}
218
+ />
219
+ {!searchValue && (
220
+ <div className="map-choose-header_search_place">
221
+ <img
222
+ src="https://qcloudimg.tencent-cloud.cn/raw/388c48cdcbe9ca07f5682fb10d05ebdd.png"
223
+ alt=""
224
+ />
225
+ <span>搜索地点</span>
226
+ </div>
227
+ )}
228
+ </div>
229
+ <span
230
+ className="map-choose-header_search_cancel"
231
+ onClick={cancleSearch}
232
+ >
233
+ 取消
234
+ </span>
235
+ </div>
236
+ );
237
+ };
238
+ const renderMapView = () => {
239
+ return (
240
+ <div
241
+ id={`form-map-choose-${mapDomName}`}
242
+ style={{ height: isPC ? '100%' : '45%', width: '100%' }}
243
+ ></div>
244
+ );
245
+ };
246
+ const renderSuggestList = () => {
247
+ return (
248
+ <div
249
+ className={classNames({
250
+ 'map-choose-warp_sugges': true,
251
+ 'map-choose-explore_show_inSearch': isSearch,
252
+ 'map-choose-warp_sugges-pc': isPC,
253
+ })}
254
+ >
255
+ <ul>
256
+ {exploreList.map((item, index) => (
257
+ <li
258
+ key={index}
259
+ onClick={() => {
260
+ chooseLoction(item);
261
+ }}
262
+ className={classNames({
263
+ 'map-choose-warp_sugges_choosed': chooseLoc.id == item.id,
264
+ })}
265
+ >
266
+ <div className="map-choose-warp_sugges_title">{item.title}</div>
267
+ <div>{item.address}</div>
268
+ <span />
269
+ </li>
270
+ ))}
271
+ </ul>
272
+ </div>
273
+ );
274
+ };
275
+ const renderExplore = () => {
276
+ return (
277
+ <div
278
+ className={classNames({
279
+ 'map-choose-explore': true,
280
+ 'map-choose-explore_show': isSearch,
281
+ 'map-choose-explore_show-h5': isSearch && !isPC,
282
+ 'map-choose-explore-pc': isPC,
283
+ 'map-choose-explore_show-pc': isPC,
284
+ })}
285
+ >
286
+ <ul>
287
+ {searchList.map((item, index) => (
288
+ <li
289
+ key={index}
290
+ onClick={() => {
291
+ chooseLoction(item, true);
292
+ }}
293
+ className={classNames({
294
+ 'map-choose-explore_choosed': chooseLoc.id == item.id,
295
+ })}
296
+ >
297
+ <div className="map-choose-explore_title">{item.title}</div>
298
+ <div>{item.address}</div>
299
+ <span />
300
+ </li>
301
+ ))}
302
+ </ul>
303
+ </div>
304
+ );
305
+ };
306
+ if (isPC) {
307
+ return (
308
+ <div
309
+ className={classNames(
310
+ 'map-choose',
311
+ 'map-choose-pc',
312
+ 'weda-ui_map-choose'
313
+ )}
314
+ >
315
+ <div className="map-choose-pc-left">
316
+ {renderHeader()}
317
+ {renderSuggestList()}
318
+ {renderExplore()}
319
+ </div>
320
+ <div className="map-choose-pc-right">{renderMapView()}</div>
321
+ </div>
322
+ );
323
+ }
324
+ return (
325
+ <div className="map-choose weda-ui_map-choose">
326
+ {renderHeader()}
327
+ <div className="map-choose-con">
328
+ <div className="map-choose-warp">
329
+ {renderMapView()}
330
+ {renderSuggestList()}
331
+ </div>
332
+ {renderExplore()}
333
+ </div>
334
+ </div>
335
+ );
336
+ }
337
+
338
+ MapChoose.propTypes = {
339
+ APIKEY: PropTypes.string,
340
+ latlng: PropTypes.object,
341
+ changeLocation: PropTypes.func,
342
+ isPC: PropTypes.bool,
343
+ };