@cloudbase/weda-ui 0.2.16 → 1.0.24

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 (194) hide show
  1. package/README.md +41 -169
  2. package/package.json +23 -11
  3. package/src/configs/components/calendar.json +4 -1
  4. package/src/configs/components/chart/bar.json +724 -0
  5. package/src/configs/components/chart/line.json +679 -0
  6. package/src/configs/components/chart/pie.json +497 -0
  7. package/src/configs/components/chart/statisticsCard.json +61 -13
  8. package/src/configs/components/container.json +7 -2
  9. package/src/configs/components/dataView.json +21 -6
  10. package/src/configs/components/form/checkbox.json +97 -5
  11. package/src/configs/components/form/radio.json +96 -4
  12. package/src/configs/components/form/select.json +245 -11
  13. package/src/configs/components/graphicCard.json +84 -73
  14. package/src/configs/components/image.json +7 -2
  15. package/src/configs/components/link.json +19 -3
  16. package/src/configs/components/listView.json +65 -18
  17. package/src/configs/components/lottery.json +151 -0
  18. package/src/configs/components/modal.json +37 -5
  19. package/src/configs/components/navLayout.json +87 -75
  20. package/src/configs/components/navigationBar.json +59 -0
  21. package/src/configs/components/richtextview.json +4 -1
  22. package/src/configs/components/scrollVeiw.json +74 -22
  23. package/src/configs/components/swiper.json +4 -1
  24. package/src/configs/components/tabs.json +51 -8
  25. package/src/configs/components/text.json +33 -25
  26. package/src/configs/components/wxOpenApi/phone.json +141 -0
  27. package/src/configs/components/wxOpenApi/phoneCode.json +121 -0
  28. package/src/configs/components/wxOpenApi/share.json +167 -0
  29. package/src/configs/components/wxOpenApi/userInfo.json +174 -0
  30. package/src/configs/index.js +20 -0
  31. package/src/index.js +2 -0
  32. package/src/mp/components/button/index.wxml +1 -2
  33. package/src/mp/components/chart/bar/index.js +258 -0
  34. package/src/mp/components/chart/bar/index.json +6 -0
  35. package/src/mp/components/chart/bar/index.wxml +3 -0
  36. package/src/mp/components/chart/bar/index.wxss +9 -0
  37. package/src/mp/components/chart/common/config/bar.js +50 -0
  38. package/src/mp/components/chart/common/config/global.js +16 -0
  39. package/src/mp/components/chart/common/config/line.js +48 -0
  40. package/src/mp/components/chart/common/config/pie.js +36 -0
  41. package/src/mp/components/chart/common/core/eChartBar.js +263 -0
  42. package/src/mp/components/chart/common/core/eChartBase.js +375 -0
  43. package/src/mp/components/chart/common/core/eChartLine.js +229 -0
  44. package/src/mp/components/chart/common/core/eChartPie.js +166 -0
  45. package/src/mp/components/chart/common/lib/echarts.min.js +18 -0
  46. package/src/mp/components/chart/ec-canvas/ec-canvas.js +277 -0
  47. package/src/mp/components/chart/ec-canvas/ec-canvas.json +4 -0
  48. package/src/mp/components/chart/ec-canvas/ec-canvas.wxml +4 -0
  49. package/src/mp/components/chart/ec-canvas/ec-canvas.wxss +4 -0
  50. package/src/mp/components/chart/ec-canvas/wx-canvas.js +107 -0
  51. package/src/mp/components/chart/line/index.js +247 -0
  52. package/src/mp/components/chart/line/index.json +6 -0
  53. package/src/mp/components/chart/line/index.wxml +3 -0
  54. package/src/mp/components/chart/line/index.wxss +9 -0
  55. package/src/mp/components/chart/pie/index.js +182 -0
  56. package/src/mp/components/chart/pie/index.json +6 -0
  57. package/src/mp/components/chart/pie/index.wxml +4 -0
  58. package/src/mp/components/chart/pie/index.wxss +9 -0
  59. package/src/mp/components/chart/statisticsCard/index.js +33 -6
  60. package/src/mp/components/form/checkbox/index.js +41 -2
  61. package/src/mp/components/form/checkbox/index.wxml +1 -1
  62. package/src/mp/components/form/form/index.wxml +1 -2
  63. package/src/mp/components/form/input/index.js +1 -1
  64. package/src/mp/components/form/location/index.js +43 -2
  65. package/src/mp/components/form/radio/index.js +38 -0
  66. package/src/mp/components/form/select/index.js +348 -40
  67. package/src/mp/components/form/select/index.wxml +21 -6
  68. package/src/mp/components/form/select/region/index.js +101 -0
  69. package/src/mp/components/form/textarea/index.wxml +6 -5
  70. package/src/mp/components/form/uploader/index.js +76 -44
  71. package/src/mp/components/form/uploader/index.wxml +15 -3
  72. package/src/mp/components/form/uploaderFile/index.js +61 -29
  73. package/src/mp/components/graphicCard/index.js +26 -28
  74. package/src/mp/components/listView/index.js +52 -64
  75. package/src/mp/components/listView/index.wxml +2 -2
  76. package/src/mp/components/listView/index.wxss +5 -0
  77. package/src/mp/components/lottery/index.js +270 -0
  78. package/src/mp/components/lottery/index.json +4 -0
  79. package/src/mp/components/lottery/index.wxml +43 -0
  80. package/src/mp/components/lottery/index.wxss +317 -0
  81. package/src/mp/components/navLayout/index.js +3 -3
  82. package/src/mp/components/navigationBar/index.js +193 -0
  83. package/src/mp/components/navigationBar/index.json +6 -0
  84. package/src/mp/components/navigationBar/index.wxml +88 -0
  85. package/src/mp/components/navigationBar/index.wxss +1257 -0
  86. package/src/mp/components/tabs/index.js +7 -2
  87. package/src/mp/components/tabs/index.wxml +2 -1
  88. package/src/mp/components/text/index.js +0 -25
  89. package/src/mp/components/text/index.wxml +3 -3
  90. package/src/mp/components/wxOpenApi/phone/index.js +117 -0
  91. package/src/mp/components/wxOpenApi/phone/index.json +4 -0
  92. package/src/mp/components/wxOpenApi/phone/index.wxml +15 -0
  93. package/src/mp/components/wxOpenApi/phone/index.wxss +22 -0
  94. package/src/mp/components/wxOpenApi/phoneCode/index.js +89 -0
  95. package/src/mp/components/wxOpenApi/phoneCode/index.json +4 -0
  96. package/src/mp/components/wxOpenApi/phoneCode/index.wxml +15 -0
  97. package/src/mp/components/wxOpenApi/phoneCode/index.wxss +22 -0
  98. package/src/mp/components/wxOpenApi/share/index.js +117 -0
  99. package/src/mp/components/wxOpenApi/share/index.json +4 -0
  100. package/src/mp/components/wxOpenApi/share/index.wxml +15 -0
  101. package/src/mp/components/wxOpenApi/share/index.wxss +22 -0
  102. package/src/mp/components/wxOpenApi/userInfo/index.js +88 -0
  103. package/src/mp/components/wxOpenApi/userInfo/index.json +4 -0
  104. package/src/mp/components/wxOpenApi/userInfo/index.wxml +14 -0
  105. package/src/mp/components/wxOpenApi/userInfo/index.wxss +22 -0
  106. package/src/mp/index.json +10 -1
  107. package/src/mp/style/weda-ui.wxss +2 -0
  108. package/src/mp/utils/constant.js +15 -0
  109. package/src/mp/utils/destr.js +48 -0
  110. package/src/mp/utils/lodash.js +2 -0
  111. package/src/mp/utils/platform.js +25 -0
  112. package/src/mp/utils/tcb.js +44 -0
  113. package/src/setupTests.js +2 -1
  114. package/src/web/components/button/index.css +8 -1
  115. package/src/web/components/button/index.tsx +3 -2
  116. package/src/web/components/chart/bar/index.tsx +140 -0
  117. package/src/web/components/chart/common/config/bar.js +49 -0
  118. package/src/web/components/chart/common/config/global.js +16 -0
  119. package/src/web/components/chart/common/config/line.js +50 -0
  120. package/src/web/components/chart/common/config/pie.js +37 -0
  121. package/src/web/components/chart/common/core/eChartBar.js +265 -0
  122. package/src/web/components/chart/common/core/eChartBase.ts +383 -0
  123. package/src/web/components/chart/common/core/eChartLine.js +231 -0
  124. package/src/web/components/chart/common/core/eChartPie.js +170 -0
  125. package/src/web/components/chart/common/core/type.ts +34 -0
  126. package/src/web/components/chart/common/echart.css +106 -0
  127. package/src/web/components/chart/common/echarts.ts +33 -0
  128. package/src/web/components/chart/common/useChart.tsx +69 -0
  129. package/src/web/components/chart/line/index.tsx +136 -0
  130. package/src/web/components/chart/pie/index.tsx +99 -0
  131. package/src/web/components/chart/statisticsCard/index.tsx +29 -8
  132. package/src/web/components/form/checkbox/index.tsx +61 -23
  133. package/src/web/components/form/formcell/index.tsx +10 -5
  134. package/src/web/components/form/location/components/LocationH5/location.h5.jsx +3 -3
  135. package/src/web/components/form/location/components/LocationPC/location.PC.jsx +2 -2
  136. package/src/web/components/form/radio/index.tsx +90 -53
  137. package/src/web/components/form/select/h5.tsx +371 -72
  138. package/src/web/components/form/select/index.css +10 -0
  139. package/src/web/components/form/select/index.tsx +392 -145
  140. package/src/web/components/form/select/region/index.ts +122 -31
  141. package/src/web/components/form/select/time.jsx +90 -0
  142. package/src/web/components/form/select/year.tsx +170 -0
  143. package/src/web/components/form/tips/index.css +4 -0
  144. package/src/web/components/form/tips/index.tsx +4 -3
  145. package/src/web/components/form/uploader/uploader.h5.tsx +28 -19
  146. package/src/web/components/form/uploader/uploader.pc.tsx +17 -20
  147. package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +48 -44
  148. package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +28 -26
  149. package/src/web/components/graphicCard/index.css +1 -5
  150. package/src/web/components/graphicCard/index.tsx +4 -3
  151. package/src/web/components/image/image.tsx +1 -1
  152. package/src/web/components/image/index.tsx +1 -1
  153. package/src/web/components/index.js +13 -2
  154. package/src/web/components/link/index.tsx +6 -3
  155. package/src/web/components/listView/index.css +4 -0
  156. package/src/web/components/listView/index.tsx +10 -18
  157. package/src/web/components/lottery/index.css +327 -0
  158. package/src/web/components/lottery/index.tsx +567 -0
  159. package/src/web/components/lottery/lotteryUtil.ts +130 -0
  160. package/src/web/components/modal/index.tsx +3 -1
  161. package/src/web/components/navigationBar/chevron-right--double.svg +3 -0
  162. package/src/web/components/navigationBar/common.tsx +198 -0
  163. package/src/web/components/navigationBar/h5Menu.tsx +179 -0
  164. package/src/web/components/navigationBar/horizontalMenu.tsx +200 -0
  165. package/src/web/components/navigationBar/index.css +762 -0
  166. package/src/web/components/navigationBar/index.tsx +231 -0
  167. package/src/web/components/navigationBar/type.d.ts +111 -0
  168. package/src/web/components/navigationBar/verticalMenu.tsx +81 -0
  169. package/src/web/components/phone/index.css +0 -0
  170. package/src/web/components/phone/index.tsx +22 -0
  171. package/src/web/components/phoneCode/index.css +0 -0
  172. package/src/web/components/phoneCode/index.tsx +22 -0
  173. package/src/web/components/richTextView/index.tsx +3 -5
  174. package/src/web/components/share/index.css +0 -0
  175. package/src/web/components/share/index.tsx +38 -0
  176. package/src/web/components/tabs/index.tsx +2 -0
  177. package/src/web/components/tabs/tabs.h5.tsx +43 -33
  178. package/src/web/components/tabs/tabs.pc.tsx +23 -10
  179. package/src/web/components/text/index.tsx +6 -14
  180. package/src/web/components/userInfo/index.css +0 -0
  181. package/src/web/components/userInfo/index.tsx +30 -0
  182. package/src/web/utils/{constant.js → constant.ts} +17 -2
  183. package/src/web/utils/lodash.ts +2 -0
  184. package/src/web/utils/platform.js +10 -1
  185. package/src/web/utils/tcb.js +20 -6
  186. package/src/web/weda-ui.css +2 -0
  187. package/CHANGELOG.md +0 -240
  188. package/src/.DS_Store +0 -0
  189. package/src/configs/.DS_Store +0 -0
  190. package/src/mp/.gitignore +0 -10
  191. package/src/web/.DS_Store +0 -0
  192. package/src/web/components/form/select/region/cities.ts +0 -2410
  193. package/src/web/components/form/select/region/provinces.ts +0 -240
  194. package/src/web/components/form/select/region/regions.ts +0 -20645
