@mpxjs/webpack-plugin 2.10.18-beta.1 → 2.10.19
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/LICENSE +433 -0
- package/lib/index.js +0 -12
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +4 -4
- package/lib/runtime/components/react/dist/mpx-camera.jsx +75 -41
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +92 -15
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +24 -43
- package/lib/runtime/components/react/mpx-camera.tsx +78 -47
- package/lib/runtime/components/react/mpx-scroll-view.tsx +106 -16
- package/lib/runtime/components/react/mpx-swiper.tsx +23 -43
- package/lib/runtime/components/web/mpx-scroll-view.vue +2 -5
- package/lib/template-compiler/compiler.js +3 -7
- package/lib/utils/const.js +0 -29
- package/package.json +4 -3
- package/lib/resolver/ExtendComponentsPlugin.js +0 -60
- package/lib/runtime/components/ali/mpx-section-list.mpx +0 -566
- package/lib/runtime/components/ali/mpx-sticky-header.mpx +0 -212
- package/lib/runtime/components/ali/mpx-sticky-section.mpx +0 -17
- package/lib/runtime/components/react/dist/mpx-section-list.d.ts +0 -48
- package/lib/runtime/components/react/dist/mpx-section-list.jsx +0 -292
- package/lib/runtime/components/react/mpx-section-list.tsx +0 -439
- package/lib/runtime/components/web/mpx-section-list.vue +0 -551
- package/lib/runtime/components/wx/mpx-section-list-default/list-footer.mpx +0 -26
- package/lib/runtime/components/wx/mpx-section-list-default/list-header.mpx +0 -26
- package/lib/runtime/components/wx/mpx-section-list-default/list-item.mpx +0 -26
- package/lib/runtime/components/wx/mpx-section-list-default/section-header.mpx +0 -26
- package/lib/runtime/components/wx/mpx-section-list.mpx +0 -209
- package/lib/runtime/components/wx/mpx-sticky-header.mpx +0 -40
- package/lib/runtime/components/wx/mpx-sticky-section.mpx +0 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.19",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@d11/react-native-fast-image": "^8.6.12",
|
|
87
|
-
"@mpxjs/api-proxy": "^2.10.
|
|
87
|
+
"@mpxjs/api-proxy": "^2.10.19",
|
|
88
88
|
"@types/babel-traverse": "^6.25.4",
|
|
89
89
|
"@types/babel-types": "^7.0.4",
|
|
90
90
|
"@types/glob": "^8.1.0",
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"react-native-safe-area-context": "^4.12.0",
|
|
98
98
|
"react-native-svg": "^15.8.0",
|
|
99
99
|
"react-native-video": "^6.9.0",
|
|
100
|
+
"react-native-vision-camera": "^4.7.2",
|
|
100
101
|
"react-native-webview": "^13.12.2",
|
|
101
102
|
"rimraf": "^6.0.1",
|
|
102
103
|
"webpack": "^5.75.0"
|
|
@@ -104,5 +105,5 @@
|
|
|
104
105
|
"engines": {
|
|
105
106
|
"node": ">=14.14.0"
|
|
106
107
|
},
|
|
107
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "ca50ba6b1361f3c7790746476dd8b8e6be802ea3"
|
|
108
109
|
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const { EXTEND_COMPONENT_CONFIG } = require('../utils/const')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 扩展组件路径解析插件
|
|
5
|
-
* 将 @mpxjs/webpack-plugin/lib/runtime/components/extends/[component-name] 格式的路径
|
|
6
|
-
* 解析为对应平台的实际组件路径
|
|
7
|
-
*/
|
|
8
|
-
module.exports = class ExtendComponentsPlugin {
|
|
9
|
-
constructor (source, mode, target) {
|
|
10
|
-
this.source = source
|
|
11
|
-
this.target = target
|
|
12
|
-
this.mode = mode
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
apply (resolver) {
|
|
16
|
-
const target = resolver.ensureHook(this.target)
|
|
17
|
-
const mode = this.mode
|
|
18
|
-
|
|
19
|
-
resolver.getHook(this.source).tapAsync('ExtendComponentsPlugin', (request, resolveContext, callback) => {
|
|
20
|
-
const requestPath = request.request
|
|
21
|
-
if (!requestPath || !requestPath.startsWith('@mpxjs/webpack-plugin/lib/runtime/components/extends/')) {
|
|
22
|
-
return callback()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// 匹配 @mpxjs/webpack-plugin/lib/runtime/components/extends/[component-name]
|
|
26
|
-
const extendsMatch = requestPath.match(/^@mpxjs\/webpack-plugin\/lib\/runtime\/components\/extends\/(.+)$/)
|
|
27
|
-
|
|
28
|
-
if (!extendsMatch) {
|
|
29
|
-
return callback()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const componentName = extendsMatch[1]
|
|
33
|
-
|
|
34
|
-
// 检查组件是否在配置中
|
|
35
|
-
if (!EXTEND_COMPONENT_CONFIG[componentName]) {
|
|
36
|
-
return callback(new Error(`Extended component "${componentName}" was not found. Available extended components: ${Object.keys(EXTEND_COMPONENT_CONFIG).join(', ')}`))
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// 获取当前模式下的组件路径
|
|
40
|
-
const componentConfig = EXTEND_COMPONENT_CONFIG[componentName]
|
|
41
|
-
const newRequest = componentConfig[mode]
|
|
42
|
-
|
|
43
|
-
if (!newRequest) {
|
|
44
|
-
return callback(new Error(`Extended component "${componentName}" cannot be used on the ${mode} platform. Supported platforms include: ${Object.keys(componentConfig).join(', ')}`))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const obj = Object.assign({}, request, {
|
|
48
|
-
request: newRequest
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
resolver.doResolve(
|
|
52
|
-
target,
|
|
53
|
-
obj,
|
|
54
|
-
`resolve extend component: ${componentName} to ${newRequest}`,
|
|
55
|
-
resolveContext,
|
|
56
|
-
callback
|
|
57
|
-
)
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,566 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="mpx-section-list">
|
|
3
|
-
<scroll-view
|
|
4
|
-
id="scrollViewContainer"
|
|
5
|
-
class="scroll-view-container"
|
|
6
|
-
wx:ref="mpxRecycleView"
|
|
7
|
-
scroll-y="{{true}}"
|
|
8
|
-
scroll-top="{{scrollTop}}"
|
|
9
|
-
enhanced="{{enhanced}}"
|
|
10
|
-
scroll-with-animation="{{scrollWithAnimation}}"
|
|
11
|
-
scroll-animation-duration="{{scrollAnimationDuration}}"
|
|
12
|
-
refresher-enabled="{{refresherEnabled}}"
|
|
13
|
-
refresher-triggered="{{refresherTriggered}}"
|
|
14
|
-
bindscroll="onScroll"
|
|
15
|
-
bindscrolltolower="onScrolltolower"
|
|
16
|
-
bindrefresherrefresh="onRefresherrefresh"
|
|
17
|
-
wx:style="{{scrollViewStyle}}"
|
|
18
|
-
>
|
|
19
|
-
<view class="content-wrapper">
|
|
20
|
-
<block wx:if="{{useListHeader}}">
|
|
21
|
-
<list-header listHeaderData="{{listHeaderData}}"></list-header>
|
|
22
|
-
</block>
|
|
23
|
-
<view
|
|
24
|
-
class="infinite-list-placeholder"
|
|
25
|
-
ref="infinitePlaceholder"
|
|
26
|
-
wx:style="{{placeholderStyle}}"
|
|
27
|
-
></view>
|
|
28
|
-
<view class="infinite-list" ref="infiniteList" wx:style="{{infiniteListStyle}}">
|
|
29
|
-
<block wx:for="{{visibleData}}">
|
|
30
|
-
<section-header
|
|
31
|
-
wx:if="{{item.itemData && item.itemData.isSectionHeader}}"
|
|
32
|
-
wx:key="header{{item.itemData.item_key || item._index}}"
|
|
33
|
-
itemData="{{item.itemData}}"
|
|
34
|
-
/>
|
|
35
|
-
<recycle-item
|
|
36
|
-
wx:if="{{item.itemData && !item.itemData.isSectionHeader}}"
|
|
37
|
-
wx:key="item{{item.itemData.item_key || item._index}}"
|
|
38
|
-
itemData="{{item.itemData}}"
|
|
39
|
-
/>
|
|
40
|
-
</block>
|
|
41
|
-
</view>
|
|
42
|
-
<block wx:if="{{useListFooter}}">
|
|
43
|
-
<list-footer listFooterData="{{listFooterData}}"></list-footer>
|
|
44
|
-
</block>
|
|
45
|
-
</view>
|
|
46
|
-
<block
|
|
47
|
-
wx:if="{{ _stickyHeaders &&
|
|
48
|
-
_stickyHeaders.length &&
|
|
49
|
-
positions.length &&
|
|
50
|
-
enableSticky
|
|
51
|
-
}}"
|
|
52
|
-
>
|
|
53
|
-
<sticky-header
|
|
54
|
-
scroll-view-id="scrollViewContainer"
|
|
55
|
-
sticky-id="mpx-sticky-header-{{index}}"
|
|
56
|
-
wx:ref="stickyHeader"
|
|
57
|
-
class="sticky-section"
|
|
58
|
-
wx:style="top: {{(positions[stickyItem._index] && positions[stickyItem._index].top) || 0}}px"
|
|
59
|
-
wx:for="{{_stickyHeaders}}"
|
|
60
|
-
wx:for-item="stickyItem"
|
|
61
|
-
wx:key="_index"
|
|
62
|
-
enable-polling="{{enablePolling}}"
|
|
63
|
-
polling-duration="{{pollingDuration}}"
|
|
64
|
-
>
|
|
65
|
-
<section-header
|
|
66
|
-
wx:key="{{'header' + stickyItem._index}}"
|
|
67
|
-
itemData="{{stickyItem.itemData}}"
|
|
68
|
-
/>
|
|
69
|
-
</sticky-header>
|
|
70
|
-
</block>
|
|
71
|
-
</scroll-view>
|
|
72
|
-
</view>
|
|
73
|
-
</template>
|
|
74
|
-
|
|
75
|
-
<script>
|
|
76
|
-
import mpx, { createComponent } from '@mpxjs/core'
|
|
77
|
-
createComponent({
|
|
78
|
-
properties: {
|
|
79
|
-
width: String | Number,
|
|
80
|
-
height: String | Number,
|
|
81
|
-
listData: {
|
|
82
|
-
type: Array,
|
|
83
|
-
value: () => {
|
|
84
|
-
return []
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
scrollOptions: {
|
|
88
|
-
type: Object,
|
|
89
|
-
value: () => {
|
|
90
|
-
return {}
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
minRenderCount: {
|
|
94
|
-
type: Number,
|
|
95
|
-
value: 10
|
|
96
|
-
},
|
|
97
|
-
bufferScale: {
|
|
98
|
-
type: Number,
|
|
99
|
-
value: 1
|
|
100
|
-
},
|
|
101
|
-
itemHeight: {
|
|
102
|
-
type: Object,
|
|
103
|
-
value: () => {
|
|
104
|
-
return {}
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
listHeaderHeight: {
|
|
108
|
-
type: Object,
|
|
109
|
-
value: () => {
|
|
110
|
-
return {}
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
sectionHeaderHeight: {
|
|
114
|
-
type: Object,
|
|
115
|
-
value: () => {
|
|
116
|
-
return {}
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
listHeaderData: {
|
|
120
|
-
type: Object,
|
|
121
|
-
value: () => {
|
|
122
|
-
return {}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
enhanced: {
|
|
126
|
-
type: Boolean,
|
|
127
|
-
value: false
|
|
128
|
-
},
|
|
129
|
-
refresherEnabled: {
|
|
130
|
-
type: Boolean,
|
|
131
|
-
value: false
|
|
132
|
-
},
|
|
133
|
-
refresherTriggered: {
|
|
134
|
-
type: Boolean,
|
|
135
|
-
value: false
|
|
136
|
-
},
|
|
137
|
-
enableSticky: {
|
|
138
|
-
type: Boolean,
|
|
139
|
-
value: false
|
|
140
|
-
},
|
|
141
|
-
scrollWithAnimation: {
|
|
142
|
-
type: Boolean,
|
|
143
|
-
value: false
|
|
144
|
-
},
|
|
145
|
-
scrollAnimationDuration: {
|
|
146
|
-
type: Number,
|
|
147
|
-
value: 300
|
|
148
|
-
},
|
|
149
|
-
enablePolling: {
|
|
150
|
-
type: Boolean,
|
|
151
|
-
value: false
|
|
152
|
-
},
|
|
153
|
-
pollingDuration: {
|
|
154
|
-
type: Number,
|
|
155
|
-
value: 3000
|
|
156
|
-
},
|
|
157
|
-
useListHeader: {
|
|
158
|
-
type: Boolean,
|
|
159
|
-
value: false
|
|
160
|
-
},
|
|
161
|
-
listFooterData: {
|
|
162
|
-
type: Object,
|
|
163
|
-
value: () => {
|
|
164
|
-
return {}
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
useListFooter: {
|
|
168
|
-
type: Boolean,
|
|
169
|
-
value: false
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
data: {
|
|
173
|
-
start: 0,
|
|
174
|
-
end: 0,
|
|
175
|
-
containerHeight: 0,
|
|
176
|
-
positions: [],
|
|
177
|
-
visibleCounts: [],
|
|
178
|
-
infiniteListStyle: '',
|
|
179
|
-
placeholderStyle: '',
|
|
180
|
-
scrollTop: 0
|
|
181
|
-
},
|
|
182
|
-
computed: {
|
|
183
|
-
_listData() {
|
|
184
|
-
return (this.listData && this.listData.map((item, index) => {
|
|
185
|
-
return {
|
|
186
|
-
itemData: item,
|
|
187
|
-
_index: `_${index}`
|
|
188
|
-
}
|
|
189
|
-
})) || []
|
|
190
|
-
},
|
|
191
|
-
_stickyHeaders() {
|
|
192
|
-
const data = []
|
|
193
|
-
this.listData && this.listData.forEach((item, index) => {
|
|
194
|
-
if (item.isSectionHeader) {
|
|
195
|
-
data.push({
|
|
196
|
-
itemData: item,
|
|
197
|
-
_index: index
|
|
198
|
-
})
|
|
199
|
-
}
|
|
200
|
-
})
|
|
201
|
-
return data
|
|
202
|
-
},
|
|
203
|
-
scrollViewStyle() {
|
|
204
|
-
return `height: ${this.formatDimension(
|
|
205
|
-
this.height
|
|
206
|
-
)};width: ${this.formatDimension(this.width)}`
|
|
207
|
-
},
|
|
208
|
-
visibleCount() {
|
|
209
|
-
if (!this.visibleCounts.length) return this.minRenderCount
|
|
210
|
-
return Math.max(this.visibleCounts[this.start], this.minRenderCount)
|
|
211
|
-
},
|
|
212
|
-
aboveCount() {
|
|
213
|
-
if (!this._listData.length || !this.visibleCounts.length) return 0
|
|
214
|
-
let count = 0
|
|
215
|
-
const startIndex = Math.max(0, this.start)
|
|
216
|
-
const endIndex = Math.max(0, startIndex - this.bufferScale)
|
|
217
|
-
|
|
218
|
-
for (let i = startIndex; i > endIndex; i--) {
|
|
219
|
-
count += this.visibleCounts[i] || 0
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return count
|
|
223
|
-
},
|
|
224
|
-
belowCount() {
|
|
225
|
-
if (!this._listData.length || !this.visibleCounts.length) return 0
|
|
226
|
-
let count = 0
|
|
227
|
-
const startIndex = Math.min(this.start, this._listData.length - 1)
|
|
228
|
-
const endIndex = Math.min(startIndex + this.bufferScale, this._listData.length - 1)
|
|
229
|
-
|
|
230
|
-
for (let i = startIndex; i < endIndex; i++) {
|
|
231
|
-
count += this.visibleCounts[i] || 0
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return count
|
|
235
|
-
},
|
|
236
|
-
visibleData() {
|
|
237
|
-
if (!this._listData.length) return []
|
|
238
|
-
|
|
239
|
-
const start = Math.min(Math.max(0, this.start - this.aboveCount), this._listData.length - 1)
|
|
240
|
-
|
|
241
|
-
let end = Math.min(this._listData.length, this.start + this.visibleCount + this.belowCount)
|
|
242
|
-
|
|
243
|
-
// 如果接近列表末尾,确保显示所有剩余项目
|
|
244
|
-
if (end > this._listData.length - 3) {
|
|
245
|
-
end = this._listData.length
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return this._listData.slice(start, end).map((item, idx) => {
|
|
249
|
-
const realIndex = start + idx
|
|
250
|
-
return {
|
|
251
|
-
...item,
|
|
252
|
-
_index: `_${realIndex}`
|
|
253
|
-
}
|
|
254
|
-
})
|
|
255
|
-
},
|
|
256
|
-
_listHeaderHeight() {
|
|
257
|
-
let listHeaderHeight = 0
|
|
258
|
-
if (this.useListHeader) {
|
|
259
|
-
listHeaderHeight = this.getItemHeight(this.listHeaderData, 0, 'listHeaderHeight') || 0
|
|
260
|
-
}
|
|
261
|
-
return listHeaderHeight
|
|
262
|
-
},
|
|
263
|
-
placeholderHeight() {
|
|
264
|
-
if (!this.positions.length) return 0
|
|
265
|
-
return this.positions[this.positions.length - 1].bottom - this._listHeaderHeight || 0
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
watch: {
|
|
269
|
-
listData: {
|
|
270
|
-
handler() {
|
|
271
|
-
this.initPositions()
|
|
272
|
-
this.setPlaceholderStyle()
|
|
273
|
-
// 更新真实偏移量
|
|
274
|
-
this.setStartOffset()
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
itemHeight: {
|
|
278
|
-
handler() {
|
|
279
|
-
this.initPositions()
|
|
280
|
-
this.setPlaceholderStyle()
|
|
281
|
-
this.setStartOffset()
|
|
282
|
-
},
|
|
283
|
-
deep: true
|
|
284
|
-
},
|
|
285
|
-
sectionHeaderHeight: {
|
|
286
|
-
handler() {
|
|
287
|
-
this.initPositions()
|
|
288
|
-
this.setPlaceholderStyle()
|
|
289
|
-
this.setStartOffset()
|
|
290
|
-
},
|
|
291
|
-
deep: true
|
|
292
|
-
},
|
|
293
|
-
listHeaderHeight: {
|
|
294
|
-
handler() {
|
|
295
|
-
this.initPositions()
|
|
296
|
-
this.setPlaceholderStyle()
|
|
297
|
-
this.setStartOffset()
|
|
298
|
-
},
|
|
299
|
-
deep: true
|
|
300
|
-
},
|
|
301
|
-
containerHeight() {
|
|
302
|
-
this.calculateVisibleCounts()
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
ready() {
|
|
306
|
-
this.initPositions()
|
|
307
|
-
this.getContainerHeight()
|
|
308
|
-
this.setPlaceholderStyle()
|
|
309
|
-
if (!this.positions || !this.positions.length) {
|
|
310
|
-
return
|
|
311
|
-
}
|
|
312
|
-
this.start = this.getStartIndex()
|
|
313
|
-
this.end = this.start + this.visibleCount
|
|
314
|
-
this.setStartOffset()
|
|
315
|
-
},
|
|
316
|
-
methods: {
|
|
317
|
-
getContainerHeight() {
|
|
318
|
-
mpx
|
|
319
|
-
.createSelectorQuery()
|
|
320
|
-
.select('#scrollViewContainer')
|
|
321
|
-
.boundingClientRect((rect) => {
|
|
322
|
-
if (!rect) return
|
|
323
|
-
this.containerHeight = rect.height
|
|
324
|
-
})
|
|
325
|
-
.exec()
|
|
326
|
-
},
|
|
327
|
-
formatDimension(value) {
|
|
328
|
-
return typeof value === 'number' ? `${value}px` : value || '100%'
|
|
329
|
-
},
|
|
330
|
-
setPlaceholderStyle() {
|
|
331
|
-
this.placeholderStyle = `height: ${this.placeholderHeight}px`
|
|
332
|
-
},
|
|
333
|
-
initPositions() {
|
|
334
|
-
let bottom = this._listHeaderHeight || 0
|
|
335
|
-
this.positions = this._listData.map((item, index) => {
|
|
336
|
-
const height = this.getItemHeight(
|
|
337
|
-
item.itemData,
|
|
338
|
-
index,
|
|
339
|
-
item.itemData.isSectionHeader ? 'sectionHeaderHeight' : 'itemHeight'
|
|
340
|
-
)
|
|
341
|
-
const position = {
|
|
342
|
-
index,
|
|
343
|
-
height: height,
|
|
344
|
-
top: bottom,
|
|
345
|
-
bottom: bottom + height
|
|
346
|
-
}
|
|
347
|
-
bottom = position.bottom
|
|
348
|
-
return position
|
|
349
|
-
})
|
|
350
|
-
|
|
351
|
-
if (this.containerHeight) {
|
|
352
|
-
this.calculateVisibleCounts()
|
|
353
|
-
}
|
|
354
|
-
},
|
|
355
|
-
calculateVisibleCounts() {
|
|
356
|
-
this.visibleCounts = this.positions.map((_, startIndex) => {
|
|
357
|
-
let count = 0
|
|
358
|
-
let totalHeight = 0
|
|
359
|
-
|
|
360
|
-
for (let i = startIndex; i < this.positions.length; i++) {
|
|
361
|
-
totalHeight += this.positions[i].height
|
|
362
|
-
if (totalHeight > this.containerHeight) {
|
|
363
|
-
break
|
|
364
|
-
}
|
|
365
|
-
count++
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// 如果是最后几个项目,确保全部显示
|
|
369
|
-
if (startIndex + count > this.positions.length - 3) {
|
|
370
|
-
count = this.positions.length - startIndex
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return count
|
|
374
|
-
})
|
|
375
|
-
},
|
|
376
|
-
|
|
377
|
-
getStartIndex(scrollTop = 0) {
|
|
378
|
-
// 确保不会返回超出范围的索引
|
|
379
|
-
if (!this.positions.length) {
|
|
380
|
-
return 0
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// 如果滚动位置为0,直接返回0
|
|
384
|
-
if (scrollTop <= 0) {
|
|
385
|
-
return 0
|
|
386
|
-
}
|
|
387
|
-
const index = this.binarySearch(this.positions, scrollTop)
|
|
388
|
-
return Math.max(0, Math.min(index, this._listData.length - 1))
|
|
389
|
-
},
|
|
390
|
-
binarySearch(list, value) {
|
|
391
|
-
if (!list.length) return 0
|
|
392
|
-
|
|
393
|
-
// 如果 scrollTop 超过了最后一个元素的底部
|
|
394
|
-
if (value >= list[list.length - 1].bottom) {
|
|
395
|
-
return list.length - 1
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
let start = 0
|
|
399
|
-
let end = list.length - 1
|
|
400
|
-
|
|
401
|
-
while (start <= end) {
|
|
402
|
-
const midIndex = Math.floor((start + end) / 2)
|
|
403
|
-
const midValue = list[midIndex]
|
|
404
|
-
|
|
405
|
-
if (value >= midValue.top && value < midValue.bottom) {
|
|
406
|
-
return midIndex
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (value < midValue.top) {
|
|
410
|
-
end = midIndex - 1
|
|
411
|
-
} else {
|
|
412
|
-
start = midIndex + 1
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return Math.min(Math.max(0, start - 1), list.length - 1)
|
|
417
|
-
},
|
|
418
|
-
setStartOffset() {
|
|
419
|
-
if (!this.positions.length) return
|
|
420
|
-
if (this.start >= 1) {
|
|
421
|
-
// 确保 startIndex 不会超出范围
|
|
422
|
-
const startIndex = Math.min(
|
|
423
|
-
Math.max(0, this.start - this.aboveCount),
|
|
424
|
-
this.positions.length - 1
|
|
425
|
-
)
|
|
426
|
-
|
|
427
|
-
const offset = this.positions[startIndex].top
|
|
428
|
-
this.infiniteListStyle = `transform: translateY(${offset}px)`
|
|
429
|
-
} else {
|
|
430
|
-
this.infiniteListStyle = `transform: translateY(${this.positions[0].top}px)`
|
|
431
|
-
}
|
|
432
|
-
},
|
|
433
|
-
getItemHeight(item, index, key) {
|
|
434
|
-
const { value, getter } = this[key]
|
|
435
|
-
if (typeof getter === 'function') {
|
|
436
|
-
return getter(item, index) || 0
|
|
437
|
-
} else {
|
|
438
|
-
return value || 0
|
|
439
|
-
}
|
|
440
|
-
},
|
|
441
|
-
onScroll(e) {
|
|
442
|
-
const { scrollTop } = e.detail
|
|
443
|
-
const newStart = this.getStartIndex(scrollTop)
|
|
444
|
-
// 只有当start发生足够变化时才更新,避免滚动触发重渲染
|
|
445
|
-
if (Math.abs(newStart - this.end) >= Math.floor(this.belowCount / 2)) {
|
|
446
|
-
this.start = newStart
|
|
447
|
-
this.end = this.start + this.visibleCount
|
|
448
|
-
this.setStartOffset()
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
this.triggerEvent('scroll', e)
|
|
452
|
-
},
|
|
453
|
-
onScrolltolower(e) {
|
|
454
|
-
this.triggerEvent('scrolltolower', e)
|
|
455
|
-
},
|
|
456
|
-
onRefresherrefresh(e) {
|
|
457
|
-
this.triggerEvent('refresherrefresh', e)
|
|
458
|
-
},
|
|
459
|
-
scrollToIndex({ index, viewPosition = 0, viewOffset = 0 }) {
|
|
460
|
-
const isStickyHeader = this._listData[index].itemData?.isSectionHeader
|
|
461
|
-
let prevHeaderHeight = 0
|
|
462
|
-
// 如果不是sticky header 查找最近一个吸顶的 sticky header
|
|
463
|
-
if (!isStickyHeader && this.enableSticky) {
|
|
464
|
-
for (let i = index - 1; i >= 0; i--) {
|
|
465
|
-
if (this._listData[i].itemData?.isSectionHeader) {
|
|
466
|
-
prevHeaderHeight = this.positions[i].height
|
|
467
|
-
break
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
const itemTop = (this.positions[index]?.top || 0) - prevHeaderHeight
|
|
473
|
-
const itemHeight = this.positions[index]?.height || 0
|
|
474
|
-
const containerHeight = this.containerHeight
|
|
475
|
-
|
|
476
|
-
let targetTop = itemTop
|
|
477
|
-
if (viewPosition === 1) {
|
|
478
|
-
// 滚动到可视区底部
|
|
479
|
-
targetTop = itemTop - (containerHeight - itemHeight)
|
|
480
|
-
} else if (viewPosition === 0.5) {
|
|
481
|
-
// 滚动到可视区中央
|
|
482
|
-
targetTop = itemTop - (containerHeight - itemHeight) / 2
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
targetTop -= viewOffset
|
|
486
|
-
|
|
487
|
-
// 如果 targetTop 为 0,触发不了支付宝滚动,所以需要加一个很小的值
|
|
488
|
-
if (targetTop <= 0) {
|
|
489
|
-
targetTop = 0.01
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// 支付宝小程序不支持 animated 参数,也不支持 scrollTo 方法滚动
|
|
493
|
-
this.scrollTop = targetTop
|
|
494
|
-
|
|
495
|
-
setTimeout(() => {
|
|
496
|
-
this.refreshStickyHeader()
|
|
497
|
-
}, this.scrollAnimationDuration + 100)
|
|
498
|
-
},
|
|
499
|
-
refreshStickyHeader() {
|
|
500
|
-
if (!this.$refs.stickyHeader) return
|
|
501
|
-
|
|
502
|
-
this.$refs.stickyHeader.forEach((header) => {
|
|
503
|
-
if (header && header.refresh) {
|
|
504
|
-
header.refresh()
|
|
505
|
-
}
|
|
506
|
-
})
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
})
|
|
510
|
-
</script>
|
|
511
|
-
|
|
512
|
-
<style scoped>
|
|
513
|
-
.scroll-view-container {
|
|
514
|
-
position: relative;
|
|
515
|
-
}
|
|
516
|
-
.mpx-section-list {
|
|
517
|
-
position: relative;
|
|
518
|
-
overflow: hidden;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
.content-wrapper {
|
|
522
|
-
position: relative;
|
|
523
|
-
width: 100%;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
.infinite-list {
|
|
527
|
-
left: 0;
|
|
528
|
-
right: 0;
|
|
529
|
-
top: 0;
|
|
530
|
-
position: absolute;
|
|
531
|
-
will-change: transform;
|
|
532
|
-
-webkit-backface-visibility: hidden;
|
|
533
|
-
backface-visibility: hidden;
|
|
534
|
-
/* 支付宝环境需要设置允许事件穿透, 否则滑不动 */
|
|
535
|
-
/* @mpx-if (__mpx_mode__ === 'ali') */
|
|
536
|
-
pointer-events: none;
|
|
537
|
-
/* @mpx-endif */
|
|
538
|
-
}
|
|
539
|
-
.sticky-section {
|
|
540
|
-
position: absolute;
|
|
541
|
-
width: 100%;
|
|
542
|
-
height: 100%;
|
|
543
|
-
}
|
|
544
|
-
</style>
|
|
545
|
-
<script type="application/json">
|
|
546
|
-
{
|
|
547
|
-
"disableScroll": true,
|
|
548
|
-
"usingComponents": {
|
|
549
|
-
"sticky-header": "./mpx-sticky-header.mpx"
|
|
550
|
-
},
|
|
551
|
-
"componentGenerics": {
|
|
552
|
-
"recycle-item": {
|
|
553
|
-
"default": "../wx/mpx-section-list-default/list-item.mpx"
|
|
554
|
-
},
|
|
555
|
-
"section-header": {
|
|
556
|
-
"default": "../wx/mpx-section-list-default/section-header.mpx"
|
|
557
|
-
},
|
|
558
|
-
"list-header": {
|
|
559
|
-
"default": "../wx/mpx-section-list-default/list-header.mpx"
|
|
560
|
-
},
|
|
561
|
-
"list-footer": {
|
|
562
|
-
"default": "../wx/mpx-section-list-default/list-footer.mpx"
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
</script>
|