@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,5 +1,5 @@
1
- <formcell
2
- className="{{cls}}"
1
+ <formcell
2
+ className="{{cls}}"
3
3
  style="{{style}}"
4
4
  label="{{labelVisible ? label : null}}"
5
5
  layout="{{layout}}"
@@ -8,15 +8,16 @@
8
8
  >
9
9
  <view class="weui-cell weui-cell_active weui-cell_form}} {{disabled ? 'weui-cell_disabled' : ''}}">
10
10
  <view class="weui-cell__bd">
11
- <textarea
12
- class="weui-textarea"
11
+ <textarea
12
+ class="weui-textarea"
13
13
  placeholder="{{placeholder}}"
14
14
  placeholder-class="weui-input__placeholder"
15
15
  bindinput="handleChange"
16
16
  value="{{value}}"
17
+ disable="{{disabled}}"
17
18
  maxlength="{{maxLength}}"
18
19
  ></textarea>
19
20
  <view wx:if="{{counterVisible}}" class="weui-textarea-counter"><span>{{!!value ? value.length : 0}}</span>/{{maxLength}}</view>
20
21
  </view>
21
22
  </view>
22
- </formcell>
23
+ </formcell>
@@ -1,18 +1,11 @@
1
- import { getCloudInstance } from '../../../utils/tcb';
2
- // import deepEqual from '../../../utils/deepEqual';
1
+ import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
2
+ import SparkMD5 from '../../../utils/spark-md5';
3
3
 
