@cloudbase/weda-ui-mp 3.15.1 → 3.15.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.
@@ -143,34 +143,36 @@ Component({
143
143
  .select(`#${this.data.canvasId}`)
144
144
  .fields({ node: true, size: true })
145
145
  .exec(async (res) => {
146
- const canvasNode = res[0].node;
147
- this.canvasNode = canvasNode;
146
+ const canvasNode = res[0]?.node;
147
+ if (canvasNode) {
148
+ this.canvasNode = canvasNode;
148
149
 
149
- const canvasDpr = wx.getSystemInfoSync().pixelRatio;
150
- const canvasWidth = res[0].width;
151
- const canvasHeight = res[0].height;
150
+ const canvasDpr = wx.getSystemInfoSync().pixelRatio;
151
+ const canvasWidth = res[0].width;
152
+ const canvasHeight = res[0].height;
152
153
 
153
- const ctx = canvasNode.getContext('2d');
154
+ const ctx = canvasNode.getContext('2d');
154
155
 
155
- const canvas = new WxCanvas(ctx, this.data.canvasId, true, canvasNode);
156
- echarts.setCanvasCreator(() => {
157
- return canvas;
158
- });
159
-
160
- if (typeof callback === 'function') {
161
- this.chart = callback(canvas, canvasWidth, canvasHeight, canvasDpr);
162
- } else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
163
- this.chart = await this.data.ec.onInit(canvas, canvasWidth, canvasHeight, canvasDpr);
164
- } else {
165
- this.triggerEvent('init', {
166
- canvas: canvas,
167
- width: canvasWidth,
168
- height: canvasHeight,
169
- dpr: canvasDpr,
156
+ const canvas = new WxCanvas(ctx, this.data.canvasId, true, canvasNode);
157
+ echarts.setCanvasCreator(() => {
158
+ return canvas;
170
159
  });
171
- }
172
160
 
173
- this.domObserver && this.domObserver.disconnect();
161
+ if (typeof callback === 'function') {
162
+ this.chart = callback(canvas, canvasWidth, canvasHeight, canvasDpr);
163
+ } else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
164
+ this.chart = await this.data.ec.onInit(canvas, canvasWidth, canvasHeight, canvasDpr);
165
+ } else {
166
+ this.triggerEvent('init', {
167
+ canvas: canvas,
168
+ width: canvasWidth,
169
+ height: canvasHeight,
170
+ dpr: canvasDpr,
171
+ });
172
+ }
173
+
174
+ this.domObserver && this.domObserver.disconnect();
175
+ }
174
176
  });
175
177
  },
176
178
  canvasToTempFilePath(opt) {
@@ -127,7 +127,7 @@ Component({
127
127
  });
128
128
  }
129
129
  this.triggerEvent('search', { value });
130
- }, 1000);
130
+ }, 300);
131
131
  this.setData({
132
132
  timeId,
133
133
  });
