@cloudbase/weda-ui-mp 3.12.2 → 3.12.3

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.
@@ -1,5 +1,6 @@
1
1
  import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
2
2
  import { transSize, randomStr } from '../../../utils/platform';
3
+ import equal from '../../../utils/deepEqual';
3
4
 
4
5
  Component({
5
6
  options: {
@@ -24,6 +25,9 @@ Component({
24
25
  defaultValue: {
25
26
  type: null,
26
27
  },
28
+ oldValue: {
29
+ type: null,
30
+ },
27
31
  maxUploadCount: {
28
32
  type: Number,
29
33
  value: 9,
@@ -105,10 +109,7 @@ Component({
105
109
  });
106
110
  return false;
107
111
  }
108
- if (
109
- this.properties.maxSize &&
110
- files.some((f) => f.size > this.properties.maxSize * 1024 * 1024)
111
- ) {
112
+ if (this.properties.maxSize && files.some((f) => f.size > this.properties.maxSize * 1024 * 1024)) {
112
113
  wx.showToast({
113
114
  title: `上传文件大小不能超过${this.properties.maxSize}M`,
114
115
  icon: 'none',
@@ -154,6 +155,13 @@ Component({
154
155
  },
155
156
  });
156
157
  },
158
+ getName: function (hf) {
159
+ const uuidReg = /[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}-/;
160
+ const lastIndex = String(hf).lastIndexOf('/');
161
+ const name = String(hf).slice(lastIndex + 1);
162
+ const label = name.replace(uuidReg, '');
163
+ return label;
164
+ },
157
165
  handleUpload: async function (files, reload = false) {
158
166
  var _this = this;
159
167
  if (!this.handleBefore(files)) return;
@@ -172,10 +180,7 @@ Component({
172
180
  });
173
181
  if (typeof ret === 'boolean') {
174
182
  shouldUploadToCos = ret;
175
- } else if (
176
- Array.Array(ret) &&
177
- ret.every((i) => typeof i === 'string')
178
- ) {
183
+ } else if (Array.Array(ret) && ret.every((i) => typeof i === 'string')) {
179
184
  files = ret.map((path, idx) => {
180
185
  files[idx].path = path;
181
186
  });
@@ -193,14 +198,12 @@ Component({
193
198
  ...i,
194
199
  percent: '0',
195
200
  cloudPath: null,
196
- name: i?.name || i?.tempFilePath.slice(9),
201
+ name: i?.name || this.getName(i?.tempFilePath),
197
202
  filePath: i?.path || i?.tempFilePath || null,
198
203
  size: transSize(i?.size),
199
204
  status: 'pending',
200
205
  }));
201
- let filelsList = reload
202
- ? this.data.files
203
- : [...this.data.files, ...initFiles];
206
+ let filelsList = reload ? this.data.files : [...this.data.files, ...initFiles];
204
207
  this.setData({
205
208
  files: filelsList,
206
209
  });
@@ -210,9 +213,7 @@ Component({
210
213
  _this.handleUploadFile({
211
214
  _tempFile: tempFile,
212
215
  onSuccess: (res) => {
213
- filelsList = filelsList.map((i) =>
214
- i.filePath === res.filePath ? res : i
215
- );
216
+ filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
216
217
  _this.triggerEvent('success', {
217
218
  value: res.cloudPath,
218
219
  file: res,
@@ -220,30 +221,22 @@ Component({
220
221
  resolve(res);
221
222
  },
222
223
  onProgressUpdate: (res) => {
223
- filelsList = filelsList.map((i) =>
224
- i.filePath === res.filePath ? res : i
225
- );
224
+ filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
226
225
  _this.setData({
227
226
  files: filelsList,
228
227
  });
229
228
  },
230
229
  onFail: (res, error) => {
231
- filelsList = filelsList.map((i) =>
232
- i.filePath === res.filePath ? res : i
233
- );
230
+ filelsList = filelsList.map((i) => (i.filePath === res.filePath ? res : i));
234
231
  _this.triggerEvent('error', error.detail);
235
232
  resolve(res);
236
233
  },
237
234
  });
238
235
  });
239
- })
236
+ }),
240
237
  ).then((res) => {
241
- const result = filelsList.map(
242
- (i) => res.find((j) => j.filePath === i.filePath) || i
243
- );
244
- const cloudPathList = result
245
- .filter((i) => i.cloudPath)
246
- .map((j) => j.cloudPath);
238
+ const result = filelsList.map((i) => res.find((j) => j.filePath === i.filePath) || i);
239
+ const cloudPathList = result.filter((i) => i.cloudPath).map((j) => j.cloudPath);
247
240
  this.setData({
248
241
  files: result,
249
242
  urls: cloudPathList,
@@ -252,12 +245,7 @@ Component({
252
245
  _this.handleChange(cloudPathList);
253
246
  });
254
247
  },
255
- handleUploadFile: async function ({
256
- _tempFile,
257
- onSuccess,
258
- onProgressUpdate,
259
- onFail,
260
- }) {
248
+ handleUploadFile: async function ({ _tempFile, onSuccess, onProgressUpdate, onFail }) {
261
249
  const tempFile = {
262
250
  ..._tempFile,
263
251
  };
@@ -324,20 +312,15 @@ Component({
324
312
  }
325
313
  });
326
314
  this.setData({
327
- files: this.data.files.filter(
328
- (v) => e.target.dataset.item.cloudPath !== v.cloudPath
329
- ),
315
+ files: this.data.files.filter((v) => e.target.dataset.item.cloudPath !== v.cloudPath),
330
316
  urls: newUrls,
331
317
  });
332
318
  } else {
333
319
  const filelist = this.data.files.filter(
334
320
  (item) =>
335
- e.target.dataset.item?.path != item?.path ||
336
- e.target.dataset.item?.tempFilePath != item?.tempFilePath
337
- );
338
- newUrls = this.data.urls.filter(
339
- (v) => e.target.dataset.item?.cloudPath != v
321
+ e.target.dataset.item?.path != item?.path || e.target.dataset.item?.tempFilePath != item?.tempFilePath,
340
322
  );
323
+ newUrls = this.data.urls.filter((v) => e.target.dataset.item?.cloudPath != v);
341
324
  this.setData({
342
325
  files: filelist,
343
326
  urls: newUrls,
@@ -352,6 +335,7 @@ Component({
352
335
  if (this.properties.single) {
353
336
  value = values[0] ?? '';
354
337
  }
338
+ this.setData({ oldValue: value });
355
339
  this.triggerEvent('change', { value });
356
340
  },
357
341
 
@@ -428,6 +412,9 @@ Component({
428
412
  },
429
413
  observers: {
430
414
  defaultValue: async function (value) {
415
+ if (equal(this.data.oldValue, value)) {
416
+ return;
417
+ }
431
418
  //当单图片上传且默认值为空数组时,初次渲染更新value,以避免空串提交类型不匹配问题
432
419
  if (Array.isArray(value) && !this.data.singleFlag) {
433
420
  this.setData({
@@ -441,10 +428,7 @@ Component({
441
428
  for (let f of values) {
442
429
  if (f.startsWith('cloud:')) {
443
430
  const hf = await getTempFileURL(f);
444
- const uuidReg = /[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}-/;
445
- const lastIndex = String(hf).lastIndexOf('/');
446
- const name = String(hf).slice(lastIndex + 1);
447
- const label = name.replace(uuidReg, '');
431
+ const label = this.getName(hf);
448
432
  const httpFile = {
449
433
  name: label,
450
434
  cloudPath: f,
@@ -455,19 +439,14 @@ Component({
455
439
  httpFiles.push(httpFile);
456
440
  }
457
441
  }
458
- const files = this.data.files;
459
- // 文件上传成功也会触发defaultValue变化,此情况不执行初始化文件列表
460
- if (!files?.length) {
461
- this.setData({
462
- files: httpFiles,
463
- cloudFile:
464
- JSON.stringify(value) != JSON.stringify(this.data.cloudFile)
465
- ? [].concat(value)
466
- : [],
467
- });
468
- }
442
+ this.setData({
443
+ oldValue: value,
444
+ files: httpFiles,
445
+ cloudFile: JSON.stringify(value) != JSON.stringify(this.data.cloudFile) ? [].concat(value) : [],
446
+ });
469
447
  } else {
470
448
  this.setData({
449
+ oldValue: value,
471
450
  files: [],
472
451
  cloudFile: [],
473
452
  });
@@ -481,8 +460,7 @@ Component({
481
460
  },
482
461
  'layout,extClass': function (layout, extClass) {
483
462
  const temp = `weda-formcells weui-cells weui-cells_forms ${extClass}`;
484
- const layoutCls =
485
- layout !== 'vertical' ? ` weui-flex ${temp}` : `${temp}`;
463
+ const layoutCls = layout !== 'vertical' ? ` weui-flex ${temp}` : `${temp}`;
486
464
  this.setData({ layoutCls });
487
465
  },
488
466
  },
@@ -31,7 +31,7 @@
31
31
  /* theme */
32
32
  .weda-uploader-files__btn {
33
33
  margin: 0;
34
- width: 88px;
34
+ width: auto;
35
35
  height: 32px;
36
36
  padding: 0;
37
37
  display: flex;
@@ -132,27 +132,19 @@
132
132
  }
133
133
 
134
134
  /* 标准化样式适配 start */
135
- .wd-form-item.wd-mp-upload-file-root
136
- .weda-uploader-files
137
- .weda-uploader-files__btn-contain {
135
+ .wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__btn-contain {
138
136
  padding: 0;
139
137
  }
140
138
 
141
- .wd-form-item.wd-mp-upload-file-root
142
- .weda-uploader-files
143
- .weda-uploader-files__file-status {
139
+ .wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__file-status {
144
140
  width: auto;
145
141
  }
146
142
 
147
- .wd-form-item.wd-mp-upload-file-root
148
- .weda-uploader-files
149
- .weda-uploader-files__file-foot {
143
+ .wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__file-foot {
150
144
  margin: 0;
151
145
  }
152
146
 
153
- .wd-form-item.wd-mp-upload-file-root
154
- .weda-uploader-files
155
- .weda-uploader-files__item {
147
+ .wd-form-item.wd-mp-upload-file-root .weda-uploader-files .weda-uploader-files__item {
156
148
  padding: 0;
157
149
  }
158
150
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.12.2",
6
+ "version": "3.12.3",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"