tencent.jquery.pix.component 1.0.63-beta.1 → 1.0.63-beta.2
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.
|
@@ -19,6 +19,7 @@ const DEFAULTS = {
|
|
|
19
19
|
// 传入 $node, data, index
|
|
20
20
|
updateItem: null, // 元素更新时的回调函数
|
|
21
21
|
onscroll: null, // 滚动事件回调函数
|
|
22
|
+
shouldOccupySpace: null // 是否是静态数据的回调函数,静态数据能够占用元素
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
export function Waterfall(optionsInput = {}) {
|
|
@@ -104,7 +105,7 @@ export function Waterfall(optionsInput = {}) {
|
|
|
104
105
|
this.options.data.forEach((item, index) => {
|
|
105
106
|
const dataId = index; //this.nextDataId++;
|
|
106
107
|
this.dataIdMap.set(dataId, {
|
|
107
|
-
data: item,
|
|
108
|
+
data: true,//item,
|
|
108
109
|
originalIndex: index,
|
|
109
110
|
layoutInfo: null // 将在布局时填充
|
|
110
111
|
});
|
|
@@ -173,6 +174,9 @@ Waterfall.prototype.updateVisibleItems = function (force = false) {
|
|
|
173
174
|
|
|
174
175
|
// 新增卡片
|
|
175
176
|
Waterfall.prototype.appendCard = function (data, dataId, { top, left }) {
|
|
177
|
+
if (this.renderedDataIds.has(dataId)) {
|
|
178
|
+
return
|
|
179
|
+
}
|
|
176
180
|
const self = this;
|
|
177
181
|
const options = this.options;
|
|
178
182
|
const $container = $(options.container);
|
|
@@ -189,6 +193,7 @@ Waterfall.prototype.appendCard = function (data, dataId, { top, left }) {
|
|
|
189
193
|
console.warn('Waterfall: Empty data for dataId', dataId);
|
|
190
194
|
}
|
|
191
195
|
|
|
196
|
+
|
|
192
197
|
const $card = $(
|
|
193
198
|
`<div class="waterfall-item"
|
|
194
199
|
data-index="${dataId}"
|
|
@@ -198,11 +203,13 @@ Waterfall.prototype.appendCard = function (data, dataId, { top, left }) {
|
|
|
198
203
|
</div> `
|
|
199
204
|
);
|
|
200
205
|
|
|
206
|
+
this.renderedDataIds.add(dataId);
|
|
201
207
|
|
|
202
208
|
if (options.columns !== 1) {
|
|
203
209
|
$card.width(this.columnWidth + 'px');
|
|
204
210
|
}
|
|
205
211
|
|
|
212
|
+
|
|
206
213
|
$viewport.append($card);
|
|
207
214
|
return $card;
|
|
208
215
|
}
|
|
@@ -243,6 +250,16 @@ Waterfall.prototype.updateCardsInView = function ({ start, end, force = false })
|
|
|
243
250
|
|
|
244
251
|
const data = options.data[dataId]
|
|
245
252
|
|
|
253
|
+
// 如果当前这个节点是特殊节点 不用做处理
|
|
254
|
+
// 如果是特殊的静态占用元素卡片,需要指定节点不变更的数据,那么该数据的节点不能被其他数据使用
|
|
255
|
+
let specialNode = false;
|
|
256
|
+
if (options.shouldOccupySpace) {
|
|
257
|
+
specialNode = options.shouldOccupySpace(data) || false;
|
|
258
|
+
}
|
|
259
|
+
if (specialNode) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
|
|
246
263
|
// 在可视区域内 进行有关卡片的操作
|
|
247
264
|
const bool = row.top <= endNum && row.bottom >= startNum;
|
|
248
265
|
if (bool) {
|
|
@@ -251,8 +268,6 @@ Waterfall.prototype.updateCardsInView = function ({ start, end, force = false })
|
|
|
251
268
|
|
|
252
269
|
let $node = null;
|
|
253
270
|
|
|
254
|
-
|
|
255
|
-
|
|
256
271
|
// 遍历当前的节点是否被占用,如果被占用的话,就得要从nodePool中取一个
|
|
257
272
|
let bool = true;
|
|
258
273
|
if ($card) {
|
|
@@ -290,18 +305,15 @@ Waterfall.prototype.updateCardsInView = function ({ start, end, force = false })
|
|
|
290
305
|
});
|
|
291
306
|
row.$node = $node;
|
|
292
307
|
} else {
|
|
293
|
-
//$node = $(this.nodePool.pop());
|
|
294
308
|
this.updateRenderUI($node, data, dataId);
|
|
295
309
|
row.$node = $node;
|
|
296
310
|
}
|
|
297
311
|
}
|
|
298
312
|
}
|
|
299
|
-
|
|
300
313
|
$node.css({
|
|
301
314
|
'transform': `translate(${row.left}px,${row.top}px)`,
|
|
302
315
|
}).attr('data-index', dataId);
|
|
303
316
|
|
|
304
|
-
|
|
305
317
|
newActiveNodes.set(dataId, $node);
|
|
306
318
|
|
|
307
319
|
// 清除掉在NodePool中的card
|
|
@@ -389,6 +401,7 @@ Waterfall.prototype.createCards = function ({ end, dataId = -1 }) {
|
|
|
389
401
|
}
|
|
390
402
|
}
|
|
391
403
|
|
|
404
|
+
|
|
392
405
|
// 如果没有更多数据需要渲染
|
|
393
406
|
if (nextDataId === null) {
|
|
394
407
|
const maxHeight = this.getMaxHeight();
|
|
@@ -403,10 +416,14 @@ Waterfall.prototype.createCards = function ({ end, dataId = -1 }) {
|
|
|
403
416
|
return;
|
|
404
417
|
}
|
|
405
418
|
|
|
406
|
-
if (this.renderIndex >=
|
|
419
|
+
if (this.renderIndex >= options.data.length) {
|
|
420
|
+
const maxHeight = this.getMaxHeight();
|
|
421
|
+
$container.find('.waterfall-list-scroll').css('height', maxHeight + options.marginBottom + 'px');
|
|
407
422
|
return
|
|
408
423
|
}
|
|
409
424
|
|
|
425
|
+
const data = options.data[nextDataId];
|
|
426
|
+
|
|
410
427
|
let column = this.getMinHeightColumn();
|
|
411
428
|
if (column === null) {
|
|
412
429
|
column = this.columnItems[0];
|
|
@@ -418,16 +435,29 @@ Waterfall.prototype.createCards = function ({ end, dataId = -1 }) {
|
|
|
418
435
|
|
|
419
436
|
this.renderIndex += 1;
|
|
420
437
|
|
|
438
|
+
let specialNode = false;
|
|
439
|
+
|
|
440
|
+
// 如果是特殊的卡片,需要指定节点不变更的数据,那么该数据的节点不能被其他数据使用
|
|
441
|
+
if (options.shouldOccupySpace) {
|
|
442
|
+
specialNode = options.shouldOccupySpace(data) || false;
|
|
443
|
+
}
|
|
444
|
+
|
|
421
445
|
// 添加卡片,使用dataId作为唯一标识
|
|
422
446
|
let $card = null;
|
|
423
|
-
if (this.nodePool.length === 0) {
|
|
424
|
-
$card = this.appendCard(
|
|
447
|
+
if (this.nodePool.length === 0 || specialNode === true) {
|
|
448
|
+
$card = this.appendCard(data, nextDataId, position);
|
|
425
449
|
} else {
|
|
426
|
-
$
|
|
427
|
-
$
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
450
|
+
const $tmp = getNodePoolPop(this.nodePool, this.activeNodes);
|
|
451
|
+
if ($tmp) {
|
|
452
|
+
$card = $tmp;
|
|
453
|
+
$card.css({
|
|
454
|
+
'transform': `translate(${row.left}px,${row.top}px)`,
|
|
455
|
+
}).attr('data-index', nextDataId);
|
|
456
|
+
this.updateRenderUI($card, data, nextDataId);
|
|
457
|
+
} else {
|
|
458
|
+
$card = this.appendCard(data, nextDataId, position);
|
|
459
|
+
}
|
|
460
|
+
|
|
431
461
|
}
|
|
432
462
|
|
|
433
463
|
row.$node = $card;
|
|
@@ -437,15 +467,25 @@ Waterfall.prototype.createCards = function ({ end, dataId = -1 }) {
|
|
|
437
467
|
}
|
|
438
468
|
|
|
439
469
|
// 记录布局信息
|
|
440
|
-
dataInfo.layoutInfo = {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
470
|
+
// dataInfo.layoutInfo = {
|
|
471
|
+
// //columnIndex: this.columnItems.indexOf(column),
|
|
472
|
+
// //position: position,
|
|
473
|
+
// // row: row
|
|
474
|
+
// };
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
if (specialNode === false) {
|
|
480
|
+
// 把新增的卡片放进 activeNodes 当成活跃节点元素,那么是 可以动态使用的
|
|
481
|
+
this.activeNodes.set(nextDataId, $card);
|
|
482
|
+
|
|
483
|
+
this.allReadyNodes.set(nextDataId, $card);
|
|
484
|
+
} else {
|
|
485
|
+
// 如果是特殊的,这里不要记录了
|
|
486
|
+
this.allReadyNodes.set(nextDataId, null);
|
|
487
|
+
}
|
|
488
|
+
|
|
449
489
|
this.renderedDataIds.add(nextDataId);
|
|
450
490
|
|
|
451
491
|
// 更新列的底部距离
|
|
@@ -463,7 +503,7 @@ Waterfall.prototype.createCards = function ({ end, dataId = -1 }) {
|
|
|
463
503
|
});
|
|
464
504
|
} else {
|
|
465
505
|
const maxHeight = this.getMaxHeight();
|
|
466
|
-
$(options.container).find('.waterfall-list-scroll').css('height', maxHeight + options.marginBottom);
|
|
506
|
+
$(options.container).find('.waterfall-list-scroll').css('height', maxHeight + options.marginBottom + 'px');
|
|
467
507
|
}
|
|
468
508
|
}
|
|
469
509
|
|
|
@@ -521,7 +561,7 @@ Waterfall.prototype.updateData = function (newData) {
|
|
|
521
561
|
const dataId = index; // this.nextDataId++;
|
|
522
562
|
if (!this.allReadyNodes.has(dataId)) {
|
|
523
563
|
this.dataIdMap.set(dataId, {
|
|
524
|
-
data: item,
|
|
564
|
+
data: true,// item,
|
|
525
565
|
originalIndex: index,
|
|
526
566
|
layoutInfo: null // 将在布局时填充
|
|
527
567
|
});
|
|
@@ -540,6 +580,8 @@ Waterfall.prototype.updateData = function (newData) {
|
|
|
540
580
|
|
|
541
581
|
// 重新计算设置一遍所有的卡片位置
|
|
542
582
|
Waterfall.prototype.updatePointCards = function () {
|
|
583
|
+
// 有问题 不要用
|
|
584
|
+
return
|
|
543
585
|
const self = this;
|
|
544
586
|
const options = this.options;
|
|
545
587
|
const columnItems = this.columnItems;
|