@tuya-miniapp/smart-ui 2.10.0-beta-0 → 2.10.0-beta-1

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.
@@ -22,19 +22,25 @@ SmartComponent({
22
22
  type: String,
23
23
  value: 'right',
24
24
  },
25
- show: {
25
+ isControl: {
26
26
  type: Boolean,
27
+ value: false,
28
+ },
29
+ show: {
30
+ type: null,
27
31
  observer(value) {
32
+ // 动态设置受控模式:如果 show 有值(不是 undefined 或 null),则为受控模式
33
+ // 如果 show 为 undefined 或 null,则为非受控模式
28
34
  if (this.data.cancel_timer) {
29
35
  clearTimeout(this.data.cancel_timer);
30
36
  this.data.cancel_timer = null;
31
37
  }
32
- if (value !== this.data.currentShow) {
38
+ if (value !== this.data.currentShow || this.data.isControl) {
33
39
  if (value) {
34
- this.onOpen();
40
+ this.onOpen(!this.data.isControl);
35
41
  }
36
42
  else {
37
- this.onClose();
43
+ this.onClose(!this.data.isControl);
38
44
  }
39
45
  }
40
46
  },
@@ -169,10 +175,18 @@ SmartComponent({
169
175
  this.setData(params);
170
176
  },
171
177
  onClick() {
178
+ if (this.data.isControl) {
179
+ // 受控模式下,不触发 show-change 事件,由外部控制
180
+ return;
181
+ }
182
+ // 非受控模式下,如果 show 为 false,则不打开
183
+ if (this.data.show === false) {
184
+ return;
185
+ }
172
186
  this.onOpen();
173
187
  },
174
188
  noop() { },
175
- onOpen() {
189
+ onOpen(trigger = true) {
176
190
  this.getButtonPosition();
177
191
  this.setData({
178
192
  currentShow: true,
@@ -182,14 +196,14 @@ SmartComponent({
182
196
  showStyle: 'opacity: 1;',
183
197
  });
184
198
  }, 100);
185
- this.$emit('show-change', true);
199
+ trigger && this.$emit('show-change', true);
186
200
  if (this.data.duration) {
187
201
  this.data.cancel_timer = setTimeout(() => {
188
- this.onClose();
202
+ this.onClose(trigger);
189
203
  }, this.data.duration);
190
204
  }
191
205
  },
192
- onClose() {
206
+ onClose(trigger = true) {
193
207
  if (this.data.cancel_timer) {
194
208
  clearTimeout(this.data.cancel_timer);
195
209
  this.data.cancel_timer = null;
@@ -201,8 +215,8 @@ SmartComponent({
201
215
  this.setData({
202
216
  currentShow: false,
203
217
  });
204
- this.$emit('show-change', false);
205
- this.$emit('close', false);
218
+ trigger && this.$emit('show-change', false);
219
+ trigger && this.$emit('close', false);
206
220
  }, 300);
207
221
  },
208
222
  },
@@ -35,19 +35,25 @@ function createSvgIcon(svg) {
35
35
  type: String,
36
36
  value: 'right',
37
37
  },
38
- show: {
38
+ isControl: {
39
39
  type: Boolean,
40
+ value: false,
41
+ },
42
+ show: {
43
+ type: null,
40
44
  observer: function (value) {
45
+ // 动态设置受控模式:如果 show 有值(不是 undefined 或 null),则为受控模式
46
+ // 如果 show 为 undefined 或 null,则为非受控模式
41
47
  if (this.data.cancel_timer) {
42
48
  clearTimeout(this.data.cancel_timer);
43
49
  this.data.cancel_timer = null;
44
50
  }
45
- if (value !== this.data.currentShow) {
51
+ if (value !== this.data.currentShow || this.data.isControl) {
46
52
  if (value) {
47
- this.onOpen();
53
+ this.onOpen(!this.data.isControl);
48
54
  }
49
55
  else {
50
- this.onClose();
56
+ this.onClose(!this.data.isControl);
51
57
  }
52
58
  }
53
59
  },
@@ -182,11 +188,20 @@ function createSvgIcon(svg) {
182
188
  this.setData(params);
183
189
  },
184
190
  onClick: function () {
191
+ if (this.data.isControl) {
192
+ // 受控模式下,不触发 show-change 事件,由外部控制
193
+ return;
194
+ }
195
+ // 非受控模式下,如果 show 为 false,则不打开
196
+ if (this.data.show === false) {
197
+ return;
198
+ }
185
199
  this.onOpen();
186
200
  },
187
201
  noop: function () { },
188
- onOpen: function () {
202
+ onOpen: function (trigger) {
189
203
  var _this = this;
204
+ if (trigger === void 0) { trigger = true; }
190
205
  this.getButtonPosition();
191
206
  this.setData({
192
207
  currentShow: true,
@@ -196,15 +211,16 @@ function createSvgIcon(svg) {
196
211
  showStyle: 'opacity: 1;',
197
212
  });
198
213
  }, 100);
199
- this.$emit('show-change', true);
214
+ trigger && this.$emit('show-change', true);
200
215
  if (this.data.duration) {
201
216
  this.data.cancel_timer = setTimeout(function () {
202
- _this.onClose();
217
+ _this.onClose(trigger);
203
218
  }, this.data.duration);
204
219
  }
205
220
  },
206
- onClose: function () {
221
+ onClose: function (trigger) {
207
222
  var _this = this;
223
+ if (trigger === void 0) { trigger = true; }
208
224
  if (this.data.cancel_timer) {
209
225
  clearTimeout(this.data.cancel_timer);
210
226
  this.data.cancel_timer = null;
@@ -216,8 +232,8 @@ function createSvgIcon(svg) {
216
232
  _this.setData({
217
233
  currentShow: false,
218
234
  });
219
- _this.$emit('show-change', false);
220
- _this.$emit('close', false);
235
+ trigger && _this.$emit('show-change', false);
236
+ trigger && _this.$emit('close', false);
221
237
  }, 300);
222
238
  },
223
239
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/smart-ui",
3
- "version": "2.10.0-beta-0",
3
+ "version": "2.10.0-beta-1",
4
4
  "author": "MiniApp Team",
5
5
  "license": "MIT",
6
6
  "miniprogram": "lib",