@cloudbase/weda-ui-mp 3.27.3 → 3.29.0

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.
@@ -27,6 +27,7 @@ Component({
27
27
  observers: {
28
28
  data: function (data) {
29
29
  this.setReadonlyAttributes?.({ data });
30
+ this.setData({ id: this.id });
30
31
  },
31
32
  },
32
33
  });
@@ -441,9 +441,25 @@ Component({
441
441
  handleError: function (e) {
442
442
  this.triggerEvent('error', e.detail);
443
443
  },
444
+ openLocation: function (e) {
445
+ wx.openLocation({
446
+ latitude: e.detail.latitude,
447
+ longitude: e.detail.longitude,
448
+ scale: 18
449
+ });
450
+ }
444
451
  },
445
452
  observers: {
446
453
  value: function (value) {
454
+ if (!value) {
455
+ // 清空地图
456
+ this.setData({
457
+ currentLocations: {},
458
+ location: {},
459
+ isAddrShow: false
460
+ });
461
+ return;
462
+ }
447
463
  const currentLocations = this.data.currentLocations;
448
464
  if (value || !currentLocations.latitude) {
449
465
  const { geopoint: { coordinates } = {}, address: poiname, detailedAddress } = value || {};
@@ -58,7 +58,7 @@
58
58
  .form-location-con__text {
59
59
  margin-left: 4px;
60
60
  cursor: pointer;
61
- color: #0052d9;
61
+ color: var(--wd-color-brand, #0052d9);
62
62
  }
63
63
 
64
64
  .form-location_cell {
@@ -1,11 +1,10 @@
1
1
  @font-face {
2
2
  font-family: WdTd;
3
- src: url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.eot'),
4
- url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t_iefix.eot')
5
- format('embedded-opentype'),
6
- url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.woff') format('woff'),
7
- url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.ttf') format('truetype'),
8
- url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.svg') format('svg');
3
+ src: url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t.eot'),
4
+ url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t_iefix.eot') format('embedded-opentype'),
5
+ url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t.woff') format('woff'),
6
+ url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t.ttf') format('truetype'),
7
+ url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t.svg') format('svg');
9
8
  font-weight: 400;
10
9
  font-style: normal;
11
10
  }
@@ -1,9 +1,11 @@
1
1
  import handleEvents from '../../utils/handleEvents';
2
+ import { commonCompBehavior } from '../../utils/common-behavior';
2
3
 
3
4
  Component({
4
5
  options: {
5
6
  virtualHost: true,
6
7
  },
8
+ behaviors: [commonCompBehavior],
7
9
  properties: {
8
10
  id: {
9
11
  type: String,
@@ -41,6 +43,7 @@ Component({
41
43
  },
42
44
  scrollIntoView: {
43
45
  type: String,
46
+ value: '',
44
47
  },
45
48
  scrollWithAnimation: {
46
49
  type: Boolean,
@@ -98,16 +101,102 @@ Component({
98
101
  type: Boolean,
99
102
  value: false,
100
103
  },
104
+ observerSelector: {
105
+ type: Array,
106
+ value: [],
107
+ },
108
+ observerThreshold: {
109
+ type: Number,
110
+ value: 0,
111
+ },
112
+ rootMargin: {
113
+ type: Object,
114
+ value: {
115
+ top: 0,
116
+ bottom: 0,
117
+ left: 0,
118
+ right: 0,
119
+ },
120
+ },
101
121
  },
122
+ domObserver: [],
102
123
  data: {
103
124
  clientHeight: 0,
104
125
  clientWidth: 0,
126
+ currentScrollTop: 0,
127
+ currentScrollLeft: 0,
128
+ currentTop: 0,
129
+ currentLeft: 0,
130
+ scrollViewContext: null,
131
+ currentEnhanced: false,
105
132
  },
106
133
  methods: {
134
+ init() {
135
+ const query = wx.createSelectorQuery().in(this);
136
+ query
137
+ .select(`#${this.id}`)
138
+ .node()
139
+ .exec((res) => {
140
+ const scrollViewContext = res[0]?.node;
141
+ this.setData({ scrollViewContext });
142
+ this.triggerEvent('onReady', { scrollViewContext });
143
+ });
144
+ },
145
+ updateWidgetAPI() {
146
+ const that = this;
147
+ this.setReadonlyAttributes &&
148
+ this.setReadonlyAttributes({
149
+ scrollViewContext: this.data.scrollViewContext,
150
+ scrollIntoElement({ selector }) {
151
+ that.scrollIntoView(selector);
152
+ },
153
+ });
154
+ },
155
+ observeHandle(selector, callback) {
156
+ const { rootMargin } = this.data;
157
+ const _rootMargin = {
158
+ top: parseInt(rootMargin.top),
159
+ bottom: parseInt(rootMargin.bottom),
160
+ left: parseInt(rootMargin.left),
161
+ right: parseInt(rootMargin.right),
162
+ };
163
+ // 自定义组件场景,只能用wx.createIntersectionObserver创建,且不支持配置threshold参数
164
+ const observe = wx
165
+ .createIntersectionObserver()
166
+ .relativeToViewport(_rootMargin)
167
+ .observe(`.wd-mp-root >>> .${selector}`, (res) => {
168
+ // 模块曝光
169
+ if (res.intersectionRatio) {
170
+ callback(res);
171
+ } else {
172
+ console.warn('元素未找到:', selector);
173
+ }
174
+ });
175
+ return observe;
176
+ },
177
+ // 监听模块曝光
178
+ observeModuleExpose() {
179
+ if (this.domObserver?.length) {
180
+ this.domObserver.forEach((element) => {
181
+ element?.disconnect();
182
+ });
183
+ }
184
+ if (this.data.observerSelector?.length) {
185
+ const domObserver = this.data.observerSelector?.map((i) => {
186
+ // 小程序暂时只支持class
187
+ let selector = i.replace('#', '').replace('.', '');
188
+ return this.observeHandle(selector, (res) => {
189
+ this.triggerEvent('scrollToTarget', res);
190
+ });
191
+ });
192
+ this.domObserver = domObserver;
193
+ }
194
+ },
195
+
107
196
  getComponentClientHeight: function () {
108
197
  const that = this;
109
198
  const query = wx.createSelectorQuery().in(this);
110
- query.select('.g-scroll-view').boundingClientRect();
199
+ query.select(`#${this.id}`).boundingClientRect();
111
200
  query.exec((res) => {
112
201
  that.setData({
113
202
  clientHeight: res[0]?.height,
@@ -117,28 +206,138 @@ Component({
117
206
  },
118
207
  scroll: function (event) {
119
208
  const { clientHeight, clientWidth } = this.data;
120
- const detail = { ...event.detail, clientHeight, clientWidth };
209
+ const detail = {
210
+ ...event.detail,
211
+ clientHeight,
212
+ clientWidth,
213
+ };
121
214
  this.triggerEvent('scroll', detail);
122
215
  },
216
+ scrollIntoView(elementId) {
217
+ if (!this.data.currentEnhanced) {
218
+ this.setData({ currentEnhanced: true });
219
+ }
220
+ const queryScroll = wx.createSelectorQuery().in(this);
221
+ queryScroll
222
+ .select(`#${this.id}`)
223
+ .scrollOffset()
224
+ .select(`#${this.id}`)
225
+ .boundingClientRect()
226
+ .exec((res) => {
227
+ const scrollOffset = res?.[0];
228
+ const node = res?.[1];
229
+ if (scrollOffset) {
230
+ this.setData({
231
+ currentScrollTop: scrollOffset?.scrollTop ?? 0,
232
+ currentScrollLeft: scrollOffset?.scrollLeft ?? 0,
233
+ });
234
+ }
235
+ if (node) {
236
+ this.setData({ currentTop: node?.top ?? 0, currentLeft: node?.left ?? 0 });
237
+ }
238
+ });
239
+
240
+ const { scrollY, scrollX, scrollViewContext } = this.data;
241
+ // 自定义组件无法通过id获取到子元素,转换为通过跨自定义组件的后代选择器选取 .the-ancestor >>> .the-descendant
242
+ let selector = elementId.replace('#', '').replace('.', '');
243
+ const query = wx.createSelectorQuery();
244
+ query
245
+ .select(`.wd-mp-root >>> .wd-comp-id-${selector}`)
246
+ .boundingClientRect()
247
+ .select(`.wd-mp-root >>> .${selector}`)
248
+ .boundingClientRect()
249
+ .exec((res) => {
250
+ const node = res[0] || res[1];
251
+ if (node) {
252
+ const top = node.top + this.data.currentScrollTop - this.data.currentTop + 1;
253
+ const left = node.left + this.data.currentScrollLeft - this.data.currentLeft + 1;
254
+ if (scrollY && scrollViewContext) {
255
+ scrollViewContext.scrollTo({
256
+ top: top,
257
+ animated: true,
258
+ });
259
+ }
260
+ if (scrollX && scrollViewContext) {
261
+ scrollViewContext.scrollTo({
262
+ left: left,
263
+ animated: true,
264
+ });
265
+ }
266
+ } else {
267
+ console.warn('元素未找到:', selector);
268
+ }
269
+ });
270
+ },
123
271
  ...handleEvents([
124
272
  // { name: 'scroll', title: '滚动时触发' },
125
- { name: 'scrolltolower', title: '滚动到底部/右边时触发' },
126
- { name: 'scrolltoupper', title: '滚动到顶部/左边时触发' },
273
+ {
274
+ name: 'scrolltolower',
275
+ title: '滚动到底部/右边时触发',
276
+ },
277
+ {
278
+ name: 'scrolltoupper',
279
+ title: '滚动到顶部/左边时触发',
280
+ },
127
281
  {
128
282
  name: 'dragstart',
129
283
  title: '滑动开始事件(同时开启 enhanced 属性后生效)',
130
284
  },
131
- { name: 'dragging', title: '滑动事件(同时开启 enhanced 属性后生效)' },
132
- { name: 'dragend', title: '滑动结束事件(同时开启 enhanced 属性后生效)' },
133
- { name: 'refresherpulling', title: '自定义下拉刷新控件被下拉' },
134
- { name: 'refresherrefresh', title: '自定义下拉刷新被触发' },
135
- { name: 'refresherrestore', title: '自定义下拉刷新被复位' },
136
- { name: 'refresherabort', title: '自定义下拉刷新被中止' },
285
+ {
286
+ name: 'dragging',
287
+ title: '滑动事件(同时开启 enhanced 属性后生效)',
288
+ },
289
+ {
290
+ name: 'dragend',
291
+ title: '滑动结束事件(同时开启 enhanced 属性后生效)',
292
+ },
293
+ {
294
+ name: 'refresherpulling',
295
+ title: '自定义下拉刷新控件被下拉',
296
+ },
297
+ {
298
+ name: 'refresherrefresh',
299
+ title: '自定义下拉刷新被触发',
300
+ },
301
+ {
302
+ name: 'refresherrestore',
303
+ title: '自定义下拉刷新被复位',
304
+ },
305
+ {
306
+ name: 'refresherabort',
307
+ title: '自定义下拉刷新被中止',
308
+ },
137
309
  ]),
138
310
  },
311
+ observers: {
312
+ enhanced: function (enhanced) {
313
+ this.setData({
314
+ currentEnhanced: enhanced,
315
+ });
316
+ },
317
+ scrollIntoView: function (scrollIntoView) {
318
+ this.scrollIntoView(scrollIntoView);
319
+ },
320
+ scrollViewContext: function () {
321
+ this.updateWidgetAPI();
322
+ },
323
+ },
139
324
  lifetimes: {
325
+ attached() {
326
+ this.setData({ id: this.id });
327
+ this.init();
328
+ this.updateWidgetAPI();
329
+ },
140
330
  ready() {
141
331
  this.getComponentClientHeight();
332
+
333
+ this.observeModuleExpose();
334
+ },
335
+ detached() {
336
+ if (this.domObserver?.length) {
337
+ this.domObserver?.forEach((i) => {
338
+ i?.disconnect();
339
+ });
340
+ }
142
341
  },
143
342
  },
144
343
  });
@@ -18,7 +18,7 @@
18
18
  refresher-default-style="{{refresherDefaultStyle}}"
19
19
  refresher-background="{{refresherBackground}}"
20
20
  refresher-triggered="{{refresherTriggered}}"
21
- enhanced="{{enhanced}}"
21
+ enhanced="{{currentEnhanced}}"
22
22
  bounces="{{bounces}}"
23
23
  show-scrollbar="{{showScrollbar}}"
24
24
  paging-enabled="{{pagingEnabled}}"
@@ -9,6 +9,7 @@ import { WdCompError } from '../../utils/error';
9
9
  import { getErrorObjectFromValidateResult, getFormDataFromItemMap } from './form-utils';
10
10
  import lodashGet from 'lodash.get';
11
11
  import debounce from '../../utils/debounce';
12
+ import { convertMethodParam } from '../../utils/getFormLegacy';
12
13
 
13
14
  const formTypeWithInitValue = ['edit', 'read'];
14
15
  const debounceMs = 100;
@@ -82,8 +83,13 @@ Component({
82
83
  },
83
84
  },
84
85
  methods: {
85
- setValue(data, setNull) {
86
- data = Object.freeze(JSON.parse(JSON.stringify(data)));
86
+ setValue(_data, setNull) {
87
+ if (typeof _data !== 'object' || _data === null) {
88
+ console.warn('setValue data need expect a object but got null', _data);
89
+ return;
90
+ }
91
+ _data = convertMethodParam(_data);
92
+ const data = Object.freeze(JSON.parse(JSON.stringify(_data)));
87
93
  // Object.entries(that.data._formItemMap).forEach(())
88
94
  Object.keys(this.data._formItemMap).forEach((name) => {
89
95
  const items = this.data._formItemMap[name];
@@ -58,7 +58,7 @@ Component({
58
58
  lifetimes: {
59
59
  attached: function () {
60
60
  this.updateWidgetAPI();
61
- this.setData({ id: this.id });
61
+ this.setData({ id: this.id, _oldLocationValue: this.data.value });
62
62
  },
63
63
  },
64
64
  });
@@ -43,6 +43,7 @@
43
43
  disabled="{{disabled || readOnly}}"
44
44
  bind:change="handleChange"
45
45
  bind:error="handleError"
46
+ openLocation="{{openLocation}}"
46
47
  />
47
48
  </wd-input-wrap>
48
49
  </wd-input-group>
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "miniprogram": "./",
4
4
  "packageManager": "yarn@3.0.2",
5
5
  "dependencies": {},
6
- "version": "3.27.3",
6
+ "version": "3.29.0",
7
7
  "main": "./",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -1,11 +1,11 @@
1
1
  @font-face {
2
2
  font-family: WdTd;
3
- src: url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.eot'),
4
- url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t_iefix.eot')
3
+ src: url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t.eot'),
4
+ url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t_iefix.eot')
5
5
  format('embedded-opentype'),
6
- url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.woff') format('woff'),
7
- url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.ttf') format('truetype'),
8
- url('https://comp-public-replace-1303824488-cos.weda.tencent.com/icon/0.0.7/t.svg') format('svg');
6
+ url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t.woff') format('woff'),
7
+ url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t.ttf') format('truetype'),
8
+ url('https://comp-public-replace-cos.cloudbase.net/icon/0.0.7/t.svg') format('svg');
9
9
  font-weight: 400;
10
10
  font-style: normal;
11
11
  }