@@ -181,12 +181,7 @@ Component({
181
181
  observers: {
182
182
  'option,searchValue,staticSearchable': function (option, searchValue, staticSearchable) {
183
183
  const { ignoreCase } = this.properties;
184
- if (searchValue === '') {
185
- this.setData({
186
- showOption: option,
187
- status: option.length > 0 ? 0 : 3,
188
- });
189
- } else if (staticSearchable) {
184
+ if (staticSearchable) {
190
185
  const searchRange = option.filter((item) => {
191
186
  if (ignoreCase) {
192
187
  return String(item.label).toLowerCase().indexOf(searchValue.toLowerCase()) !== -1;
@@ -94,10 +94,6 @@ Component({
94
94
  type: Boolean,
95
95
  value: true,
96
96
  },
97
- staticSearchable: {
98
- type: Boolean,
99
- value: true,
100
- },
101
97
  where: {
102
98
  type: Array,
103
99
  value: [],
@@ -120,6 +116,7 @@ Component({
120
116
  whereEffected: [], // 每次请求都加上
121
117
  fetchTimed: null, // 防抖
122
118
  queryParam: { select: { $master: true } },
119
+ staticSearchable: true,
123
120
  },
124
121
  lifetimes: {
125
122
  attached() {
@@ -143,7 +140,6 @@ Component({
143
140
  // 默认
144
141
  this.setData({
145
142
  option: range,
146
- loadStatus: range.length > 0 ? 0 : -1,
147
143
  value: this.properties.defaultValue,
148
144
  cls,
149
145
  subCls,
@@ -175,6 +171,11 @@ Component({
175
171
  value: this.properties.defaultValue,
176
172
  });
177
173
  },
174
+ format: function (format) {
175
+ this.setData({
176
+ staticSearchable: !['many-many', 'one-many'].includes(format),
177
+ });
178
+ },
178
179
  'value,range': function () {
179
180
  const { range, format } = this.properties;
180
181
  if (format !== 'one-many' && format !== 'many-many') {
@@ -187,6 +188,7 @@ Component({
187
188
  this.setData({
188
189
  option: checkRange,
189
190
  displayLabel: label,
191
+ loadStatus: range.length > 0 ? 0 : -1,
190
192
  });
191
193
  },
192
194
  dataSourceName: function () {
@@ -259,7 +261,7 @@ Component({
259
261
  // eslint-disable-next-line rulesdir/no-timer
260
262
  this.data.fetchTimed = setTimeout(() => {
261
263
  const { format, dataSourceName, primaryField } = this.properties;
262
- if (['many-many', 'one-many'].concat(format) && dataSourceName && primaryField) {
264
+ if (['many-many', 'one-many'].includes(format) && dataSourceName && primaryField) {
263
265
  this.setData({ records: [], option: [], pageNo: 1 });
264
266
  this._fetchData({ searchValue, _init: true });
265
267
  }
@@ -270,6 +272,7 @@ Component({
270
272
  _fetchData: async function ({ queryParam = this.data.queryParam, searchValue = '', pageNo = 1, _init = false }) {
271
273
  const { dataSourceName, primaryField } = this.properties;
272
274
  if (!dataSourceName) return;
275
+ this.setData({ loadStatus: 1 });
273
276
  // 默认筛选条件
274
277
  let _filter = destr(this.data.queryParam.filter) ?? {};
275
278
  // 根据搜索值查询
@@ -304,9 +307,9 @@ Component({
304
307
  finalRecords = this.getUniqueOption(finalRecords);
305
308
  const { value } = this.data;
306
309
 
307
- const unchecked = value.filter((i) => !finalRecords.find((j) => i === j.value));
310
+ const unchecked = value?.filter((i) => !finalRecords.find((j) => i === j.value));
308
311
  // 跨页勾选回显示
309
- if (unchecked.length) {
312
+ if (unchecked?.length) {
310
313
  const uncheckedItem = await this.fetchItem(unchecked);
311
314
  uncheckedItem?.forEach((i) => {
312
315
  if (i) {
@@ -251,7 +251,8 @@ Component({
251
251
  };
252
252
  const uploadPath = 'weda-uploader';
253
253
  const _uploadPath = await getDefaultUploadPath(uploadPath);
254
- const cloudPath = `${_uploadPath}/${randomStr()}-${tempFile.name}`;
254
+ const filenameRegex = /[^a-zA-Z0-9\u4e00-\u9fff-*!_.]/g;
255
+ const cloudPath = `${_uploadPath}/${randomStr()}-${tempFile.name?.replace(filenameRegex, '-')}`;
255
256
  try {
256
257
  const tcb = await getCloudInstance();
257
258
  const uploadTask = await tcb.uploadFile({
@@ -5,6 +5,7 @@ import { commonCompBehavior } from '../../utils/common-behavior';
5
5
  import { callDataSource } from '../../utils/tcb';
6
6
  import isEqual from '../../utils/deepEqual';
7
7
  import { textToString } from '../../utils/platform';
8
+ import { deepClone } from '../../utils/lodash';
8
9
 
9
10
  import { WdCompError } from '../../utils/error';
10
11
  const LISTVIEW_MESSAGE = {
@@ -175,6 +176,7 @@ Component({
175
176
  },
176
177
  },
177
178
  paramRef: [],
179
+ preDataSourceCache: [],
178
180
  },
179
181
  methods: {
180
182
  // 数据列表设置表达式: 区分前后端分页
@@ -185,7 +187,7 @@ Component({
185
187
  let total = 0;
186
188
  if (Array.isArray(dataSourceData)) {
187
189
  if (enableTotal) {
188
- records = dataSourceData;
190
+ records = deepClone(dataSourceData);
189
191
  total = !isNaN(parseInt(`${_total}`)) ? _total : 0;
190
192
  } else {
191
193
  const count = pageSize * pageNo;
@@ -603,7 +605,10 @@ Component({
603
605
  });
604
606
  }, 500);
605
607
  },
606
- 'dataSourceType,dataSourceData,total,enableTotal': function () {
608
+ 'dataSourceType,dataSourceData,total,enableTotal': function (...rest) {
609
+ if (isEqual(this.data.preDataSourceCache, rest)) return;
610
+
611
+ this.setData({ preDataSourceCache: rest });
607
612
  if (this.properties.dataSourceType === 'expression') {
608
613
  // console.log('====dataSourceData====', this.data.dataSourceData);
609
614
  this.setExpression();
@@ -16,8 +16,7 @@ import equal from '../../utils/deepEqual';
16
16
  * @param currentName 当前表单项名称
17
17
  * @returns
18
18
  */
19
- const getValueName = (operateName, currentName) =>
20
- operateName.replace(new RegExp(`^${currentName}(\\.)?`), '');
19
+ const getValueName = (operateName, currentName) => operateName.replace(new RegExp(`^${currentName}(\\.)?`), '');
21
20
 
22
21
  Component({
23
22
  options: { virtualHost: true },
@@ -64,10 +63,7 @@ Component({
64
63
  that.change({ type: 'add' }, { isUpdateParentForm: false });
65
64
  },
66
65
  remove({ index = -1 } = {}) {
67
- that.change(
68
- { type: 'remove', value: index },
69
- { isUpdateParentForm: false }
70
- );
66
+ that.change({ type: 'remove', value: index }, { isUpdateParentForm: false });
71
67
  },
72
68
  change(params) {
73
69
  that.change(params, { isUpdateParentForm: true });
@@ -100,14 +96,10 @@ Component({
100
96
  * @returns
101
97
  */
102
98
  addFormItem(childName, formItem) {
103
- if (
104
- isNil(childName) ||
105
- !formItem ||
106
- (typeof childName === 'string' && childName.length === 0)
107
- ) {
99
+ if (isNil(childName) || !formItem || (typeof childName === 'string' && childName.length === 0)) {
108
100
  // childName 没设置或为空串的时候不受表单容器控制
109
101
  console.warn(
110
- `组件 #${formItem?.id} 表单key(表单输入类组件 childName 属性)没设置或为空串的时候不受表单容器控制`
102
+ `组件 #${formItem?.id} 表单key(表单输入类组件 childName 属性)没设置或为空串的时候不受表单容器控制`,
111
103
  );
112
104
  return noop;
113
105
  }
@@ -119,9 +111,7 @@ Component({
119
111
  }
120
112
  that.setData({ formsItemMap });
121
113
  return () => {
122
- const removedArr = formsItemMap[childName].filter(
123
- (item) => item !== formItem
124
- );
114
+ const removedArr = formsItemMap[childName].filter((item) => item !== formItem);
125
115
  if (removedArr.length <= 0) {
126
116
  delete formsItemMap[childName];
127
117
  } else {
@@ -144,8 +134,7 @@ Component({
144
134
  });
145
135
  },
146
136
  updateWidgetAPI(apis = {}) {
147
- const { name, objValue, label, visible, readOnly, disabled, status } =
148
- this.data;
137
+ const { name, objValue, label, visible, readOnly, disabled, status } = this.data;
149
138
  this.setReadonlyAttributes?.({
150
139
  ...apis,
151
140
  label,
@@ -163,16 +152,12 @@ Component({
163
152
  },
164
153
  // 父级普通表单对象
165
154
  getParentForm() {
166
- const parent = this?.$widget?.closest(
167
- (w) => w.getConfig?.().componentType === 'form'
168
- );
155
+ const parent = this?.$widget?.closest((w) => w.getConfig?.().componentType === 'form');
169
156
  return parent;
170
157
  },
171
158
  // 父级嵌套表单对象
172
159
  getParentFormObj() {
173
- const parent = this?.$widget?.closest(
174
- (w) => w.getConfig?.().componentType === 'formObj'
175
- );
160
+ const parent = this?.$widget?.closest((w) => w.getConfig?.().componentType === 'formObj');
176
161
  return parent;
177
162
  },
178
163
  /**
@@ -192,10 +177,7 @@ Component({
192
177
  if (!Array.isArray(items)) {
193
178
  items = [items];
194
179
  }
195
- const newValue = lodashGet(
196
- value,
197
- getValueName(childName, this.data.name)
198
- );
180
+ const newValue = lodashGet(value, getValueName(childName, this.data.name));
199
181
  items.forEach((item) => {
200
182
  if (item?.setValue && !equal(item.value, newValue)) {
201
183
  item.setValue(newValue);
@@ -226,10 +208,7 @@ Component({
226
208
  }
227
209
  return value;
228
210
  },
229
- change(
230
- params,
231
- { isUpdateParentForm = false, isUpdateChildValue = true } = {}
232
- ) {
211
+ change(params, { isUpdateParentForm = false, isUpdateChildValue = true } = {}) {
233
212
  const { objValue, name, addDefaultValue } = this.data;
234
213
  let value = deepClone(params.value);
235
214
 
@@ -244,10 +223,7 @@ Component({
244
223
  // 触发删除操作,则删除对应索引的值
245
224
  if (params.type === 'remove') {
246
225
  value = deepClone(objValue);
247
- value = [
248
- ...value.slice(0, params.value),
249
- ...value.slice(params.value + 1),
250
- ];
226
+ value = [...value.slice(0, params.value), ...value.slice(params.value + 1)];
251
227
  }
252
228
  }
253
229
 
@@ -294,8 +270,6 @@ Component({
294
270
  // 外部直接调用formObj.setValue的情况下,触发父级嵌套表单值更新
295
271
  parentFormObj?.__setValueImmediate__?.({ name, value });
296
272
  }
297
-
298
- this.triggerOnDataChange(value);
299
273
  },
300
274
  /**
301
275
  * 子组件默认值变更,触发嵌套表单值更新
@@ -320,9 +294,7 @@ Component({
320
294
 
321
295
  if (params.name) {
322
296
  // 判断是否将当前的name前缀加上,以便父级嵌套表单更新值
323
- const nameTemp = `${
324
- !params.name.startsWith(name) && name ? `${name}.` : ''
325
- }${params.name}`;
297
+ const nameTemp = `${!params.name.startsWith(name) && name ? `${name}.` : ''}${params.name}`;
326
298
  // 将值同步给父级嵌套表单
327
299
  parentFormObj?.__setValueImmediate__?.({
328
300
  name: nameTemp,
@@ -361,7 +333,7 @@ Component({
361
333
  this.change({ value }, { isUpdateParentForm: true });
362
334
  });
363
335
  },
364
- objValue: function () {
336
+ objValue: function (value) {
365
337
  this.updateWidgetAPI();
366
338
  // 更新子组件的值需要主动去调用,不被动执行
367
339
  // 如果是最顶层的嵌套表单,则去更新子组件的值,否则自己的值更新不去触发子组件值更新,因为父级普通表单会去更新
@@ -369,6 +341,10 @@ Component({
369
341
  // if (!parentFormObj) {
370
342
  // // this.updateChildValue(objValue);
371
343
  // }
344
+ const tempValue = this.getTempValue(value);
345
+ if (equal(tempValue, this.data.objValue)) {
346
+ this.triggerOnDataChange(value);
347
+ }
372
348
  },
373
349
  },
374
350
  });
@@ -25,6 +25,7 @@ Component({
25
25
  counter: 0,
26
26
  placeholderCls: `${WD_PREFIX}-form-input-wrap__placeholder weui-input__placeholder`,
27
27
  _size: 'md',
28
+ _focus: false,
28
29
  },
29
30
  methods: {
30
31
  handleChange: function (e) {
@@ -32,17 +33,18 @@ Component({
32
33
  this.triggerEvent('change', e.detail);
33
34
  },
34
35
  handleFocus: function (e) {
36
+ this.setData({ _focus: true });
35
37
  this.triggerEvent('focus', e.detail);
36
38
  },
37
39
  handleBlur: function (e) {
40
+ this.setData({ _focus: false });
38
41
  this.triggerEvent('blur', e.detail);
39
42
  },
40
43
  handleConfirm: function (e) {
41
44
  this.triggerEvent('confirm', e.detail);
42
45
  },
43
46
  updateWidgetAPI: function () {
44
- const { name, value, label, required, visible, disabled, readOnly } =
45
- this.data;
47
+ const { name, value, label, required, visible, disabled, readOnly } = this.data;
46
48
  this.setReadonlyAttributes?.({
47
49
  name,
48
50
  value,
@@ -54,7 +56,7 @@ Component({
54
56
  });
55
57
  },
56
58
  init() {
57
- const { disabled, size, classRoot } = this.data;
59
+ const { disabled, size, classRoot, _focus } = this.data;
58
60
  const { classPrefix } = this.data;
59
61
  const _size = convertSize(size);
60
62
  const root = `${classPrefix}-${classRoot}`;
@@ -70,14 +72,15 @@ Component({
70
72
  'size-width-hundred': true,
71
73
  'is-disabled': disabled,
72
74
  'textarea-restriction': true,
73
- }
75
+ 'is-focused': _focus,
76
+ },
74
77
  );
75
78
  const countCls = `${textareaWrap}__label ${root}-${classRoot}__count-text`;
76
79
  this.setData({ cls, countCls, _size });
77
80
  },
78
81
  },
79
82
  observers: {
80
- 'disabled,counterVisible,size,classRoot': function () {
83
+ 'disabled,counterVisible,size,classRoot,_focus': function () {
81
84
  this.init();
82
85
  },
83
86
  value: function (value) {
@@ -87,6 +90,9 @@ Component({
87
90
  'name, value, label, required, visible, disabled, readOnly': function () {
88
91
  this.updateWidgetAPI();
89
92
  },
93
+ focus: function (focus) {
94
+ this.setData({ _focus: focus });
95
+ },
90
96
  },
91
97
  lifetimes: {
92
98
  attached: function () {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.15.1",
6
+ "version": "3.15.3",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"