@@ -24,8 +24,7 @@ Component({
24
24
  value: 'horizontal',
25
25
  },
26
26
  defaultValue: {
27
- type: Object,
28
- value: '',
27
+ type: null,
29
28
  },
30
29
  single: {
31
30
  type: Boolean,
@@ -41,30 +40,39 @@ Component({
41
40
  cloudFile: [],
42
41
  files: [],
43
42
  urls: [],
43
+ singleFlag: false,
44
44
  uploadFile: async function (files) {
45
- // 文件上传的函数,返回一个promise
46
- const uploadPath = 'weda-uploader';
47
- const tcb = await getCloudInstance();
48
- const uploadPromise = files.tempFilePaths.map(
49
- async (tempFilePath, index) => {
50
- var spark = new SparkMD5.ArrayBuffer();
51
- spark.append(files.contents[index]);
52
- var md5Path = spark.end(false);
53
- const fileType = tempFilePath.split('.')[1];
54
- const cloudPath = `${uploadPath}/${md5Path}-${Date.now()}.${fileType}`;
55
- const uploadRes = await tcb.uploadFile({
56
- cloudPath,
57
- filePath: tempFilePath,
58
- });
59
- return { fileID: uploadRes.fileID };
60
- }
61
- );
62
- const uploadFileList = await Promise.all(uploadPromise);
63
- const cloudUrls = uploadFileList.map((file) => file.fileID);
64
- // 这里返回的东西会在uploadSuccess回调函数中获取到
65
- // https://github.com/wechat-miniprogram/weui-miniprogram/blob/a3630575910302e3b94e69fcef266d2b509de650/src/components/uploader/uploader.ts#L149
66
- // 写死的从返回值的 .urls 获取展示用的url来用。一定要将tempFilePaths透传下去,否则会重新加载然后出现闪白
67
- return { urls: files.tempFilePaths, cloudUrls };
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,
74
+ });
75
+ }
68
76
  },
69
77
  },