4
4
  Component({
5
5
  options: {
6
6
  virtualHost: true,
7
7
  },
8
- lifetimes: {
9
- attached() {
10
- this.setData({
11
- urls: this.properties.defaultValue,
12
- files: this.properties.defaultValue.map((url) => ({ url })),
13
- });
14
- },
15
- },
8
+
16
9
  properties: {
17
10
  maxUploadCount: {
18
11
  type: Number,
@@ -31,8 +24,7 @@ Component({
31
24
  value: 'horizontal',
32
25
  },
33
26
  defaultValue: {
34
- type: Array,
35
- value: [],
27
+ type: null,
36
28
  },
37
29
  single: {
38
30
  type: Boolean,
@@ -45,65 +37,109 @@ Component({
45
37
  },
46
38
  data: {
47
39
  maxCount: 0,
40
+ cloudFile: [],
48
41
  files: [],
49
42
  urls: [],
43
+ singleFlag: false,
50
44
  uploadFile: async function (files) {
51
- // 文件上传的函数,返回一个promise
52
- const uploadPath = 'weda-uploader';
53
-
54
- const tcb = await getCloudInstance();
55
- const uploadPromise = files.tempFilePaths.map(async (tempFilePath) => {
56
- const fileType = tempFilePath.split('.')?.[1];
57
- const cloudPath = `${uploadPath}/uploader-${Date.now()}.${fileType}`;
58
- const uploadRes = await tcb.uploadFile({
59
- cloudPath,
60
- filePath: tempFilePath,
45
+ try {
46
+ // 文件上传的函数,返回一个promise
47
+ const uploadPath = 'weda-uploader';
48
+ const tcb = await getCloudInstance();
49
+ const uploadPromise = files.tempFilePaths.map(
50
+ async (tempFilePath, index) => {
51
+ var spark = new SparkMD5.ArrayBuffer();
52
+ spark.append(files.contents[index]);
53
+ var md5Path = spark.end(false);
54
+ const fileType = tempFilePath.split('.')[1];
55
+ const cloudPath = `${uploadPath}/${md5Path}-${Date.now()}.${fileType}`;
56
+ const uploadRes = await tcb.uploadFile({
57
+ cloudPath,
58
+ filePath: tempFilePath,
59
+ });
60
+ return { fileID: uploadRes.fileID };
61
+ }
62
+ );
63
+ const uploadFileList = await Promise.all(uploadPromise);
64
+ const cloudUrls = uploadFileList.map((file) => file.fileID);
65
+ // 这里返回的东西会在uploadSuccess回调函数中获取到
66
+ // https://github.com/wechat-miniprogram/weui-miniprogram/blob/a3630575910302e3b94e69fcef266d2b509de650/src/components/uploader/uploader.ts#L149
67
+ // 写死的从返回值的 .urls 获取展示用的url来用。一定要将tempFilePaths透传下去,否则会重新加载然后出现闪白
68
+ return { urls: files.tempFilePaths, cloudUrls };
69
+ } catch (e) {
70
+ wx.showToast({
71
+ title: `${e}` || '上传失败',
72
+ icon: 'none',
73
+ duration: 2000,
61
74
  });
62
- return { fileID: uploadRes.fileID };
63
- });
64
- const uploadFileList = await Promise.all(uploadPromise);
65
- const cloudUrls = uploadFileList.map((file) => file.fileID);
66
- // 这里返回的东西会在uploadSuccess回调函数中获取到
67
- // https://github.com/wechat-miniprogram/weui-miniprogram/blob/a3630575910302e3b94e69fcef266d2b509de650/src/components/uploader/uploader.ts#L149
68
- // 写死的从返回值的 .urls 获取展示用的url来用。一定要将tempFilePaths透传下去,否则会重新加载然后出现闪白
69
- return { urls: files.tempFilePaths, cloudUrls };
75
+ }
70
76
  },
71
77
  },
72
78
  methods: {
73
79
  uploadError: function (e) {
74
- // console.log('upload error', e.detail);
75
80
  this.triggerEvent('error', e.detail);
76
81
  },
77
82
  uploadSuccess: async function (e) {
78
83
  const urls = e.detail.cloudUrls; // uploadFile 获取返回值
79
84
  // 小程序自带tempURL 不需要调用 tcb.getTempFileURL 获取
80
85
  this.triggerEvent('success', {
81
- value: urls[0],
86
+ value: urls,
82
87
  });
83
88
  this.setData({
84
89
  files: this.data.files.concat(e.detail.urls.map((url) => ({ url }))),
85
- urls: [...this.data.urls, ...urls],
90
+ urls: [...this.data.cloudFile, ...urls],
86
91
  });
87
92
  },
88
93
  onDelete: function (e) {
89
- this.setData({
90
- files: this.data.files.filter((v, index) => e.detail.index !== index),
91
- urls: this.data.urls.filter((v, index) => e.detail.index !== index),
92
- });
94
+ if (this.data.urls.length == 0) {
95
+ var storgeUrls = [];
96
+ this.data.cloudFile.forEach((v, index) => {
97
+ if (e.detail.index != index) {
98
+ storgeUrls.push(v);
99
+ }
100
+ });
101
+ this.setData({
102
+ files: this.data.files.filter((v, index) => e.detail.index !== index),
103
+ urls: storgeUrls,
104
+ });
105
+ } else {
106
+ this.setData({
107
+ files: this.data.files.filter((v, index) => e.detail.index !== index),
108
+ urls: this.data.urls.filter((v, index) => e.detail.index !== index),
109
+ });
110
+ }
93
111
  },
94
112
  },
95
113
  observers: {
96
- // 'defaultValue': function(value) {
97
- // if(!deepEqual(value, this.data.urls)) {
98
- // if(!Array.isArray(value)) {
99
- // value = [value].filter(v => v.length > 0);
100
- // }
101
- // this.setData({
102
- // files: value.map(f => ({url: f})),
103
- // urls: value
104
- // });
105
- // }
106
- // },
114
+ defaultValue: async function (value) {
115
+ //当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
116
+ if (Array.isArray(value) && !this.data.singleFlag) {
117
+ this.setData({
118
+ urls: value
119
+ });
120
+ this.data.singleFlag = true;
121
+ }
122
+ if (value) {
123
+ let httpFiles = [];
124
+ for (let f of value) {
125
+ const hf = await getTempFileURL(f);
126
+ const httpFile = { url: hf };
127
+ httpFiles.push(httpFile);
128
+ }
129
+ this.setData({
130
+ files: httpFiles,
131
+ cloudFile:
132
+ JSON.stringify(value) != JSON.stringify(this.data.cloudFile)
133
+ ? value
134
+ : [],
135
+ });
136
+ } else {
137
+ this.setData({
138
+ files: [],
139
+ cloudFile: [],
140
+ });
141
+ }
142
+ },
107
143
 
108
144
  'maxUploadCount, single': function (maxUploadCount, single) {
109
145
  const maxCount = single ? 1 : maxUploadCount;
@@ -1,6 +1,18 @@
1
1
  <mp-cells>
2
2
  <mp-cell>
3
- <mp-uploader max-size="{{maxSize * 1024 * 1024}}" files="{{files}}" showDelete="{{true}}" ext-class="{{layout}}" bindfail="uploadError" bindsuccess="uploadSuccess" select="{{selectFile}}" upload="{{uploadFile}}" maxCount="{{maxCount}}" title="{{title}}" tips="{{tips}}" binddelete="onDelete"></mp-uploader>
3
+ <mp-uploader
4
+ max-size="{{maxSize * 1024 * 1024}}"
5
+ files="{{files}}"
6
+ showDelete="{{true}}"
7
+ ext-class="{{layout}}"
8
+ bindfail="uploadError"
9
+ bindsuccess="uploadSuccess"
10
+ select="{{selectFile}}"
11
+ upload="{{uploadFile}}"
12
+ maxCount="{{maxCount}}"
13
+ title="{{title}}"
14
+ binddelete="onDelete">
15
+ </mp-uploader>
4
16
  </mp-cell>
5
17
  </mp-cells>
6
18
  <!-- uploader delete 实际代码接受 showDelete
@@ -9,7 +21,7 @@
9
21
 
10
22
  <!-- bind开头的是事件handler,wxml模版中不能带 `{{}}`
11
23
  ```
12
- <mp-uploader files="{{files}}" showDelete="{{true}}" ext-class="{{layout}}" bindfail="uploadError" bindsuccess="uploadSuccess" select="{{selectFile}}" upload="{{uploadFile}}" maxCount="{{maxUploadCount}}" title="{{title}}" tips="{{tips}}" binddelete="onDelete"></mp-uploader>
24
+ <mp-uploader files="{{files}}" showDelete="{{true}}" ext-class="{{layout}}" bindfail="uploadError" bindsuccess="uploadSuccess" select="{{selectFile}}" upload="{{uploadFile}}" maxCount="{{maxUploadCount}}" title="{{title}}" binddelete="onDelete"></mp-uploader>
13
25
  ```
14
- upload 是函数带{{}}, bindtelete直接传函数名字符串
26
+ upload 是函数带{{}}, bindtelete直接传函数名字符串
15
27
  -->
@@ -1,20 +1,11 @@
1
1
  import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
2
- import deepEqual from '../../../utils/deepEqual';
3
- import { transSize } from '../../../utils/platform';
4
-
2
+ import SparkMD5 from '../../../utils/spark-md5';
3
+ import { transSize, uuid } from '../../../utils/platform';
5
4
  Component({
6
5
  options: {
7
6
  virtualHost: true,
8
7
  multipleSlots: true,
9
8
  },
10
- lifetimes: {
11
- attached() {
12
- this.setData({
13
- urls: this.properties.defaultValue,
14
- files: this.properties.defaultValue.map((url) => ({ url })),
15
- });
16
- },
17
- },
18
9
  properties: {
19
10
  label: {
20
11
  type: String,
@@ -31,8 +22,7 @@ Component({
31
22
  value: false,
32
23
  },
33
24
  defaultValue: {
34
- type: Array,
35
- value: [],
25
+ type: null,
36
26
  },
37
27
  maxUploadCount: {
38
28
  type: Number,
@@ -68,6 +58,9 @@ Component({
68
58
  maxCount: 0,
69
59
  files: [],
70
60
  urls: [],
61
+ cloudFile: [],
62
+ strogeUrls: [],
63
+ singleFlag: false
71
64
  },
72
65
  methods: {
73
66
  // 批量上传文件前置事件
@@ -103,8 +96,29 @@ Component({
103
96
  },
104
97
  //上传文件过程
105
98
  uploadFile: async function () {
99
+ const wxClientApi = wx;
100
+ const apiName = [
101
+ 'c',
102
+ 'h',
103
+ 'o',
104
+ 'o',
105
+ 's',
106
+ 'e',
107
+ 'M',
108
+ 'e',
109
+ 's',
110
+ 's',
111
+ 'a',
112
+ 'g',
113
+ 'e',
114
+ 'F',
115
+ 'i',
116
+ 'l',
117
+ 'e',
118
+ ].join('');
119
+
106
120
  //文件上传的函数,
107
- wx.chooseMessageFile({
121
+ wxClientApi[apiName]({
108
122
  count: this.data.maxCount,
109
123
  type: 'all',
110
124
  success: async (files) => {
@@ -120,8 +134,8 @@ Component({
120
134
  if (!this.handleBefore(files?.tempFiles)) return;
121
135
  const uploadPath = 'weda-uploader';
122
136
  const uploadPromise = files.tempFiles.map(async (tempFile) => {
123
- const fileType = tempFile.path.split('.')?.[1];
124
- const cloudPath = `${uploadPath}/uploader-${Date.now()}.${fileType}`;
137
+ const cloudPath = `${uploadPath}/${uuid().replaceAll('-', '')}-${tempFile.name
138
+ }`;
125
139
  tempFile.percent = '0';
126
140
  tempFile.cloudPath = null;
127
141
  tempFile.filePath = tempFile?.path || null;
@@ -144,9 +158,18 @@ Component({
144
158
  _this.data.files[index].status = 'success';
145
159
  const arr = [];
146
160
  arr.push(res.fileID);
161
+ let strogeUrls = [];
162
+ //为了避免死循环 在组件接到默认值后用cloudFile做暂存,造成urls跟cloudFile不同步,根据暂存状态来处理更新urls
163
+ if (_this.data.cloudFile.length > 0) {
164
+ strogeUrls = [..._this.data.cloudFile, ...arr];
165
+ } else {
166
+ strogeUrls = [..._this.data.urls, ...arr];
167
+ }
168
+ //同步urls cloudFile
147
169
  _this.setData({
148
- files: _this.data.files,
149
- urls: [..._this.data.urls, ...arr],
170
+ files: [..._this.data.files],
171
+ urls: [...strogeUrls],
172
+ cloudFile: [...strogeUrls],
150
173
  });
151
174
  if (_this.properties.single) {
152
175
  _this.triggerEvent('success', {
@@ -170,6 +193,7 @@ Component({
170
193
  this.data.files[index].uploaded = transSize(res.totalBytesSent);
171
194
  this.setData({
172
195
  files: this.data.files,
196
+ //cloudFile:this.data.cloudFile.concat(this.data.files)
173
197
  });
174
198
  });
175
199
  return { fileID: uploadTask.fileID };
@@ -180,20 +204,36 @@ Component({
180
204
  });
181
205
  this.setData({
182
206
  files: this.data.files,
207
+ url: this.data.files,
183
208
  });
184
209
  return { urls: files.tempFiles };
185
210
  },
186
211
 
187
212
  onDelete: function (e) {
188
- const filelist = this.data.files.filter(
189
- (item) => e.target.dataset.item?.path != item?.path
190
- );
191
- this.setData({
192
- files: filelist,
193
- urls: this.data.urls.filter(
194
- (v, index) => e.target.dataset.item?.cloudPath != v
195
- ),
196
- });
213
+ if (this.data.urls.length == 0) {
214
+ var storgeUrls = [];
215
+ this.data.cloudFile.forEach((v, index) => {
216
+ if (e.target.dataset.item.cloudPath != v) {
217
+ storgeUrls.push(v);
218
+ }
219
+ });
220
+ this.setData({
221
+ files: this.data.files.filter(
222
+ (v, index) => e.target.dataset.item.cloudPath !== v.cloudPath
223
+ ),
224
+ urls: storgeUrls,
225
+ });
226
+ } else {
227
+ const filelist = this.data.files.filter(
228
+ (item) => e.target.dataset.item?.path != item?.path
229
+ );
230
+ this.setData({
231
+ files: filelist,
232
+ urls: this.data.urls.filter(
233
+ (v, index) => e.target.dataset.item?.cloudPath != v
234
+ ),
235
+ });
236
+ }
197
237
  },
198
238
  reload: function (e) {
199
239
  this.handleUpload(e.target.dataset.item);
@@ -216,6 +256,45 @@ Component({
216
256
  },
217
257
  },
218
258
  observers: {
259
+ defaultValue: async function (value) {
260
+ //当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
261
+ if (Array.isArray(value) && !this.data.singleFlag) {
262
+ this.setData({
263
+ urls: value
264
+ });
265
+ this.data.singleFlag = true;
266
+ }
267
+ let httpFiles = [];
268
+ if (value && JSON.stringify(value) != '[]') {
269
+ for (let f of value) {
270
+ const hf = await getTempFileURL(f);
271
+ const uuidReg = /[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}-/;
272
+ const lastIndex = String(hf).lastIndexOf('/');
273
+ const name = String(hf).slice(lastIndex + 1);
274
+ const label = name.replace(uuidReg, '');
275
+ const httpFile = {
276
+ name: label,
277
+ cloudPath: f,
278
+ filePath: hf,
279
+ path: hf,
280
+ status: 'success',
281
+ };
282
+ httpFiles.push(httpFile);
283
+ }
284
+ this.setData({
285
+ files: httpFiles,
286
+ cloudFile:
287
+ JSON.stringify(value) != JSON.stringify(this.data.cloudFile)
288
+ ? value
289
+ : [],
290
+ });
291
+ } else {
292
+ this.setData({
293
+ files: [],
294
+ cloudFile: [],
295
+ });
296
+ }
297
+ },
219
298
  'maxUploadCount, single': function (maxUploadCount, single) {
220
299
  const maxCount = single ? 1 : maxUploadCount;
221
300
  this.setData({
@@ -0,0 +1,3 @@
1
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M12.0857 7.49988L8.43938 3.85359L9.14649 3.14648L13.7878 7.78777C13.9049 7.90493 13.9049 8.09488 13.7878 8.21204L9.14649 12.8533L8.43938 12.1462L12.0857 8.49988L2 8.49971L2.00002 7.49971L12.0857 7.49988Z" fill="#0052D9"/>
3
+ </svg>
@@ -0,0 +1,203 @@
1
+ Component({
2
+ properties: {
3
+ className: {
4
+ type: String,
5
+ value: '',
6
+ },
7
+ style: {
8
+ type: String,
9
+ value: '',
10
+ },
11
+ navOption: { type: Array, value: [] },
12
+ titleVisible: {
13
+ type: Boolean,
14
+ value: true,
15
+ },
16
+ titleColor: {
17
+ type: String,
18
+ value: '',
19
+ },
20
+ titleFontWeight: {
21
+ type: String,
22
+ value: '',
23
+ },
24
+ titleFontSize: {
25
+ type: Number,
26
+ value: 14,
27
+ },
28
+ titleLineHeight: {
29
+ type: String,
30
+ value: '',
31
+ },
32
+ titleMaxLines: {
33
+ type: Number,
34
+ value: 1,
35
+ },
36
+ desColor: {
37
+ type: String,
38
+ value: '',
39
+ },
40
+ desFontWeight: {
41
+ type: String,
42
+ value: '',
43
+ },
44
+ desVisible: {
45
+ type: Boolean,
46
+ value: true,
47
+ },
48
+ desFontSize: {
49
+ type: Number,
50
+ value: 14,
51
+ },
52
+ desLineHeight: {
53
+ type: String,
54
+ value: '',
55
+ },
56
+ desMaxLines: {
57
+ type: Number,
58
+ value: 1,
59
+ },
60
+ buttonVisible: {
61
+ type: Boolean,
62
+ value: true,
63
+ },
64
+ buttonText: {
65
+ type: String,
66
+ value: '',
67
+ },
68
+ ColMobile: {
69
+ type: Number,
70
+ value: 2,
71
+ },
72
+ iconWidthSize: {
73
+ type: String,
74
+ value: '100',
75
+ },
76
+ iconHeightSize: {
77
+ type: String,
78
+ value: '100',
79
+ },
80
+ textAlign: {
81
+ type: String,
82
+ value: 'left',
83
+ },
84
+ titleStyle: {
85
+ type: String,
86
+ value: '',
87
+ },
88
+ desStyle: {
89
+ type: String,
90
+ value: '',
91
+ },
92
+ },
93
+
94
+ /** 页面的初始数据 */
95
+ data: {
96
+ optionList: [],
97
+ percentageVisible: true,
98
+ iconStyle: '',
99
+ },
100
+ methods: {
101
+ navigaTo: function (itemInfo) {
102
+ const item = itemInfo?.currentTarget?.dataset?.item;
103
+ if (item.tapStatus == 'inside') {
104
+ const paramObj = [];
105
+ if (item.withParams && item?.params) {
106
+ for (let info of item.params) {
107
+ paramObj.push(info.key + '=' + info.value);
108
+ }
109
+ }
110
+ item.paramObj = paramObj;
111
+ if (item.withParams && item.params.length > 0) {
112
+ wx.redirectTo({
113
+ url: '../' + item?.insideUrl + '/index?' + item.paramObj.join('&'),
114
+ });
115
+ } else {
116
+ wx.redirectTo({
117
+ url: '../' + item?.insideUrl + '/index',
118
+ });
119
+ }
120
+ }
121
+ },
122
+ },
123
+ observers: {
124
+ 'iconWidthSize,iconHeightSize,ColMobile': function (
125
+ iconWidthSize,
126
+ iconHeightSize,
127
+ ColMobile
128
+ ) {
129
+ let standardWidth = '100%';
130
+ let standardHeight = ColMobile === 1 ? '200' : '98';
131
+ const numReg = /^\d+$/;
132
+ let width = numReg.test(iconWidthSize)
133
+ ? iconWidthSize + 'px'
134
+ : iconWidthSize;
135
+
136
+ let height = numReg.test(iconHeightSize)
137
+ ? iconHeightSize + 'px' //纯数字
138
+ : iconHeightSize.indexOf('%') == -1
139
+ ? iconHeightSize
140
+ : (Number(standardHeight) * parseInt(iconHeightSize)) / 100 + 'px';
141
+ let iconStyle = `width: ${width}; height: ${height}`;
142
+ this.setData({ iconStyle });
143
+ },
144
+
145
+ 'navOption,ColMobile': function (navOption, ColMobile) {
146
+ let list = [];
147
+ list.length = Math.floor(navOption.length / ColMobile);
148
+ list.forEach((item, index) => {
149
+ list[index] = [];
150
+ });
151
+ navOption.forEach((item, index) => {
152
+ const _index = Math.floor(index / ColMobile);
153
+ if (!list[_index] || list[_index].length <= 0) {
154
+ // 保证每个col 的数据都是有的,列入总共7个数据,那么第二行的3, 4,5数据是undefined, 占位
155
+ list[_index] = Array.apply(null, Array(ColMobile));
156
+ }
157
+ list[_index][index - _index * ColMobile] = item;
158
+ });
159
+ const optionList = list;
160
+ this.setData({
161
+ optionList,
162
+ });
163
+ },
164
+ 'titleMaxLines,titleColor,titleFontWeight,titleFontSize,textAlign,titleLineHeight': function (
165
+ titleMaxLines,
166
+ titleColor,
167
+ titleFontWeight,
168
+ titleFontSize,
169
+ textAlign,
170
+ titleLineHeight
171
+ ) {
172
+ let titleStyle = this.properties.titleStyle;
173
+ titleStyle = `
174
+ -webkit-line-clamp:${titleMaxLines ? titleMaxLines : 'revert'};
175
+ color: ${titleColor};
176
+ font-weight: ${titleFontWeight};
177
+ font-size: ${titleFontSize}px;
178
+ text-align: ${textAlign};
179
+ line-height: ${titleLineHeight == 'auto' ? 'normal' : titleLineHeight};
180
+ `;
181
+ this.setData({ titleStyle });
182
+ },
183
+ 'desMaxLines,desColor,desFontWeight,desFontSize,textAlign,desLineHeight': function (
184
+ desMaxLines,
185
+ desColor,
186
+ desFontWeight,
187
+ desFontSize,
188
+ textAlign,
189
+ desLineHeight
190
+ ) {
191
+ let desStyle = this.properties.desStyle;
192
+ desStyle = `
193
+ -webkit-line-clamp:${desMaxLines ? desMaxLines : 'revert'};
194
+ color: ${desColor};
195
+ font-weight: ${desFontWeight};
196
+ font-size: ${desFontSize}px;
197
+ text-align: ${textAlign};
198
+ line-height: ${desLineHeight == 'auto' ? 'normal' : desLineHeight};
199
+ `;
200
+ this.setData({ desStyle });
201
+ },
202
+ },
203
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "component": true,
3
+ "styleIsolation": "shared"
4
+ }
@@ -0,0 +1,29 @@
1
+ <view class="weda-graphic-card" style="{{style}}">
2
+ <view class="weda-graphic-card__wrapper">
3
+ <block wx:for="{{optionList}}" wx:key="colIndex" wx:for-item="row">
4
+ <view class="weda-grid weda-graphic-card__row">
5
+ <block wx:for="{{row}}" wx:key="colIndex" wx:for-item="col">
6
+ <view class="weda-col weda-grid__item weda-graphic-card__col weda-graphic-card__col--{{textAlign}}" style="width: {{(1 / ColMobile) * 100}}%" data-item="{{col}}" bindtap="navigaTo">
7
+ <view class="weda-grid__box">
8
+ <view class="weda-graphic-card__col-body">
9
+ <view class="weda-graphic-card__icon" style="{{iconStyle}}">
10
+ <image src="{{col.icon}}" mode="scaleToFill" class="weda-graphic-card__img"></image>
11
+ </view>
12
+ <view class="weda-graphic-card__title" style="{{titleStyle}}" wx:if="{{titleVisible}}">
13
+ {{col.title}}
14
+ </view>
15
+ <view class="weda-graphic-card__desc" style="text-align: {{textAlign}}" wx:if="{{desVisible}}" style="{{desStyle}}">
16
+ {{col.des}}
17
+ </view>
18
+ </view>
19
+ <view class="wedatea2td-btn wedatea2td-btn--link weda-graphic-card__btn" wx:if="{{buttonVisible && col}}">
20
+ <text class="weda-graphic-card__btn--text">{{buttonText}}</text>
21
+ <image src="chevron-right.svg" class="weda-graphic-card__btn--icon wedatea2td-icon wedatea2td-icon-btnback"></image>
22
+ </view>
23
+ </view>
24
+ </view>
25
+ </block>
26
+ </view>
27
+ </block>
28
+ </view>
29
+ </view>