@cloudbase/weda-ui-mp 3.18.2 → 3.18.4

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.
@@ -126,9 +126,14 @@ Component({
126
126
  let tempFilePaths = files.tempFilePaths;
127
127
  if (typeof callbacks?.beforeUpload === 'function') {
128
128
  try {
129
+ const mgr = wx.getFileSystemManager();
130
+
129
131
  const ret = await callbacks.beforeUpload({
130
132
  tempFilePaths: tempFilePaths,
131
- base64Uri: files.contents.map((content) => `data:image/jpg;base64,${wx.arrayBufferToBase64(content)}`),
133
+ base64Uri: files.tempFiles.map((f) => {
134
+ const content = mgr.readFileSync(f.tempFilePath);
135
+ return `data:;base64,${wx.arrayBufferToBase64(content)}`;
136
+ }),
132
137
  });
133
138
  if (typeof ret === 'boolean') {
134
139
  shouldUploadToCos = ret;
@@ -174,7 +179,7 @@ Component({
174
179
  // 这里返回的东西会在uploadSuccess回调函数中获取到
175
180
  // https://github.com/wechat-miniprogram/weui-miniprogram/blob/a3630575910302e3b94e69fcef266d2b509de650/src/components/uploader/uploader.ts#L149
176
181
  // 写死的从返回值的 .urls 获取展示用的url来用。一定要将tempFilePaths透传下去,否则会重新加载然后出现闪白
177
- return { urls: files.tempFilePaths, cloudUrls };
182
+ return { urls: files.tempFilePaths, cloudUrls, file: files.tempFiles };
178
183
  } catch (e) {
179
184
  wx.showModal({
180
185
  title: '上传失败,请重试',
@@ -193,6 +198,7 @@ Component({
193
198
  // 小程序自带tempURL 不需要调用 tcb.getTempFileURL 获取
194
199
  this.triggerEvent('success', {
195
200
  value: this.properties.single ? urls[0] : urls,
201
+ file: e.detail.file,
196
202
  });
197
203
  const newUrls = [...this.data.cloudFile, ...urls];
198
204
  this.setData({
@@ -176,25 +176,13 @@ Component({
176
176
  });
177
177
  },
178
178
  commonFile: function (tempFiles) {
179
- // 获取文件内容
180
- const mgr = wx.getFileSystemManager();
181
- const contents = tempFiles.map((item) => {
182
- const fileContent = mgr.readFileSync(item?.tempFilePath);
183
-
184
- return fileContent;
185
- });
186
179
  const obj = {
187
180
  tempFilePaths: tempFiles.map((item) => item.tempFilePath),
188
181
  tempFiles: tempFiles,
189
- contents,
190
182
  };
191
- // 触发选中的事件,开发者根据内容来上传文件,上传了把上传的结果反馈到files属性里面
192
- this.triggerEvent('select', obj, {});
193
- const files = tempFiles.map((item, i) => ({
183
+ const files = tempFiles.map((item) => ({
194
184
  loading: true,
195
- url:
196
- item.tempFilePaths ||
197
- `data:image/jpg;base64,${wx.arrayBufferToBase64(contents[i])}`,
185
+ url: item.tempFilePath,
198
186
  }));
199
187
  if (!files || !files.length) return;
200
188
  if (typeof this.data.upload === 'function') {
@@ -230,7 +218,7 @@ Component({
230
218
  type: 3,
231
219
  errMsg: 'upload file fail, urls not found',
232
220
  },
233
- {}
221
+ {},
234
222
  );
235
223
  }
236
224
  })
@@ -252,7 +240,7 @@ Component({
252
240
  errMsg: 'upload file fail',
253
241
  error: err,
254
242
  },
255
- {}
243
+ {},
256
244
  );
257
245
  });
258
246
  }
@@ -101,7 +101,7 @@ Component({
101
101
  },
102
102
  showMessageCard: {
103
103
  type: Boolean,
104
- value: 'false',
104
+ value: false,
105
105
  },
106
106
  appParameter: {
107
107
  type: String,
@@ -121,9 +121,7 @@ Component({
121
121
  switch (this.data._formType) {
122
122
  case 'submit': {
123
123
  // 调用父级表单容器的提交
124
- parentForm = this.$widget.closest(
125
- (w) => w.getConfig?.().componentType === 'form'
126
- );
124
+ parentForm = this.$widget.closest((w) => w.getConfig?.().componentType === 'form');
127
125
  if (parentForm.submit) {
128
126
  parentForm.submit();
129
127
  return;
@@ -136,9 +134,7 @@ Component({
136
134
  }
137
135
  case 'reset': {
138
136
  // 调用父级表单容器的重置
139
- parentForm = this.$widget.closest(
140
- (w) => w.getConfig?.().componentType === 'form'
141
- );
137
+ parentForm = this.$widget.closest((w) => w.getConfig?.().componentType === 'form');
142
138
  if (parentForm.reset) {
143
139
  parentForm.reset();
144
140
  return;
@@ -154,16 +150,7 @@ Component({
154
150
  }
155
151
  },
156
152
  updateWidgetAPI() {
157
- const {
158
- text,
159
- theme,
160
- variant,
161
- size,
162
- block,
163
- disabled,
164
- formType,
165
- openType,
166
- } = this.data;
153
+ const { text, theme, variant, size, block, disabled, formType, openType } = this.data;
167
154
 
168
155
  this.setReadonlyAttributes &&
169
156
  this.setReadonlyAttributes({
@@ -210,18 +197,14 @@ Component({
210
197
  let _size = PROPS_VALUE_MAP.size[size] || size;
211
198
  let _theme = PROPS_VALUE_MAP.theme[theme] || theme;
212
199
  let _icon = loading ? 'td:loading' : icon;
213
- let _iconType =
214
- iconType === 'none' && loading ? 'text-with-icon' : iconType;
200
+ let _iconType = iconType === 'none' && loading ? 'text-with-icon' : iconType;
215
201
 
216
202
  // 枚举转换
217
203
  _theme = convertLegacyEnum(_theme, WD_BUTTON_THEME);
218
204
  _size = convertLegacyEnum(_size, WD_BUTTON_SIZE);
219
205
  _iconType = convertLegacyEnum(_iconType, WD_BUTTON_ICON_TYPE);
220
206
  const _variant = convertLegacyEnum(variant, WD_BUTTON_VARIANT);
221
- const _iconPosition = convertLegacyEnum(
222
- iconPosition,
223
- WD_BUTTON_ICON_POSITION
224
- );
207
+ const _iconPosition = convertLegacyEnum(iconPosition, WD_BUTTON_ICON_POSITION);
225
208
  const _formType = convertLegacyEnum(formType, WD_BUTTON_TYPE);
226
209
 
227
210
  const classes = {
@@ -249,12 +232,9 @@ Component({
249
232
  // icon样式
250
233
  const iconCls = classNames({
251
234
  [`${classPrefix}-btn__icon`]: true,
252
- [`${classPrefix}-btn__before-icon`]:
253
- iconType === 'text-with-icon' && _iconPosition === 'before',
254
- [`${classPrefix}-btn__after-icon`]:
255
- iconType === 'text-with-icon' && _iconPosition === 'after',
256
- [`${classPrefix}-icon--inherit`]:
257
- style?.fontSize && iconSource === 'inner',
235
+ [`${classPrefix}-btn__before-icon`]: iconType === 'text-with-icon' && _iconPosition === 'before',
236
+ [`${classPrefix}-btn__after-icon`]: iconType === 'text-with-icon' && _iconPosition === 'after',
237
+ [`${classPrefix}-icon--inherit`]: style?.fontSize && iconSource === 'inner',
258
238
  });
259
239
  this.setData({ cls, iconCls, textCls, _icon, _iconType, _formType });
260
240
  },
@@ -7,13 +7,7 @@ import { convertSize } from '../../utils/getFormLegacy';
7
7
  import classNames from '../../utils/classnames';
8
8
  import { commonCompBehavior } from '../../utils/common-behavior';
9
9
  import formFieldBehavior from '../form-field-behavior/form-field-behavior';
10
- import {
11
- dealDecimals,
12
- strNumAddCalc,
13
- isNumber,
14
- dealPercent,
15
- getPercentUnit,
16
- } from './number';
10
+ import { dealDecimals, strNumAddCalc, isNumber, dealPercent, getPercentUnit } from './number';
17
11
  import equal from '../../utils/deepEqual';
18
12
 
19
13
  const getHasClearIcon = (clearable, focus, disabled, readOnly, realValue) =>
@@ -26,12 +20,7 @@ const getRealValue = ({ value, format }) => {
26
20
  return Number(v.replace(/,/g, ''));
27
21
  };
28
22
 
29
- const judgeRule = ({
30
- value = undefined,
31
- max = undefined,
32
- min = undefined,
33
- resultType = 'boolean',
34
- } = {}) => {
23
+ const judgeRule = ({ value = undefined, max = undefined, min = undefined, resultType = 'boolean' } = {}) => {
35
24
  let maxFit = true;
36
25
  let minFit = true;
37
26
  if (isNumber(max)) {
@@ -45,12 +34,7 @@ const judgeRule = ({
45
34
  return resultType === 'boolean' ? maxFit && minFit : { maxFit, minFit };
46
35
  };
47
36
 
48
- const getRuleMessage = ({
49
- value = undefined,
50
- max = undefined,
51
- min = undefined,
52
- validMsgObj = {},
53
- } = {}) => {
37
+ const getRuleMessage = ({ value = undefined, max = undefined, min = undefined, validMsgObj = {} } = {}) => {
54
38
  const { maxFit, minFit } = judgeRule({
55
39
  value,
56
40
  max,
@@ -129,7 +113,7 @@ Component({
129
113
  inputWrap: `${WD_PREFIX}-form-input-wrap`,
130
114
  inputCls: `${WD_PREFIX}-form-input-wrap__input`,
131
115
  inputGroup: `${WD_PREFIX}-form-input-group`,
132
- placeholderCls: `${WD_PREFIX}-form-input-wrap__placeholder`,
116
+ placeholderCls: `${WD_PREFIX}-form-input-wrap__placeholder weui-input__placeholder`,
133
117
  cls: '',
134
118
  formClass: '',
135
119
 
@@ -147,21 +131,8 @@ Component({
147
131
  },
148
132
  methods: {
149
133
  updateWidgetAPI: function () {
150
- const {
151
- name,
152
- label,
153
- required,
154
- visible,
155
- disabled,
156
- readOnly,
157
- before,
158
- after,
159
- min,
160
- max,
161
- step,
162
- format,
163
- value,
164
- } = this.data;
134
+ const { name, label, required, visible, disabled, readOnly, before, after, min, max, step, format, value } =
135
+ this.data;
165
136
  this.setReadonlyAttributes?.({
166
137
  name,
167
138
  value,
@@ -186,20 +157,12 @@ Component({
186
157
  },
187
158
  onRealChange(e, type = '', { needSetData = true, value = '' } = {}) {
188
159
  const { readOnly, disabled, status, format, step } = this.properties;
189
- if (readOnly || disabled || (status && status !== 'edit'))
190
- return this.data.realValue;
160
+ if (readOnly || disabled || (status && status !== 'edit')) return this.data.realValue;
191
161
 
192
- const { stepPlusDisabled, stepMinusDisabled } = this.getStepDisabled(
193
- null,
194
- this.data.realValue
195
- );
162
+ const { stepPlusDisabled, stepMinusDisabled } = this.getStepDisabled(null, this.data.realValue);
196
163
 
197
164
  if (['plus', 'minus'].includes(type)) {
198
- if (
199
- !isNumber(step) ||
200
- (type === 'plus' && stepPlusDisabled) ||
201
- (type === 'minus' && stepMinusDisabled)
202
- ) {
165
+ if (!isNumber(step) || (type === 'plus' && stepPlusDisabled) || (type === 'minus' && stepMinusDisabled)) {
203
166
  needSetData &&
204
167
  this.setData({
205
168
  stepPlusDisabled,
@@ -263,10 +226,7 @@ Component({
263
226
  return;
264
227
  }
265
228
 
266
- const reg = new RegExp(
267
- `^\\D*(\\d*(?:\\.\\d{0,${Math.max(0, 10000)}})?).*$`,
268
- 'g'
269
- );
229
+ const reg = new RegExp(`^\\D*(\\d*(?:\\.\\d{0,${Math.max(0, 10000)}})?).*$`, 'g');
270
230
  value = value.replace(reg, '$1');
271
231
 
272
232
  if (e.detail.value.startsWith('-')) {
@@ -313,10 +273,8 @@ Component({
313
273
  stepPlusDisabled = true;
314
274
  stepMinusDisabled = true;
315
275
  } else {
316
- stepPlusDisabled =
317
- isNumber(+realValue) && isNumber(max) && max <= +realValue;
318
- stepMinusDisabled =
319
- isNumber(+realValue) && isNumber(min) && min >= +realValue;
276
+ stepPlusDisabled = isNumber(+realValue) && isNumber(max) && max <= +realValue;
277
+ stepMinusDisabled = isNumber(+realValue) && isNumber(min) && min >= +realValue;
320
278
  }
321
279
 
322
280
  return { stepPlusDisabled, stepMinusDisabled };
@@ -334,7 +292,7 @@ Component({
334
292
 
335
293
  const { stepPlusDisabled, stepMinusDisabled } = this.getStepDisabled(
336
294
  { readOnly, disabled, status, max, min, format },
337
- toReal
295
+ toReal,
338
296
  );
339
297
 
340
298
  const readValue = `${toShow}${getPercentUnit(format)}`;
@@ -342,17 +300,7 @@ Component({
342
300
  return { toShow, toReal, stepPlusDisabled, stepMinusDisabled, readValue };
343
301
  },
344
302
  // 获取显示在输入框的值,非真实值
345
- getShowValue({
346
- value,
347
- thousandShow,
348
- decimals,
349
- step,
350
- max,
351
- min,
352
- format,
353
- type = '',
354
- needSetData = true,
355
- }) {
303
+ getShowValue({ value, thousandShow, decimals, step, max, min, format, type = '', needSetData = true }) {
356
304
  if (value === '' && !['plus', 'minus'].includes(type)) return '';
357
305
 
358
306
  if (value === 'null' || value === 'undefined') return '';
@@ -362,9 +310,7 @@ Component({
362
310
  let res = `${value}`;
363
311
 
364
312
  if (isNumber(value) && res.includes('e')) {
365
- res = `${res.startsWith('-') ? '-' : ''}${res
366
- .replace(/^-/, '')
367
- .toLocaleString()}`;
313
+ res = `${res.startsWith('-') ? '-' : ''}${res.replace(/^-/, '').toLocaleString()}`;
368
314
  }
369
315
 
370
316
  res = res.replace(/ /g, '').replace(/,/g, '');
@@ -383,11 +329,7 @@ Component({
383
329
  }
384
330
 
385
331
  const validMsgObj = getValidMsgObj(format, max, min);
386
- const rules = getRules(
387
- validMsgObj,
388
- this.properties.max,
389
- this.properties.min
390
- );
332
+ const rules = getRules(validMsgObj, this.properties.max, this.properties.min);
391
333
 
392
334
  if (isNumber(this.properties.max) && Number(res) > max) {
393
335
  validState = 'error';
@@ -406,9 +348,7 @@ Component({
406
348
  // 千分符转换
407
349
  if (thousandShow && res !== 'Infinity' && res !== '-Infinity') {
408
350
  const temp = res.split('.');
409
- res = `${temp[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')}${
410
- temp[1] ? `.${temp[1]}` : ''
411
- }`;
351
+ res = `${temp[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')}${temp[1] ? `.${temp[1]}` : ''}`;
412
352
  }
413
353
 
414
354
  needSetData &&
@@ -422,118 +362,89 @@ Component({
422
362
  },
423
363
  },
424
364
  observers: {
425
- 'name,value,label,required,visible,disabled,readOnly,before,after,min,max,step,format':
426
- function () {
427
- this.updateWidgetAPI();
428
- },
429
- 'disabled,readOnly,clearable,isFocus': function (
365
+ 'name,value,label,required,visible,disabled,readOnly,before,after,min,max,step,format': function () {
366
+ this.updateWidgetAPI();
367
+ },
368
+ 'disabled,readOnly,clearable,isFocus': function (disabled, readOnly, clearable, isFocus) {
369
+ const hasClearIcon = getHasClearIcon(clearable, isFocus, disabled, readOnly, this.data.realValue);
370
+ this.setData({ hasClearIcon });
371
+ },
372
+ 'disabled,size,wrapClassName,before,after,classRoot,className,stepOption': function (
430
373
  disabled,
431
- readOnly,
432
- clearable,
433
- isFocus
374
+ size,
375
+ wrapClassName,
376
+ before,
377
+ after,
378
+ classRoot,
379
+ className,
380
+ stepOption,
434
381
  ) {
435
- const hasClearIcon = getHasClearIcon(
436
- clearable,
437
- isFocus,
438
- disabled,
439
- readOnly,
440
- this.data.realValue
382
+ const _size = convertSize(size);
383
+ const { classPrefix, inputWrap } = this.data;
384
+ const root = `${classPrefix}-${classRoot}`;
385
+ const cls = classNames(
386
+ root,
387
+ inputWrap,
388
+ this.data.inputGroup,
389
+ wrapClassName,
390
+ `size-width-${_size}`,
391
+ `size-font-${_size}`,
392
+ `size-height-${_size}`,
393
+ `${root}-${classRoot}`,
394
+ {
395
+ 'is-not-h5': true,
396
+ 'size-width-hundred': true,
397
+ 'is-disabled': disabled,
398
+ [`${classPrefix}-input-number-input-number`]: true,
399
+ [`${classPrefix}-form-input-wrap--no-border`]: stepOption !== 'both',
400
+ [`${inputWrap}--no-radius-left`]: before,
401
+ [`${inputWrap}--no-radius-right`]: after,
402
+ [`${inputWrap}--no-radius`]: before && after,
403
+ [`${classPrefix}-form-input-wrap`]: true,
404
+ },
441
405
  );
442
- this.setData({ hasClearIcon });
406
+ const formClass = classNames(className, `${root}--row`, stepOption !== 'both' ? 'input-number-step-right' : '');
407
+
408
+ this.setData({ cls, root, _size, formClass });
443
409
  },
444
- 'disabled,size,wrapClassName,before,after,classRoot,className,stepOption':
445
- function (
446
- disabled,
447
- size,
448
- wrapClassName,
449
- before,
450
- after,
451
- classRoot,
452
- className,
453
- stepOption
454
- ) {
455
- const _size = convertSize(size);
456
- const { classPrefix, inputWrap } = this.data;
457
- const root = `${classPrefix}-${classRoot}`;
458
- const cls = classNames(
459
- root,
460
- inputWrap,
461
- this.data.inputGroup,
462
- wrapClassName,
463
- `size-width-${_size}`,
464
- `size-font-${_size}`,
465
- `size-height-${_size}`,
466
- `${root}-${classRoot}`,
467
- {
468
- 'is-not-h5': true,
469
- 'size-width-hundred': true,
470
- 'is-disabled': disabled,
471
- [`${classPrefix}-input-number-input-number`]: true,
472
- [`${classPrefix}-form-input-wrap--no-border`]:
473
- stepOption !== 'both',
474
- [`${inputWrap}--no-radius-left`]: before,
475
- [`${inputWrap}--no-radius-right`]: after,
476
- [`${inputWrap}--no-radius`]: before && after,
477
- [`${classPrefix}-form-input-wrap`]: true,
478
- }
479
- );
480
- const formClass = classNames(
481
- className,
482
- `${root}--row`,
483
- stepOption !== 'both' ? 'input-number-step-right' : ''
484
- );
485
-
486
- this.setData({ cls, root, _size, formClass });
487
- },
488
- 'inputValue,format,decimals,min,max,status,readOnly,disabled,after,before,thousandShow,step':
489
- function (
490
- inputValue,
410
+ 'inputValue,format,decimals,min,max,status,readOnly,disabled,after,before,thousandShow,step': function (
411
+ inputValue,
412
+ format,
413
+ decimals,
414
+ min,
415
+ max,
416
+ status,
417
+ readOnly,
418
+ disabled,
419
+ after,
420
+ before,
421
+ thousandShow,
422
+ step,
423
+ ) {
424
+ const { toReal, toShow, stepPlusDisabled, stepMinusDisabled, readValue } = this.getRealAndShowData({
425
+ value: this.data.isInit ? (isNumber(inputValue) ? inputValue : '') : this.data.realValue,
491
426
  format,
492
427
  decimals,
493
428
  min,
494
429
  max,
495
- status,
496
430
  readOnly,
497
431
  disabled,
498
- after,
432
+ status,
499
433
  before,
434
+ after,
500
435
  thousandShow,
501
- step
502
- ) {
503
- const {
504
- toReal,
505
- toShow,
506
- stepPlusDisabled,
507
- stepMinusDisabled,
508
- readValue,
509
- } = this.getRealAndShowData({
510
- value: this.data.isInit
511
- ? isNumber(inputValue)
512
- ? inputValue
513
- : ''
514
- : this.data.realValue,
515
- format,
516
- decimals,
517
- min,
518
- max,
519
- readOnly,
520
- disabled,
521
- status,
522
- before,
523
- after,
524
- thousandShow,
525
- step,
526
- });
436
+ step,
437
+ });
527
438
 
528
- this.setData({
529
- readValue,
530
- realValue: toReal,
531
- showValue: readOnly ? readValue : toShow,
532
- stepPlusDisabled,
533
- stepMinusDisabled,
534
- });
535
- this.changeForm({ value: toReal });
536
- },
439
+ this.setData({
440
+ readValue,
441
+ realValue: toReal,
442
+ showValue: readOnly ? readValue : toShow,
443
+ stepPlusDisabled,
444
+ stepMinusDisabled,
445
+ });
446
+ this.changeForm({ value: toReal });
447
+ },
537
448
  // 监听非输入引起的value变化,比如调用 setValue, clearValue
538
449
  value: function (value) {
539
450
  const { format } = this.properties;
@@ -573,8 +484,9 @@ Component({
573
484
  },
574
485
  inputValue: function (inputValue) {
575
486
  if (equal(inputValue, this.data._oldInputValue)) return;
576
- const { toReal, toShow, stepPlusDisabled, stepMinusDisabled, readValue } =
577
- this.getRealAndShowData({ value: inputValue });
487
+ const { toReal, toShow, stepPlusDisabled, stepMinusDisabled, readValue } = this.getRealAndShowData({
488
+ value: inputValue,
489
+ });
578
490
 
579
491
  this.setData({
580
492
  readValue,
@@ -67,7 +67,7 @@ Component({
67
67
  this.setData({ visible: false });
68
68
  },
69
69
  menuClick(params) {
70
- this.triggerEvent('menuClick', params);
70
+ this.triggerEvent('menuClick', { ...params, item: params.detail?.item });
71
71
  },
72
72
  },
73
73
  });
@@ -25,7 +25,7 @@
25
25
  >
26
26
  <wd-input-group before="{{before}}" after="{{after}}" block="{{true}}" size="{{_size}}" classRoot="{{classRoot}}">
27
27
  <wd-input-wrap block="{{block}}" classRoot="{{classRoot}}" before="{{before}}" after="{{after}}" disabled="{{disabled}}" prefixType="{{prefixType}}" prefixIcon="{{prefixIcon}}" prefixSrc="{{prefixSrc}}" suffixType="{{suffixType}}" suffixIcon="{{suffixIcon}}" suffixSrc="{{suffixSrc}}" hasClearIcon="{{clearable && !disabled && (value != null)}}" bind:onClear="handleClear">
28
- <input class="{{classPrefix}}-form-select_input" placeholder="{{placeholder}}" value="{{readValue}}" disabled="true" name="{{name}}" bindtap="setPickerVisible" />
28
+ <input placeholder-class="weui-input__placeholder" class="{{classPrefix}}-form-select_input" placeholder="{{placeholder}}" value="{{readValue}}" disabled="true" name="{{name}}" bindtap="setPickerVisible" />
29
29
  </wd-input-wrap>
30
30
  </wd-input-group>
31
31
  </wd-form-item>
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.18.2",
6
+ "version": "3.18.4",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"