@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,40 +1,131 @@
1
- // 暂时把地区信息打包在本地, 后续移到COS桶内
2
- import {provinces} from './provinces';
3
- import {cities} from './cities';
4
- import {regions} from './regions';
5
1
  import weui from '../../../../utils/weui';
2
+ import { callWedaApi } from '../../../../utils/tcb';
6
3
 
7
4
  let tree;
8
5
 
9
- export function getRegionTree() {
10
- if (!tree) {
11
- tree = provinces.map((province) => {
12
- return {
13
- label: province.name,
14
- value: province.name,
15
- children: cities
16
- .filter((city) => city.parent_code === province.code)
17
- .map((city) => {
18
- return {
19
- label: city.name,
20
- value: city.name,
21
- children: regions
22
- .filter((region) => region.parent_code === city.code)
23
- .map((region) => {
24
- return {
25
- label: region.name,
26
- value: region.name,
27
- };
28
- }),
29
- };
30
- }),
31
- };
6
+ export async function getRegionTree(regionData,regionType,regionMode) {
7
+ tree = [];
8
+ tree = formatTreeData(regionData,regionType,regionMode);
9
+ return tree;
10
+ }
11
+
12
+ export function regionPicker(options,regionTree:any[]) {
13
+ const weRegionTree =regionTree.length==0?[{label:'地区数据加载中,请关闭弹窗后重试',value:null,children:null}]:regionTree;
14
+ weui.picker(weRegionTree, options);
15
+ }
16
+ /**
17
+ * 获取运行态地区数据
18
+ */
19
+ export async function getAreaCode() {
20
+ try {
21
+ const res = await callWedaApi({
22
+ action: 'QueryRuntimeAreaCode',
23
+ data: {Mask: "11100"},
32
24
  });
25
+ return res?.AreaCodeList;
26
+ } catch (error) {
27
+ console.error('错误', error);
28
+ return {};
33
29
  }
34
-
35
- return tree;
36
30
  }
31
+ /**
32
+ * 构建树形结构
33
+ */
34
+ function formatTreeData(arr,regionType,regionMode) {
35
+ let provicesData = [];
36
+ arr.forEach(item=>{
37
+ //省数据集合
38
+ if(item?.Type==1&&item?.Deprecated==false){
39
+ provicesData.push({
40
+ label: item.Value,
41
+ value: item.Value,
42
+ code:item.Code,
43
+ type:item.Type,
44
+ centralCity:item.CentralCity,
45
+ children: regionType!= 'levelOne'||regionMode=='region'?[{
46
+ label: item.Value,
47
+ value: item.Value,
48
+ code:item.Code,
49
+ type:item.Type,
50
+ children: regionType!= 'levelTwo'||regionMode=='region'?[{
51
+ label: item.Value,
52
+ value: item.Value,
53
+ code:item.Code,
54
+ type:item.Type,
55
+ centralCity:item.CentralCity,
56
+ }]:null
57
+ }]:null
58
+ });
59
+ }
60
+ });
61
+ if(regionType!= 'levelOne'||regionMode=='region'){
62
+ arr.forEach(item=>{
63
+ //市数据集合
64
+ if(item?.Type==2&&item?.Deprecated==false){
65
+ provicesData.map(provice=>{
66
+ if(provice.code.substr(0, 2) == item.Code.substr(0,2)){
67
+ if(provice['children'][0].type==1){
68
+ provice['children']=[];
69
+ }
70
+ provice['children'].push({
71
+ label: item.Value,
72
+ value: item.Value,
73
+ code:item.Code,
74
+ type:item.Type,
75
+ centralCity:item.CentralCity,
76
+ children: regionType!= 'levelTwo'||regionMode=='region'?[{
77
+ label: item.Value,
78
+ value: item.Value,
79
+ code:item.Code,
80
+ type:item.Type,
81
+ centralCity:item.CentralCity,
82
+ }]:null
83
+ });
37
84
 
38
- export function regionPicker(options) {
39
- weui.picker(getRegionTree(), options);
85
+ }
86
+ });
87
+ }
88
+ });
89
+ if(regionType != 'levelTwo'||regionMode=='region'){
90
+ arr.forEach(item=>{
91
+ //区数据集合
92
+ if(item?.Type==3&&item?.Deprecated==false){
93
+ provicesData.map(provice=>{
94
+ if(provice.centralCity){
95
+ provice.children.map(city=>{
96
+ if(city.code.substr(0, 2) == item.Code.substr(0,2)){
97
+ if(city['children'][0].type==1){
98
+ city['children']=[];
99
+ }
100
+ city['children'].push({
101
+ label: item.Value,
102
+ value: item.Value,
103
+ code:item.Code,
104
+ //type:item.Type
105
+ });
106
+
107
+ }});
108
+ }else{
109
+ provice.children.map(city=>{
110
+ if(city.code.substr(0, 4) == item.Code.substr(0,4)){
111
+ if(city['children'][0].type==2){
112
+ city['children']=[];
113
+ }
114
+ city['children'].push({
115
+ label: item.Value,
116
+ value: item.Value,
117
+ code:item.Code,
118
+ //type:item.Type
119
+ });
120
+
121
+ }});
122
+ }
123
+
124
+ });
125
+ }
126
+ });
127
+ }
128
+
129
+ }
130
+ return provicesData;
40
131
  }
@@ -48,8 +48,98 @@ export function timePicker(options) {
48
48
  ];
49
49
  weui.picker(hours, {
50
50
  ...options,
51
+ id: String(Date.now()),
51
52
  start: [startHour, startMin],
52
53
  end: [endHour, endMin],
53
54
  defaultValue,
54
55
  });
55
56
  }
57
+
58
+ /**
59
+ * 年选择器
60
+ */
61
+ export function yearPicker(options) {
62
+ const { startDate, endDate, defaultDate } = options;
63
+ if (startDate > endDate) {
64
+ throw 'startDate is bigger then endDate';
65
+ }
66
+ // 当前年
67
+ const currentYear = new Date().getFullYear();
68
+ // 默认传入年
69
+ const defaultYear = defaultDate
70
+ ? new Date(defaultDate).getFullYear()
71
+ : currentYear;
72
+ // 最小年份
73
+ const minYear = startDate
74
+ ? new Date(startDate).getFullYear()
75
+ : currentYear - 100;
76
+ // 最大年份
77
+ const maxYear = endDate ? new Date(endDate).getFullYear() : currentYear + 100;
78
+ const years = Array.from({ length: maxYear - minYear + 1 }).map(
79
+ (item, index) => ({
80
+ label: `${minYear + index}年`,
81
+ value: minYear + index,
82
+ })
83
+ );
84
+ weui.picker(years, {
85
+ ...options,
86
+ defaultValue: [defaultYear],
87
+ });
88
+ }
89
+
90
+ /**
91
+ * 年月选择器
92
+ */
93
+ export function monthPicker(options) {
94
+ const { startDate, endDate, defaultDate } = options;
95
+ if (startDate > endDate) {
96
+ throw 'startDate is bigger then endDate';
97
+ }
98
+ const _getYear = (d) => d.getFullYear();
99
+ const _getMonth = (d) => d.getMonth() + 1;
100
+ // 当前年月
101
+ const now = new Date();
102
+ const [currentYear, currentMonth] = [_getYear(now), _getMonth(now)];
103
+ // 默认传入年月
104
+ const def = defaultDate ? new Date(defaultDate) : now;
105
+ const [defaultYear, defaultMonth] = [_getYear(def), _getMonth(def)];
106
+ // 最小年月
107
+ const min = startDate && new Date(startDate);
108
+ const [minYear, minMonth] = [
109
+ min ? _getYear(min) : currentYear - 100,
110
+ min ? _getMonth(min) : 1,
111
+ ];
112
+ // 最大年月
113
+ const max = endDate && new Date(endDate);
114
+ const [maxYear, maxMonth] = [
115
+ max ? _getYear(max) : currentYear + 100,
116
+ max ? _getMonth(max) : 12,
117
+ ];
118
+ // 年份月份
119
+ const years = Array.from({ length: maxYear - minYear + 1 }).map((item, i) => {
120
+ const year = i + minYear;
121
+ let months = [];
122
+ let [minMonthWithYear, maxMonthWithYear] = [1, 12];
123
+ if (year === minYear) {
124
+ minMonthWithYear = Math.max(minMonth, 1);
125
+ }
126
+ if (year === maxYear) {
127
+ maxMonthWithYear = Math.min(maxMonth, 12);
128
+ }
129
+ months = Array.from({
130
+ length: maxMonthWithYear - minMonthWithYear + 1,
131
+ }).map((item, i) => ({
132
+ label: `${i + minMonthWithYear}月`,
133
+ value: i + minMonthWithYear,
134
+ }));
135
+ return {
136
+ label: `${i + minYear}年`,
137
+ value: i + minYear,
138
+ children: months,
139
+ };
140
+ });
141
+ weui.picker(years, {
142
+ ...options,
143
+ defaultValue: [defaultYear, defaultMonth],
144
+ });
145
+ }
@@ -0,0 +1,170 @@
1
+ import * as React from 'react';
2
+ import {
3
+ Popover,
4
+ ConfigProvider,
5
+ useConfig,
6
+ Input,
7
+ Icon,
8
+ Button,
9
+ } from 'tea-component';
10
+ import classNames from '../../../utils/classnames';
11
+ import { moment } from './index';
12
+ import './index.css';
13
+
14
+ /**
15
+ * pc 版简易年份选择器
16
+ * 传参与 DatePicker 保持一致
17
+ */
18
+ export default function YearPicker(props) {
19
+ const {
20
+ range = [],
21
+ disabled,
22
+ value,
23
+ onChange,
24
+ className,
25
+ placeholder,
26
+ ...rest
27
+ } = props;
28
+ const { classPrefix } = useConfig();
29
+ const inputRef = React.useRef(null);
30
+ const [show, setShow] = React.useState(false);
31
+ const [page, setPage] = React.useState(0);
32
+ const [inputValue, setInputValue] = React.useState(transValueToYear(value));
33
+ const { pageYears, pageStart, pageEnd } = getYears(inputValue, page);
34
+ const [min, max] = [
35
+ transValueToYear(range?.[0]),
36
+ transValueToYear(range?.[1]),
37
+ ];
38
+
39
+ React.useEffect(() => {
40
+ setInputValue(transValueToYear(value));
41
+ }, [value]);
42
+
43
+ return (
44
+ <ConfigProvider classPrefix="wedatea2td">
45
+ <Popover
46
+ trigger="click"
47
+ visible={show}
48
+ onVisibleChange={(v) => !v && setShow(v)}
49
+ overlay={
50
+ <div
51
+ className={classNames(
52
+ `${classPrefix}-dropdown-box`,
53
+ 'year-picker__overlay'
54
+ )}
55
+ >
56
+ <div
57
+ className={classNames(
58
+ `${classPrefix}-calendar__caption`,
59
+ 'year-picker__header'
60
+ )}
61
+ >
62
+ <div className="year-picker__header-title">
63
+ {pageStart}-{pageEnd}
64
+ </div>
65
+ <div className="year-picker__header-actions">
66
+ <Button
67
+ type="link"
68
+ icon="arrowleft"
69
+ title="上二十年"
70
+ onClick={() => setPage((d) => d - 1)}
71
+ />
72
+ <Button
73
+ type="link"
74
+ icon="cur-active"
75
+ title="当前二十年"
76
+ onClick={() => setPage(0)}
77
+ />
78
+ <Button
79
+ type="link"
80
+ icon="arrowright"
81
+ title="下二十年"
82
+ onClick={() => setPage((d) => d + 1)}
83
+ />
84
+ </div>
85
+ </div>
86
+ <div
87
+ className={classNames(
88
+ `${classPrefix}-calendar__type--year`,
89
+ 'year-picker__body'
90
+ )}
91
+ >
92
+ {pageYears.map((list) => (
93
+ <div
94
+ key={list.join()}
95
+ className={classNames(`${classPrefix}-calendar__row`)}
96
+ >
97
+ {list.map((item) => {
98
+ const isSelected = item === inputValue;
99
+ const isDisabled =
100
+ (min && Number(item) < Number(min)) ||
101
+ (max && Number(item) > Number(max));
102
+ return (
103
+ <div
104
+ key={item}
105
+ className={classNames(
106
+ `${classPrefix}-calendar__cell`,
107
+ 'year-picker__cell',
108
+ {
109
+ 'is-selected': isSelected,
110
+ 'is-disabled': isDisabled,
111
+ }
112
+ )}
113
+ onClick={() => {
114
+ if (isDisabled) return;
115
+ setShow(false);
116
+ setInputValue(item);
117
+ onChange?.(moment(item));
118
+ }}
119
+ >
120
+ <span>{item}</span>
121
+ </div>
122
+ );
123
+ })}
124
+ </div>
125
+ ))}
126
+ </div>
127
+ </div>
128
+ }
129
+ >
130
+ <div
131
+ // eslint-disable-next-line react/jsx-props-no-spreading
132
+ {...rest}
133
+ onClick={() => !disabled && setShow(true)}
134
+ className={classNames(`${classPrefix}-datepicker`, className)}
135
+ >
136
+ <div className={classNames(`${classPrefix}-datepicker__input`)}>
137
+ <Input
138
+ ref={inputRef}
139
+ disabled={disabled}
140
+ placeholder={placeholder}
141
+ value={inputValue}
142
+ onFocus={() => inputRef.current.blur()}
143
+ />
144
+ <Icon type="dismiss" />
145
+ </div>
146
+ </div>
147
+ </Popover>
148
+ </ConfigProvider>
149
+ );
150
+ }
151
+
152
+ /**
153
+ * 获取当前20年,page 表示分页,1表示下一页,-1表示上一页
154
+ * @returns [][]
155
+ */
156
+ const getYears = (currentYear, page = 0, range = []) => {
157
+ currentYear = currentYear || new Date().getFullYear();
158
+ const startYear = (Math.floor(parseInt(currentYear) / 20) + page) * 20;
159
+ const pageYears = Array.from({ length: 5 }).map((item, i1) =>
160
+ Array.from({ length: 4 }).map((item, i2) => i1 * 4 + i2 + startYear + '')
161
+ );
162
+ return { pageYears, pageStart: startYear, pageEnd: startYear + 20 - 1 };
163
+ };
164
+
165
+ /**
166
+ * 输入 moment 值转 string 年份
167
+ */
168
+ const transValueToYear = (val) => {
169
+ return moment.isMoment(val) ? val.format('YYYY') : '';
170
+ };
@@ -7,6 +7,7 @@ import { useSyncValue } from '../../../utils/useSyncValue';
7
7
  import { isCloudFileID } from '../../../utils/platform';
8
8
  import { IMAGE_TYPES } from './uploader.pc';
9
9
  import { CommonFormPropsType } from '../types';
10
+ import { v4 } from 'uuid';
10
11
 
11
12
  const uploadPath = 'weda-uploader';
12
13
  /**
@@ -39,7 +40,12 @@ export function ImageUploaderH5({
39
40
  //上传进度
40
41
  const [progress, setProgress] = React.useState(0);
41
42
  const [inputValue, setInputValue] = useSyncValue(defaultValue, isObjectEqual);
43
+
42
44
  const fileIdList = React.useMemo(() => {
45
+ //兼容h5默认值为空时情况
46
+ if (inputValue === null) {
47
+ setInputValue('');
48
+ }
43
49
  if (typeof inputValue === 'string') {
44
50
  // single = true 传入的是字符串
45
51
  return [inputValue].filter((i) => i.length > 0); // 排除空串
@@ -66,7 +72,7 @@ export function ImageUploaderH5({
66
72
  React.useEffect(() => {
67
73
  if (single) {
68
74
  const file = fileIdList[0] || '';
69
- file && onChange && onChange(file);
75
+ onChange && onChange(file);
70
76
  events.change && events.change({ value: file });
71
77
  } else {
72
78
  onChange && onChange(fileIdList);
@@ -88,7 +94,9 @@ export function ImageUploaderH5({
88
94
  getCloudInstance().then(async (tcb) => {
89
95
  try {
90
96
  const fileType = file.type.split('/')?.[1];
91
- const cloudPath = `${uploadPath}/uploader-${Date.now()}.${fileType}`;
97
+ const cloudPath = `${uploadPath}/${v4().replaceAll('-', '')}-${
98
+ file?.name
99
+ }`;
92
100
  const { fileID } = await tcb.uploadFile({
93
101
  cloudPath,
94
102
  filePath: file,
@@ -98,6 +106,7 @@ export function ImageUploaderH5({
98
106
  fileID && setInputValue((list) => [...list, fileID]);
99
107
  fileID && events.success && events.success({ value: fileID, file });
100
108
  } catch (err) {
109
+ weui.alert(`${err}` || '上传失败');
101
110
  events.error && events.error(err);
102
111
  } finally {
103
112
  setUploading(false);
@@ -112,6 +121,13 @@ export function ImageUploaderH5({
112
121
  : Array.from(new Set(acceptTypes));
113
122
  }, [acceptTypes]);
114
123
 
124
+ const showAdd = React.useMemo(() => {
125
+ if(single) {
126
+ // single 模式时,仅当数组为空时显示
127
+ return fileIdList.length < 1;
128
+ }
129
+ return fileIdList.length < maxUploadCount;
130
+ }, [fileIdList, single, maxUploadCount]);
115
131
  return (
116
132
  <div className={cls} id={id} style={style}>
117
133
  <div className="weui-cell">
@@ -140,8 +156,7 @@ export function ImageUploaderH5({
140
156
  </li>
141
157
  )}
142
158
  </ul>
143
- {(fileIdList.length < maxUploadCount ||
144
- (single && fileIdList.length < 1)) && ( // single 模式时,仅当数组为空时显示
159
+ {showAdd && (
145
160
  <div className="weui-uploader__input-box">
146
161
  <input
147
162
  id="uploaderInput"
@@ -14,7 +14,6 @@ import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
14
14
  import { isCloudFileID } from '../../../utils/platform';
15
15
  import isObjectEqual from '../../../utils/isObjectEqual';
16
16
  import { H5UploaderProps } from './uploader.h5';
17
-
18
17
  // 默认组件类前缀
19
18
  export const CLASS_PREFIX = 'weda-uploader-pc';
20
19
  // 默认图片类型
@@ -81,7 +80,6 @@ export function UploaderPCInner(props) {
81
80
  // 文件列表
82
81
  const [fileIDList, setfileIDList] = React.useState([]);
83
82
  const fileRef = React.useRef(fileIDList);
84
-
85
83
  React.useEffect(() => {
86
84
  let initialValue = []
87
85
  .concat(defaultValue)
@@ -90,14 +88,14 @@ export function UploaderPCInner(props) {
90
88
  initialValue = initialValue[0] ? [initialValue[0]] : [];
91
89
  }
92
90
  setfileIDList(initialValue);
93
- }, []);
91
+ }, [defaultValue]);
94
92
 
95
93
  // 值变化事件
96
94
  React.useEffect(() => {
97
95
  if (!isObjectEqual(fileRef.current, fileIDList)) {
98
96
  if (single) {
99
97
  const file = fileIDList[0] || '';
100
- file && onChange && onChange(file);
98
+ onChange && onChange(file);
101
99
  events.change && events.change({ value: file });
102
100
  } else {
103
101
  onChange && onChange(fileIDList);
@@ -132,7 +130,9 @@ export function UploaderPCInner(props) {
132
130
  getCloudInstance().then(async (tcb) => {
133
131
  try {
134
132
  const fileType = file.type.split('/')?.[1];
135
- const cloudPath = `${uploadPath}/${uploadFileName}-${v4()}.${fileType}`;
133
+ const cloudPath = `${uploadPath}/${v4().replaceAll('-', '')}-${
134
+ file?.name
135
+ }`;
136
136
  const { fileID } = await tcb.uploadFile({
137
137
  cloudPath,
138
138
  filePath: file,
@@ -140,8 +140,9 @@ export function UploaderPCInner(props) {
140
140
  });
141
141
  fileID && setfileIDList((list) => [...list, fileID]);
142
142
  fileID && events.success && events.success({ value: fileID, file });
143
- } catch (e) {
144
- events.error && events.error({ value: e, file });
143
+ } catch (err) {
144
+ message.error({ content: `${err}` || '上传失败' });
145
+ events.error && events.error(err);
145
146
  } finally {
146
147
  setUploading(false);
147
148
  setProgress(0);