70
78
  methods: {
@@ -75,7 +83,7 @@ Component({
75
83
  const urls = e.detail.cloudUrls; // uploadFile 获取返回值
76
84
  // 小程序自带tempURL 不需要调用 tcb.getTempFileURL 获取
77
85
  this.triggerEvent('success', {
78
- value: urls[0],
86
+ value: urls,
79
87
  });
80
88
  this.setData({
81
89
  files: this.data.files.concat(e.detail.urls.map((url) => ({ url }))),
@@ -83,30 +91,54 @@ Component({
83
91
  });
84
92
  },
85
93
  onDelete: function (e) {
86
- this.setData({
87
- files: this.data.files.filter((v, index) => e.detail.index !== index),
88
- urls: this.data.urls.filter((v, index) => e.detail.index !== index),
89
- });
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
+ }
90
111
  },
91
112
  },
92
113
  observers: {
93
114
  defaultValue: async function (value) {
94
- if (!Array.isArray(value)) {
95
- value = [value].filter((v) => v.length > 0);
115
+ //当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
116
+ if (Array.isArray(value) && !this.data.singleFlag) {
117
+ this.setData({
118
+ urls: value
119
+ });
120
+ this.data.singleFlag = true;
96
121
  }
97
- let httpFiles = [];
98
- for (let f of value) {
99
- const hf = await getTempFileURL(f);
100
- const httpFile = { url: hf };
101
- httpFiles.push(httpFile);
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
+ });
102
141
  }
103
- this.setData({
104
- files: httpFiles,
105
- cloudFile:
106
- JSON.stringify(value) != JSON.stringify(this.data.cloudFile)
107
- ? value
108
- : [],
109
- });
110
142
  },
111
143
 
112
144
  'maxUploadCount, single': function (maxUploadCount, single) {
@@ -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,6 +1,6 @@
1
1
  import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
2
2
  import SparkMD5 from '../../../utils/spark-md5';
3
- import { transSize } from '../../../utils/platform';
3
+ import { transSize, uuid } from '../../../utils/platform';
4
4
  Component({
5
5
  options: {
6
6
  virtualHost: true,
@@ -22,8 +22,7 @@ Component({
22
22
  value: false,
23
23
  },
24
24
  defaultValue: {
25
- type: Array,
26
- value: [],
25
+ type: null,
27
26
  },
28
27
  maxUploadCount: {
29
28
  type: Number,
@@ -60,6 +59,8 @@ Component({
60
59
  files: [],
61
60
  urls: [],
62
61
  cloudFile: [],
62
+ strogeUrls: [],
63
+ singleFlag: false
63
64
  },
64
65
  methods: {
65
66
  // 批量上传文件前置事件
@@ -133,13 +134,8 @@ Component({
133
134
  if (!this.handleBefore(files?.tempFiles)) return;
134
135
  const uploadPath = 'weda-uploader';
135
136
  const uploadPromise = files.tempFiles.map(async (tempFile) => {
136
- const res = wx
137
- .getFileSystemManager()
138
- .readFileSync(tempFile?.path, 'utf8', 0);
139
- var spark = new SparkMD5.ArrayBuffer();
140
- spark.append(res);
141
- var md5Path = spark.end(false);
142
- const cloudPath = `${uploadPath}/${md5Path}-${tempFile.name}`;
137
+ const cloudPath = `${uploadPath}/${uuid().replaceAll('-', '')}-${tempFile.name
138
+ }`;
143
139
  tempFile.percent = '0';
144
140
  tempFile.cloudPath = null;
145
141
  tempFile.filePath = tempFile?.path || null;
@@ -162,9 +158,18 @@ Component({
162
158
  _this.data.files[index].status = 'success';
163
159
  const arr = [];
164
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
165
169
  _this.setData({
166
- files: _this.data.files,
167
- urls: [..._this.data.cloudFile, ..._this.data.urls, ...arr],
170
+ files: [..._this.data.files],
171
+ urls: [...strogeUrls],
172
+ cloudFile: [...strogeUrls],
168
173
  });
169
174
  if (_this.properties.single) {
170
175
  _this.triggerEvent('success', {
@@ -188,6 +193,7 @@ Component({
188
193
  this.data.files[index].uploaded = transSize(res.totalBytesSent);
189
194
  this.setData({
190
195
  files: this.data.files,
196
+ //cloudFile:this.data.cloudFile.concat(this.data.files)
191
197
  });
192
198
  });
193
199
  return { fileID: uploadTask.fileID };
@@ -204,15 +210,30 @@ Component({
204
210
  },
205
211
 
206
212
  onDelete: function (e) {
207
- const filelist = this.data.files.filter(
208
- (item) => e.target.dataset.item?.path != item?.path
209
- );
210
- this.setData({
211
- files: filelist,
212
- urls: this.data.urls.filter(
213
- (v, index) => e.target.dataset.item?.cloudPath != v
214
- ),
215
- });
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
+ }
216
237
  },
217
238
  reload: function (e) {
218
239
  this.handleUpload(e.target.dataset.item);
@@ -236,11 +257,15 @@ Component({
236
257
  },
237
258
  observers: {
238
259
  defaultValue: async function (value) {
239
- if (!Array.isArray(value)) {
240
- value = [value].filter((v) => v.length > 0);
260
+ //当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
261
+ if (Array.isArray(value) && !this.data.singleFlag) {
262
+ this.setData({
263
+ urls: value
264
+ });
265
+ this.data.singleFlag = true;
241
266
  }
242
267
  let httpFiles = [];
243
- if (value.length > 0) {
268
+ if (value && JSON.stringify(value) != '[]') {
244
269
  for (let f of value) {
245
270
  const hf = await getTempFileURL(f);
246
271
  const uuidReg = /[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}-/;
@@ -256,12 +281,19 @@ Component({
256
281
  };
257
282
  httpFiles.push(httpFile);
258
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
+ });
259
296
  }
260
-
261
- this.setData({
262
- files: httpFiles,
263
- cloudFile: value,
264
- });
265
297
  },
266
298
  'maxUploadCount, single': function (maxUploadCount, single) {
267
299
  const maxCount = single ? 1 : maxUploadCount;
@@ -109,11 +109,11 @@ Component({
109
109
  }
110
110
  item.paramObj = paramObj;
111
111
  if (item.withParams && item.params.length > 0) {
112
- wx.navigateTo({
112
+ wx.redirectTo({
113
113
  url: '../' + item?.insideUrl + '/index?' + item.paramObj.join('&'),
114
114
  });
115
115
  } else {
116
- wx.navigateTo({
116
+ wx.redirectTo({
117
117
  url: '../' + item?.insideUrl + '/index',
118
118
  });
119
119
  }
@@ -161,17 +161,16 @@ Component({
161
161
  optionList,
162
162
  });
163
163
  },
164
- 'titleMaxLines,titleColor,titleFontWeight,titleFontSize,textAlign,titleLineHeight':
165
- function (
166
- titleMaxLines,
167
- titleColor,
168
- titleFontWeight,
169
- titleFontSize,
170
- textAlign,
171
- titleLineHeight
172
- ) {
173
- let titleStyle = this.properties.titleStyle;
174
- titleStyle = `
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 = `
175
174
  -webkit-line-clamp:${titleMaxLines ? titleMaxLines : 'revert'};
176
175
  color: ${titleColor};
177
176
  font-weight: ${titleFontWeight};
@@ -179,19 +178,18 @@ Component({
179
178
  text-align: ${textAlign};
180
179
  line-height: ${titleLineHeight == 'auto' ? 'normal' : titleLineHeight};
181
180
  `;
182
- this.setData({ titleStyle });
183
- },
184
- 'desMaxLines,desColor,desFontWeight,desFontSize,textAlign,desLineHeight':
185
- function (
186
- desMaxLines,
187
- desColor,
188
- desFontWeight,
189
- desFontSize,
190
- textAlign,
191
- desLineHeight
192
- ) {
193
- let desStyle = this.properties.desStyle;
194
- desStyle = `
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 = `
195
193
  -webkit-line-clamp:${desMaxLines ? desMaxLines : 'revert'};
196
194
  color: ${desColor};
197
195
  font-weight: ${desFontWeight};
@@ -199,7 +197,7 @@ Component({
199
197
  text-align: ${textAlign};
200
198
  line-height: ${desLineHeight == 'auto' ? 'normal' : desLineHeight};
201
199
  `;
202
- this.setData({ desStyle });
203
- },
200
+ this.setData({ desStyle });
201
+ },
204
202
  },
205
203
  });
@@ -1,17 +1,6 @@
1
- const isNull = (val) => [undefined, null].includes(val);
2
- const REL_DICT = {
3
- equal: 'eq', // 等于
4
- unequal: 'neq', // 不等于
5
- include: 'search', // 包含
6
- exclude: '_exclude', // 不包含
7
- begin_with: '_begin_with', // 开头是
8
- greater: 'gt', // 大于
9
- greater_or_equal: 'gte', // 大于等于
10
- less: 'lt', // 小于
11
- less_or_equal: 'lte', // 小于等于
12
- in: 'in', // 多选值
13
- not_in: 'nin', // 不在多选值
14
- };
1
+ import { REL_DICT } from '../../utils/constant';
2
+ import { isNil } from '../../utils/lodash';
3
+
15
4
  const ORDERTYPE = ['asc', 'desc'];
16
5
  const getWhereList = (where) => {
17
6
  let result = [];
@@ -28,7 +17,7 @@ const getWhereList = (where) => {
28
17
  rel = 'regex';
29
18
  val = `^((?!${val}).)*$`;
30
19
  }
31
- if (item2?.logic !== 'or' && item2?.key && rel && !isNull(val)) {
20
+ if (item2?.logic !== 'or' && item2?.key && rel && !isNil(val)) {
32
21
  result.push({ key: item2.key, rel, val });
33
22
  }
34
23
  });
@@ -38,7 +27,6 @@ const getWhereList = (where) => {
38
27
  };
39
28
  const DEFAULT_DATA = {
40
29
  pageNo: 1,
41
- loading: false,
42
30
  total: 0,
43
31
  records: [],
44
32
  pageStr: '0/0',
@@ -90,7 +78,7 @@ Component({
90
78
  value: (v) => v,
91
79
  },
92
80
  },
93
- data: { ...DEFAULT_DATA },
81
+ data: { ...DEFAULT_DATA, isReLoad: false, loading: false },
94
82
  methods: {
95
83
  /**
96
84
  * 列表容器拉取数据,放在 setData 的回调函数中执行
@@ -98,10 +86,10 @@ Component({
98
86
  _fetchData: async function () {
99
87
  const { app } = getApp();
100
88
  const callDataSource = app?.cloud?.callDataSource;
101
- const { pageNo, loading } = this.data;
89
+ const { pageNo, loading, isReLoad } = this.data;
102
90
  const { datasource, orderBy, orderType, where, pageSize } =
103
91
  this.properties;
104
- if (loading) return;
92
+ if (loading && !isReLoad) return;
105
93
  if (!callDataSource) {
106
94
  console.warn(`当前环境缺少方法 app.cloud.callDataSource`);
107
95
  return;
@@ -115,7 +103,7 @@ Component({
115
103
  const tcbParams = {};
116
104
 
117
105
  // tcb分页参数
118
- if (!isNull(pageNo) && !isNull(pageSize)) {
106
+ if (!isNil(pageNo) && !isNil(pageSize)) {
119
107
  tcbParams['pageNo'] = pageNo;
120
108
  tcbParams['pageSize'] = pageSize;
121
109
  }
@@ -128,32 +116,40 @@ Component({
128
116
  const whereEffected = [].concat(getWhereList(where));
129
117
  whereEffected.length > 0 && (tcbParams['where'] = whereEffected);
130
118
  // tcb结果和事件
131
- const data = await callDataSource({
132
- dataSourceName,
133
- methodName,
134
- params: tcbParams,
135
- });
136
- let records = data?.records || [];
137
- let total = data?.total || 0;
138
- if (
139
- ['loadMoreButton', 'bottomLoad'].includes(this.properties.pagination)
140
- ) {
141
- records = [...this.data.records, ...records]; // TODO 可能存在单次 setData 数据量过大引起小程序性能问题
142
- }
143
- this.setData(
144
- {
145
- total,
146
- records,
147
- loading: false,
148
- pageStr: `${total > 0 ? pageNo : 0}/${
149
- Math.ceil(total / pageSize) || 0
150
- }`,
151
- },
152
- () => {
153
- this._handleEvents(data);
154
- setTimeout(() => this._firstScreenLoadMore(), 150);
119
+ try {
120
+ const data = await callDataSource({
121
+ dataSourceName,
122
+ methodName,
123
+ params: tcbParams,
124
+ });
125
+ let records = data?.records || [];
126
+ let total = data?.total || 0;
127
+ if (
128
+ ['loadMoreButton', 'bottomLoad'].includes(
129
+ this.properties.pagination
130
+ ) &&
131
+ !isReLoad
132
+ ) {
133
+ records = [...this.data.records, ...records]; // TODO 可能存在单次 setData 数据量过大引起小程序性能问题
155
134
  }
156
- );
135
+ this.setData(
136
+ {
137
+ total,
138
+ records,
139
+ loading: false,
140
+ isReLoad: false,
141
+ pageStr: `${total > 0 ? pageNo : 0}/${
142
+ Math.ceil(total / pageSize) || 0
143
+ }`,
144
+ },
145
+ () => {
146
+ this._handleEvents(data);
147
+ setTimeout(() => this._firstScreenLoadMore(), 150);
148
+ }
149
+ );
150
+ } catch (e) {
151
+ this.setData({ loading: false });
152
+ }
157
153
  },
158
154
  /**
159
155
  * 下一页
@@ -236,31 +232,22 @@ Component({
236
232
  _observerSign: function () {
237
233
  this.signObserver = this.createIntersectionObserver();
238
234
  this.signObserver
239
- .relativeTo('.weda-list-view__containor', { bottom: 10 })
235
+ .relativeToViewport()
240
236
  .observe('#weda-list-view_sign', (res) => {
241
237
  this.setData({ isVisiableSign: res?.intersectionRatio > 0 });
242
238
  });
243
239
  },
244
240
  },
245
241
  observers: {
246
- 'datasource,orderBy,orderType,where,pageSize,pagination': function (
247
- dDatasource,
248
- dOrderBy,
249
- dOrderType,
250
- dWhere,
251
- dPageSize,
252
- dPagination
253
- ) {
254
- if (
255
- dDatasource !== this.properties.datasource ||
256
- dOrderBy !== this.properties.orderBy ||
257
- dOrderType !== this.properties.orderType ||
258
- dWhere !== this.properties.where ||
259
- dPageSize !== this.properties.pageSize ||
260
- dPagination !== this.properties.pagination
261
- ) {
262
- this.setData({ ...DEFAULT_DATA }, () => this._fetchData());
263
- }
242
+ 'datasource,orderBy,orderType,where,pageSize,pagination': function () {
243
+ clearTimeout(this._timer);
244
+ this._timer = setTimeout(
245
+ () =>
246
+ this.setData({ ...DEFAULT_DATA, isReLoad: true }, () =>
247
+ this._fetchData()
248
+ ),
249
+ 200
250
+ );
264
251
  },
265
252
  isVisiableSign: function (dIsVisiableSign) {
266
253
  if (dIsVisiableSign && this.properties.pagination === 'bottomLoad') {
@@ -275,6 +262,7 @@ Component({
275
262
  },
276
263
  lifetimes: {
277
264
  attached: function () {
265
+ clearTimeout(this._timer);
278
266
  this._fetchData();
279
267
  this._observerSign();
280
268
  },
@@ -1,11 +1,11 @@
1
- <scroll-view scroll-y scroll-with-animation lower-threshold="5" style="height:97vh;{{style}}"
1
+ <scroll-view scroll-y scroll-with-animation lower-threshold="5" style="{{style}}"
2
2
  class="weda-list-view__containor weda-ui {{className}}">
3
3
  <!-- 列表插槽 -->
4
4
  <view class="{{template === 'cardList' ? 'weda-list-view-card' : ''}}" id="weda-list-view_content">
5
5
  <slot></slot>
6
6
  </view>
7
7
 
8
- <view class="weda-list-view__more">
8
+ <view class="weda-list-view__more {{'weda-list-view__more-' + pagination}}">
9
9
  <!-- 加载更多 -->
10
10
  <block wx:if="{{pagination==='loadMoreButton' && pageSize * pageNo < total}}">
11
11
  <view class="weda-list-view__more-text" bindtap="handleNext">加载更多</view>
@@ -34,6 +34,11 @@
34
34
  background: #fff;
35
35
  }
36
36
 
37
+ .weda-list-view__containor
38
+ .weda-list-view__more.weda-list-view__more-bottomLoad {
39
+ background: transparent;
40
+ }
41
+
37
42
  .weda-list-view__bottom-load {
38
43
  padding-top: 1px;
39
44
  }