@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,27 +1,53 @@
1
1
  import * as React from 'react';
2
- import * as _moment from 'moment';
3
-
4
2
  import weui from '../../../utils/weui';
5
3
  import classNames from '../../../utils/classnames';
6
4
  import isObjectEqual from '../../../utils/isObjectEqual';
7
- import { timePicker } from './time';
8
- import { regionPicker } from './region';
9
- import {PropsType} from './index';
5
+ import { regionPicker,getRegionTree,getAreaCode } from './region/index';
6
+ import { PropsType } from './index';
10
7
  import { defaultProps } from './index';
8
+ import { timePicker, yearPicker, monthPicker } from './time';
9
+ import { moment } from './index';
10
+ import { callDataSource, callWedaApi } from '../../../utils/tcb';
11
+ import destr from 'destr';
12
+
13
+
14
+
15
+
16
+ const REL_DICT = {
17
+ equal: 'eq', // 等于
18
+ unequal: 'neq', // 不等于
19
+ include: 'search', // 包含
20
+ exclude: '_exclude', // 不包含
21
+ begin_with: '_begin_with', // 开头是
22
+ greater: 'gt', // 大于
23
+ greater_or_equal: 'gte', // 大于等于
24
+ bigger_or_equal: 'gte', //大于等于
25
+ less: 'lt', // 小于
26
+ less_or_equal: 'lte', // 小于等于
27
+ in: 'in', // 多选值
28
+ not_in: 'nin', // 不在多选值
29
+ };
30
+
11
31
 
