@cloudbase/weda-ui-mp 3.27.3 → 3.28.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.
- package/components/container/index.js +1 -0
- package/components/form/location/index.js +16 -0
- package/components/form/location/index.wxss +1 -1
- package/components/scrollView/index.js +209 -10
- package/components/scrollView/index.wxml +1 -1
- package/components/wd-location/index.js +1 -1
- package/components/wd-location/index.wxml +1 -0
- package/package.json +1 -1
|
@@ -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 || {};
|
|
@@ -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(
|
|
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 = {
|
|
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
|
-
{
|
|
126
|
-
|
|
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
|
-
{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
{
|
|
136
|
-
|
|
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="{{
|
|
21
|
+
enhanced="{{currentEnhanced}}"
|
|
22
22
|
bounces="{{bounces}}"
|
|
23
23
|
show-scrollbar="{{showScrollbar}}"
|
|
24
24
|
paging-enabled="{{pagingEnabled}}"
|