12
- // @ts-expect-error TODO: fix 与plugin构建阶段效果不同
13
- const moment = (typeof _moment === 'function' ? _moment : _moment.default) as _moment.moment;
14
32
  export default function Select({
15
33
  // 系统属性
16
- events,
34
+ events = {change: null },
17
35
  // 组件属性
18
36
  name,
19
37
  placeholder,
20
38
  layout,
21
39
  mode,
40
+ dateMode = 'day',
22
41
  disabled = false,
23
42
  // selector mode
24
43
  range = defaultProps.range,
44
+ where,
45
+ primaryField,
46
+ tipBlock,
47
+ enumName,
48
+ dataSourceName,
49
+ viewId,
50
+ format,
25
51
  defaultValue,
26
52
  // date mode
27
53
  startDate,
@@ -33,29 +59,38 @@ export default function Select({
33
59
  defaultTime,
34
60
  // region mode
35
61
  defaultRegion,
62
+ defaultMutiRegion,
63
+ regionType,
36
64
  separator,
65
+ onChange
66
+ //regionTree,
37
67
  }: PropsType) {
38
68
  const [date, setDate] = React.useState(
39
- decodeIsoDatetime(defaultDate, 'date')
69
+ decodeIsoDatetime(defaultDate, 'date', dateMode)
40
70
  );
41
71
  const [time, setTime] = React.useState(
42
72
  decodeIsoDatetime(defaultTime, 'time')
43
73
  );
44
- const [region, setRegion] = React.useState(
45
- defaultRegion
46
- );
74
+ const [regioDepth,setRegionDepth] = React.useState(3);
75
+ const [regionData,setRegionData] = React.useState([]);
76
+ const [regionTree,setRegionTree] = React.useState([]);
77
+ const [region, setRegion] = React.useState(defaultRegion);
78
+ const [mutiRegion,setMutiRegion]=React.useState([]);
79
+ const [typeRegion, setTypeRegion] = React.useState(regionType);
47
80
  const [selectedValue, setSelectedValue] = React.useState(defaultValue);
81
+ const [option, setOption] = React.useState([{ label: '', value: '' }]);
82
+ const [records, setRecords] = React.useState([]);
48
83
 
49
84
  // 两次默认值不同, 需要刷新
50
85
  const prevDefaultRef = React.useRef<any>({});
51
- React.useEffect(() => {
86
+ React.useEffect( () => {
52
87
  let hasChange = false;
53
88
  if (prevDefaultRef.current?.defaultValue !== defaultValue) {
54
89
  setSelectedValue(defaultValue);
55
90
  hasChange = true;
56
91
  }
57
92
  if (prevDefaultRef.current?.defaultDate !== defaultDate) {
58
- setDate(decodeIsoDatetime(defaultDate, 'date'));
93
+ setDate(decodeIsoDatetime(defaultDate, 'date', dateMode));
59
94
  hasChange = true;
60
95
  }
61
96
  if (prevDefaultRef.current?.defaultTime !== defaultTime) {
@@ -66,14 +101,168 @@ export default function Select({
66
101
  setRegion(defaultRegion);
67
102
  hasChange = true;
68
103
  }
104
+ if (!isObjectEqual(prevDefaultRef.current?.defaultMutiRegion, defaultMutiRegion)) {
105
+
106
+ //setMutiRegion((defaultMutiRegion || ".").split(','));
107
+ setMutiRegion(defaultMutiRegion?defaultMutiRegion.split(','):[]);
108
+ hasChange = true;
109
+ }
110
+ if (prevDefaultRef.current?.regionType !== regionType) {
111
+ setTypeRegion(regionType);
112
+ hasChange = true;
113
+ }
69
114
  if (hasChange) {
70
115
  prevDefaultRef.current = {
116
+ defaultValue,
71
117
  defaultDate,
72
118
  defaultTime,
73
119
  defaultRegion,
120
+ defaultMutiRegion
74
121
  };
75
122
  }
123
+
76
124
  });
125
+ //实现初始值触发change事件
126
+ const defaultMutiRegionChange = function(treeValue,defaultMutiRegion){
127
+ const defaultValue =defaultMutiRegion?defaultMutiRegion.split(','):null;
128
+ const changeValue=[];
129
+ if(Array.isArray(defaultValue)&&defaultValue.length>0){
130
+ defaultValue.forEach(element => {
131
+ treeValue.map((item)=>{
132
+ if(item?.Value == element){
133
+ changeValue.push({
134
+ value:item?.Value,
135
+ code:item?.Code
136
+ }
137
+ );
138
+ }
139
+ });
140
+ });
141
+
142
+ events?.change?.({ value:defaultMutiRegion,result:changeValue });
143
+ }
144
+ };
145
+ const regionTreeMode = React.useMemo(()=>{
146
+ if((mode=='region'|| mode=='mutiRegion')){
147
+ if(regionData.length<1){
148
+ getAreaCode().then((value)=>{
149
+ defaultMutiRegionChange(value,defaultMutiRegion);
150
+ setRegionData(value);
151
+ getRegionTree(value,regionType,mode).then(tree=>{
152
+ setRegionTree(tree);
153
+ });
154
+ });
155
+ }else{
156
+ getRegionTree(regionData,regionType,mode).then(tree=>{
157
+ setRegionTree(tree);
158
+ });
159
+ }
160
+ }
161
+ switch(regionType){
162
+ case 'levelOne':{
163
+ setRegionDepth(1);
164
+ break;
165
+ }
166
+ case 'levelTwo':{
167
+ setRegionDepth(2);
168
+ break;
169
+ }
170
+ case 'levelThree':{
171
+ setRegionDepth(3);
172
+ break;
173
+ }
174
+ default: {
175
+ break;
176
+ }
177
+ }
178
+
179
+ },[regionType,mode,regionData]);
180
+
181
+ React.useEffect(() => {
182
+ // tcb过滤参数
183
+ const whereEffected = [].concat(getWhereList(where));
184
+ if ((format === 'father-son' || format === 'related') && dataSourceName && viewId) {
185
+ fetchData({
186
+ dataSourceName: dataSourceName,
187
+ viewId: viewId,
188
+ methodName: 'wedaGetRecords',
189
+ params: whereEffected
190
+ });
191
+ }
192
+ }, [where]);
193
+
194
+ // 获取数据列表中主列字段,将其作为选项
195
+ React.useEffect(() => {
196
+ if (records && records.length !== 0 && primaryField) {
197
+ const option = records.map(item => {
198
+ return {
199
+ label: item[primaryField],
200
+ value: item._id
201
+ };
202
+ });
203
+ setOption(option);
204
+ }
205
+ }, [records]);
206
+
207
+ // 获取数据列表
208
+ const fetchData = async (param: {
209
+ dataSourceName?: string,
210
+ viewId?: string,
211
+ methodName?: string,
212
+ params?: any,
213
+ }) => {
214
+ let pageNo = 1;
215
+ let pageSize = 200;
216
+ let records = [];
217
+ let total = 99999;
218
+ for (let index = 0; index < Math.floor(total / pageSize) + 1; index++) {
219
+ let data = await callDataSource({
220
+ dataSourceName: param.dataSourceName,
221
+ viewId: param.viewId,
222
+ methodName: param.methodName,
223
+ params: {
224
+ where: param.params,
225
+ pageNo: pageNo,
226
+ pageSize: pageSize
227
+ },
228
+ });
229
+ pageNo = pageNo + 1;
230
+ if (data?.records) {
231
+ total = data?.total || 0;
232
+ records = records.concat(data?.records);
233
+ }
234
+
235
+ }
236
+
237
+ if (records) {
238
+ setRecords(records);
239
+ }
240
+ };
241
+
242
+ React.useEffect(() => {
243
+ // 如果绑定字段类型为枚举,且传入自定义选项集的名称则默认使用自定义选项集的内容作为选项
244
+ if (format === 'x-enum' && enumName) {
245
+ fetchEnumData({ OptNameList: [enumName], PageIndex: 1, PageSize: 10 });
246
+ }
247
+ }, [enumName]);
248
+
249
+ // 获取自定义选项集
250
+ const fetchEnumData = async (param:
251
+ { OptNameList?: object, PageIndex?: number, PageSize?: number }
252
+ ) => {
253
+ let data = await callWedaApi({
254
+ action: 'DescribeGeneralOptionsDetailList',
255
+ data: param,
256
+ });
257
+ const config = destr(data?.Items[0]?.Config) ?? [];
258
+ const enumOption = config.map(item => {
259
+ return {
260
+ label: item.value,
261
+ value: item.key,
262
+ };
263
+ });
264
+ setOption(enumOption);
265
+ };
77
266
 
78
267
  const isFlex = layout !== 'vertical';
79
268
  const subCls = classNames({
@@ -91,19 +280,26 @@ export default function Select({
91
280
  !!date && (options.defaultDate = date);
92
281
  !!startDate && (options.start = decodeIsoDatetime(startDate, 'date'));
93
282
  !!endDate && (options.end = decodeIsoDatetime(endDate, 'date'));
283
+ if (['year', 'month'].includes(dateMode)) {
284
+ !!startDate && (options.startDate = startDate);
285
+ !!endDate && (options.endDate = endDate);
286
+ }
287
+ options.onConfirm = (result) => {
288
+ const value = formatDateModeValue(result, dateMode);
289
+ setDate(value);
290
+ events.change({ value: new Date(value).getTime() });
291
+ };
94
292
 
95
- weui.datePicker({
96
- ...options,
97
- onConfirm(result) {
98
- const value = moment()
99
- .year(result[0].value)
100
- .month(result[1].value - 1)
101
- .date(result[2].value)
102
- .format('YYYY-MM-DD');
103
- setDate(value);
104
- events.change({ value: new Date(value).getTime() });
105
- },
106
- });
293
+ if (dateMode === 'year') {
294
+ // 年,1 列
295
+ yearPicker({ ...options });
296
+ } else if (dateMode === 'month') {
297
+ // 年月,2 列
298
+ monthPicker({ ...options });
299
+ } else {
300
+ // 年月日,3 列
301
+ weui.datePicker({ id: String(Date.now()), ...options });
302
+ }
107
303
  };
108
304
 
109
305
  const onTimeClick = function () {
@@ -120,41 +316,112 @@ export default function Select({
120
316
  const date = moment().hour(result[0].value).minute(result[1].value);
121
317
  const value = date.format('HH:mm');
122
318
  setTime(value);
123
- events.change({
319
+ events?.change({
124
320
  value: (date.hour() * 60 * 60 + date.minute() * 60) * 1000,
125
321
  });
126
322
  },
127
323
  });
128
324
  };
325
+ const isNull = (val) => [undefined, null].includes(val);
326
+ const getWhereList = (where) => {
327
+ let result = [];
328
+ Array.isArray(where) &&
329
+ where.forEach((item1) => {
330
+ if (item1?.groupLogic !== 'or' && Array.isArray(item1?.logicData)) {
331
+ item1?.logicData.forEach((item2) => {
332
+ let [rel, val] = [REL_DICT[item2?.rel], item2?.value];
333
+ if ('_begin_with' === rel) {
334
+ rel = 'regex';
335
+ val = `^${val}`;
336
+ }
337
+ if ('_exclude' === rel) {
338
+ rel = 'regex';
339
+ val = `^((?!${val}).)*$`;
340
+ }
341
+ if (item2?.logic !== 'or' && item2?.key && rel && !isNull(val)) {
342
+ result.push({ key: item2.key, rel, val });
343
+ }
344
+ });
345
+ }
346
+ });
347
+ return result;
348
+ };
129
349
 
130
350
  const onSelect = function () {
131
- weui.picker(range, {
132
- defaultValue: [selectedValue || range[0].value],
133
- onConfirm(result) {
134
- const item = result[0];
135
- setSelectedValue(item?.value);
136
- events.change({ value: item?.value });
137
- },
138
- className: 'weda-ui weda-picker',
139
- });
351
+ if (format === 'father-son' || format === 'related' || format === 'x-enum') {
352
+ weui.picker(option, {
353
+ id: String(Date.now()),
354
+ defaultValue: [selectedValue || option[0].value],
355
+ onConfirm(result) {
356
+ const item = result[0];
357
+ setSelectedValue(item?.value);
358
+ events.change({ value: item?.value });
359
+ },
360
+ className: 'weda-ui weda-picker',
361
+ });
362
+ } else {
363
+ weui.picker(range, {
364
+ id: String(Date.now()),
365
+ defaultValue: [selectedValue || range[0].value],
366
+ onConfirm(result) {
367
+ const item = result[0];
368
+ setSelectedValue(item?.value);
369
+ events.change({ value: item?.value });
370
+ },
371
+ className: 'weda-ui weda-picker',
372
+ });
373
+ }
374
+ };
375
+ let regionTimer;
376
+ const momentClick =async () => {
377
+ regionTimer = setInterval(() => {
378
+ setTimeout(()=>{
379
+ if(regionTree.length!=0){
380
+ onRegionClick();
381
+ }
382
+ }, 0);
383
+ }, regionTree.length==0?500:0);
140
384
  };
141
-
142
385
  const onRegionClick = function () {
143
- regionPicker({
144
- defaultValue:
145
- (defaultRegion && defaultRegion.length <= 0)
146
- ? ['北京市', '北京市', '东城区']
147
- : defaultRegion,
148
- onConfirm(result) {
149
- const value = result.map((item) => item.value);
150
- setRegion(value);
151
- events.change({ value });
152
- },
153
- className: 'weda-ui weda-picker',
154
- });
386
+ clearInterval(regionTimer);
387
+ let defaultValue=[];
388
+ if(mode=='region'){
389
+ defaultRegion && defaultRegion.length <= 0
390
+ ? defaultValue=['北京市', '北京市', '东城区']
391
+ : defaultValue= defaultRegion;
392
+ }else{
393
+ mutiRegion && mutiRegion.length <= 0
394
+ ? defaultValue=['北京市', '北京市', '东城区']
395
+ : defaultValue= mutiRegion;
396
+ }
397
+ regionPicker(
398
+ {
399
+ defaultValue:defaultValue,
400
+ depth:regioDepth,
401
+ onConfirm(result) {
402
+ const value = result.map((item) => item.value);
403
+ //const value=regionValueSplit(typeRegion,defaultvalue);
404
+ mode=='region'?setRegion(value):setMutiRegion(value);
405
+ const changeValue = mode=='region'?value:value.join(',');
406
+ onChange && onChange(changeValue);
407
+ events?.change?.({ value:changeValue,result:result.map((item)=>{
408
+ return {
409
+ value:item?.value,
410
+ code:item?.code
411
+ };
412
+ }) });
413
+
414
+ },
415
+ onChange(result) {
416
+ },
417
+ className: 'weda-ui weda-picker',
418
+ id: new Date().valueOf(),
419
+ },
420
+ regionTree
421
+ );
155
422
  };
156
423
 
157
- const onClick = function () {
424
+ const onClick =async function () {
158
425
  if (disabled) {
159
426
  return;
160
427
  }
@@ -173,7 +440,11 @@ export default function Select({
173
440
  break;
174
441
  }
175
442
  case 'region': {
176
- onRegionClick();
443
+ momentClick();
444
+ break;
445
+ }
446
+ case 'mutiRegion': {
447
+ momentClick();
177
448
  break;
178
449
  }
179
450
  default: {
@@ -183,35 +454,42 @@ export default function Select({
183
454
  };
184
455
 
185
456
  const result = React.useMemo(() => {
457
+ let selectLabel = '';
458
+ if (format === 'father-son' || format === 'related' || format === 'x-enum') {
459
+ selectLabel = (option ?? []).find((item) => item.value === selectedValue)?.label;
460
+ } else {
461
+ selectLabel = (range ?? []).find((item) => item.value === selectedValue)?.label;
462
+ }
186
463
  return {
187
- selector: (range ?? []).find((item) => item.value === selectedValue)?.label,
464
+ selector: selectLabel,
188
465
  date: date,
189
466
  time: time,
190
467
  region: (region || []).join(separator), // region 有可能是空串
468
+ mutiRegion:mutiRegion
191
469
  };
192
- }, [range, selectedValue, date, time, region, separator]);
470
+ }, [range, selectedValue, date, time, region, separator,mutiRegion]);
193
471
 
194
472
  return (
195
- <div className={subCls}>
196
- <div className="weui-cell__bd weui-flex">
197
- <input
198
- onClick={onClick}
199
- className="weui-input"
200
- type="select"
201
- name={name}
202
- placeholder={placeholder}
203
- value={result[mode] ?? ''}
204
- disabled={disabled}
205
- autoComplete={'off'}
206
- readOnly={true}
207
- />
208
- </div>
473
+ <div className={subCls}>
474
+ <div className="weui-cell__bd weui-flex">
475
+ <input
476
+ onClick={onClick}
477
+ className="weui-input"
478
+ type="select"
479
+ name={name}
480
+ placeholder={placeholder}
481
+ value={result[mode] ?? ''}
482
+ disabled={disabled}
483
+ autoComplete={'off'}
484
+ readOnly={true}
485
+ data-testid="form-item-select"
486
+ />
209
487
  </div>
488
+ </div>
210
489
  );
211
490
  }
212
491
 
213
-
214
- export function decodeIsoDatetime(isoStringOrTimesnap, type) {
492
+ export function decodeIsoDatetime(isoStringOrTimesnap, type, dateMode = 'day') {
215
493
  if (!isoStringOrTimesnap) {
216
494
  return null;
217
495
  }
@@ -246,7 +524,47 @@ export function decodeIsoDatetime(isoStringOrTimesnap, type) {
246
524
  } else {
247
525
  return moment(isoStringOrTimesnap).format('HH:mm');
248
526
  }
249
- } else {
250
- return moment(isoStringOrTimesnap).format('YYYY-MM-DD');
527
+ } else {
528
+ return moment(isoStringOrTimesnap).format(getDateModeFormat(dateMode));
251
529
  }
252
530
  }
531
+
532
+ /**
533
+ * 根据时间模式,将 picker 返回的值转成对应的 年-月-日
534
+ */
535
+ export const formatDateModeValue = (result = [], dateMode = 'day') => {
536
+ let [year, month, day] = [
537
+ result[0]?.value,
538
+ result[1]?.value || 1,
539
+ result[2]?.value || 1,
540
+ ];
541
+ if (dateMode === 'year') {
542
+ month = 1;
543
+ day = 1;
544
+ }
545
+ if (dateMode === 'month') {
546
+ day = 1;
547
+ }
548
+ const value = moment()
549
+ .year(year)
550
+ .month(month - 1)
551
+ .date(day)
552
+ .format(getDateModeFormat(dateMode));
553
+ return value;
554
+ };
555
+
556
+ /**
557
+ * 不同时间模式对应的展示格式
558
+ */
559
+ export const getDateModeFormat = (dateMode = 'day') => {
560
+ switch (dateMode) {
561
+ case 'year':
562
+ return 'YYYY';
563
+ case 'month':
564
+ return 'YYYY-MM';
565
+ case 'day':
566
+ return 'YYYY-MM-DD';
567
+ default:
568
+ return 'YYYY-MM-DD';
569
+ }
570
+ };
@@ -0,0 +1,10 @@
1
+ .year-picker__overlay {
2
+ width: 300px;
3
+ }
4
+
5
+ .year-picker__overlay .year-picker__header {
6
+ display: flex;
7
+ justify-content: space-between;
8
+ align-items: center;
9
+ font-weight: 700;
10
+ }