tencent.jquery.pix.component 1.0.63-beta.3 → 1.0.63-beta.5

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.
@@ -1,7 +1,9 @@
1
1
  import "./banner.scss"
2
- import { $, windowEnv } from "../config";
2
+ import { windowEnv, getEnv } from "../config";
3
3
  import { addResizeFunc, nextAnimationFrame, removeResizeFunc } from "../utils/utils";
4
4
 
5
+ let $ = null;
6
+
5
7
  /**
6
8
  * 在页面上放置一个banner组件
7
9
  * @constructor
@@ -17,7 +19,9 @@ import { addResizeFunc, nextAnimationFrame, removeResizeFunc } from "../utils/ut
17
19
  * @param {function} [options.pageChanged] 翻页时触发,第一个参数为新生效页面元素的jq,第二个参数为 options.list 中对应的项,第三个参数为当前页码
18
20
  * @param {function} [options.renderCallback] 自定义渲染回调,第一个参数为 options.list 中对应的项,第二个参数为当前页码,返回值为渲染后的元素
19
21
  */
20
- export function Banner(options = {}){
22
+ export function Banner(options = {}) {
23
+ $ = getEnv().$;
24
+
21
25
  this.options = options;
22
26
  this.options.isTitleEnabled ??= true;
23
27
  this.options.autoResize ??= true;
@@ -30,7 +34,7 @@ export function Banner(options = {}){
30
34
  this.init();
31
35
  }
32
36
 
33
- Banner.prototype.setWidth = function(width) {
37
+ Banner.prototype.setWidth = function (width) {
34
38
  this.signWidth = width;
35
39
  this.allWidth = this.signWidth * (this.options.list.length + 2);
36
40
  $(this.options.container).width(width);
@@ -39,7 +43,7 @@ Banner.prototype.setWidth = function(width) {
39
43
  this.setTranslate(-this.signWidth * (this.index + 1));
40
44
  }
41
45
 
42
- Banner.prototype.fitWidth = function() {
46
+ Banner.prototype.fitWidth = function () {
43
47
  console.log('banner fitWidth');
44
48
  const newWidth = $(this.options.container).parent().width();
45
49
  if (newWidth != this.signWidth) {
@@ -50,7 +54,7 @@ Banner.prototype.fitWidth = function() {
50
54
  /**
51
55
  * 跳转到上一页
52
56
  */
53
- Banner.prototype.prevPage = async function() {
57
+ Banner.prototype.prevPage = async function () {
54
58
  this.pauseAutoPlay();
55
59
  await this.gotoPageUnchecked(this.index - 1);
56
60
  this.startAutoPlay();
@@ -59,7 +63,7 @@ Banner.prototype.prevPage = async function() {
59
63
  /**
60
64
  * 跳转到下一页
61
65
  */
62
- Banner.prototype.nextPage = async function() {
66
+ Banner.prototype.nextPage = async function () {
63
67
  this.pauseAutoPlay();
64
68
  await this.gotoPageUnchecked(this.index + 1);
65
69
  this.startAutoPlay();
@@ -69,7 +73,7 @@ Banner.prototype.nextPage = async function() {
69
73
  * 跳转到指定页
70
74
  * @param {number} newIdx 要切换到的页码 [0, len)
71
75
  */
72
- Banner.prototype.gotoPage = async function(newIdx) {
76
+ Banner.prototype.gotoPage = async function (newIdx) {
73
77
  if (newIdx < 0 || newIdx >= this.options.list.length) {
74
78
  throw new Error('index out of range');
75
79
  }
@@ -81,7 +85,7 @@ Banner.prototype.gotoPage = async function(newIdx) {
81
85
  this.startAutoPlay();
82
86
  }
83
87
 
84
- Banner.prototype.gotoPageUnchecked = async function(newIdx) {
88
+ Banner.prototype.gotoPageUnchecked = async function (newIdx) {
85
89
  const len = this.options.list.length;
86
90
  let wrap = 0;
87
91
  if (newIdx <= -1) {
@@ -100,14 +104,14 @@ Banner.prototype.gotoPageUnchecked = async function(newIdx) {
100
104
  }
101
105
 
102
106
  this.$inner.css('transition', 'transform 0.3s ease-out');
103
- const newTranslate = -this.signWidth * (newIdx+1);
107
+ const newTranslate = -this.signWidth * (newIdx + 1);
104
108
  this.setTranslate(newTranslate);
105
109
  if (this.options.isTitleEnabled) {
106
- this.$pagination.children().eq(newIdx+1).addClass('active').siblings().removeClass('active');
110
+ this.$pagination.children().eq(newIdx + 1).addClass('active').siblings().removeClass('active');
107
111
  this.$titleBox.text(this.options.list[newIdx].title);
108
112
  }
109
113
  if (this.options.pageChanged && newIdx != this.index) {
110
- this.options.pageChanged(this.$inner.children().eq(newIdx+1), this.options.list[newIdx], newIdx);
114
+ this.options.pageChanged(this.$inner.children().eq(newIdx + 1), this.options.list[newIdx], newIdx);
111
115
  }
112
116
  this.index = newIdx;
113
117
  }
@@ -116,11 +120,11 @@ Banner.prototype.gotoPageUnchecked = async function(newIdx) {
116
120
  * 获取当前页的序号
117
121
  * @returns {number} 当前页的序号 [0,len]
118
122
  */
119
- Banner.prototype.getCurrentPage = function() {
123
+ Banner.prototype.getCurrentPage = function () {
120
124
  return this.index;
121
125
  }
122
126
 
123
- Banner.prototype.init = function(){
127
+ Banner.prototype.init = function () {
124
128
  const $t = $(this.options.container)
125
129
  console.log('banner container:', $t.dom);
126
130
  const signWidth = $t.width()
@@ -139,10 +143,10 @@ Banner.prototype.init = function(){
139
143
  });
140
144
  }
141
145
  this.startAutoPlay();
142
- console.log('list:', this.options.list, ' signWidth:',signWidth)
146
+ console.log('list:', this.options.list, ' signWidth:', signWidth)
143
147
  }
144
148
 
145
- Banner.prototype.startAutoPlay = function() {
149
+ Banner.prototype.startAutoPlay = function () {
146
150
  if (this.options.durationMs > 0 && this.timer == null) {
147
151
  this.timer = setInterval(() => {
148
152
  this.nextPage()
@@ -150,7 +154,7 @@ Banner.prototype.startAutoPlay = function() {
150
154
  }
151
155
  }
152
156
 
153
- Banner.prototype.pauseAutoPlay = function() {
157
+ Banner.prototype.pauseAutoPlay = function () {
154
158
  if (this.timer == null) {
155
159
  return;
156
160
  }
@@ -158,25 +162,25 @@ Banner.prototype.pauseAutoPlay = function() {
158
162
  this.timer = null;
159
163
  }
160
164
 
161
- Banner.prototype.createHtml = function(){
165
+ Banner.prototype.createHtml = function () {
162
166
  const len = this.options.list.length
163
- if(len<1){
167
+ if (len < 1) {
164
168
  return
165
169
  }
166
170
  const $t = $(this.options.container)
167
171
  $t.empty();
168
172
  const signWidth = this.signWidth = $t.width()
169
-
173
+
170
174
  const allWidth = this.allWidth = signWidth * (len + 2)
171
175
  const $inner = this.$inner = $(`<div class="banner-inner-transform"></div>`)
172
176
  this.currentTranslate = -signWidth * (this.index + 1)
173
- $inner.width(allWidth).css('transform',`translateX(${this.currentTranslate}px)`)
177
+ $inner.width(allWidth).css('transform', `translateX(${this.currentTranslate}px)`)
174
178
 
175
179
  // 加第0个位置
176
- $inner.append(`<div class="banner-inner-li" data-background-url="${this.options.list[len-1].url}" style="width:${this.signWidth}px;">
180
+ $inner.append(`<div class="banner-inner-li" data-background-url="${this.options.list[len - 1].url}" style="width:${this.signWidth}px;">
177
181
  </div>
178
182
  `)
179
- for(let i=0;i<len;i++){
183
+ for (let i = 0; i < len; i++) {
180
184
  const item = this.options.list[i]
181
185
  const $li = $(`<div class="banner-inner-li" data-background-url="${item.url}" style="width:${this.signWidth}px;">
182
186
  </div>
@@ -210,7 +214,7 @@ Banner.prototype.createHtml = function(){
210
214
  this.$titleBox = $titleBox
211
215
  this.$pagination = $pagination
212
216
 
213
- $pagination.children().eq(this.index+1).addClass('active').siblings().removeClass('active')
217
+ $pagination.children().eq(this.index + 1).addClass('active').siblings().removeClass('active')
214
218
 
215
219
  $t.append($pagination)
216
220
  }
@@ -223,21 +227,21 @@ Banner.prototype.createHtml = function(){
223
227
  /**
224
228
  * 由 this.options.renderCallback 生成页面
225
229
  */
226
- Banner.prototype.createCustomHtml = function() {
230
+ Banner.prototype.createCustomHtml = function () {
227
231
  const len = this.options.list.length
228
- if(len<1){
232
+ if (len < 1) {
229
233
  return
230
234
  }
231
235
  const $t = $(this.options.container)
232
236
  $t.empty();
233
237
  const signWidth = this.signWidth = $t.width()
234
-
238
+
235
239
  const allWidth = this.allWidth = signWidth * (len + 2)
236
240
  const $inner = this.$inner = $(`<div class="banner-inner-transform"></div>`)
237
241
  this.currentTranslate = -signWidth * (this.index + 1)
238
- $inner.width(allWidth).css('transform',`translateX(${this.currentTranslate}px)`)
242
+ $inner.width(allWidth).css('transform', `translateX(${this.currentTranslate}px)`)
239
243
 
240
- let $li = $(this.options.renderCallback(this.options.list[len-1], len-1));
244
+ let $li = $(this.options.renderCallback(this.options.list[len - 1], len - 1));
241
245
  $li.width(signWidth);
242
246
  $inner.append($li);
243
247
 
@@ -254,7 +258,7 @@ Banner.prototype.createCustomHtml = function() {
254
258
  $t.append($inner);
255
259
  }
256
260
 
257
- Banner.prototype.bindEvent = function(){
261
+ Banner.prototype.bindEvent = function () {
258
262
  const self = this
259
263
  const len = this.options.list.length;
260
264
  const $inner = this.$inner;
@@ -317,7 +321,7 @@ Banner.prototype.bindEvent = function(){
317
321
  } else if (newTranslate < -this.signWidth * len) {
318
322
  newTranslate += this.signWidth * len;
319
323
  }
320
-
324
+
321
325
  // 在移动到新位置前,先变换当前位置到正确区域
322
326
  await this.normalizeTranslate();
323
327
  } else {
@@ -325,7 +329,7 @@ Banner.prototype.bindEvent = function(){
325
329
  }
326
330
 
327
331
  $inner.css('transition', 'transform 0.3s ease-out')
328
- $inner.css('transform',`translateX(${this.currentTranslate}px)`);
332
+ $inner.css('transform', `translateX(${this.currentTranslate}px)`);
329
333
 
330
334
  if (newTranslate !== this.currentTranslate) {
331
335
  this.setTranslate(newTranslate);
@@ -335,11 +339,11 @@ Banner.prototype.bindEvent = function(){
335
339
  // 由于 newTranslate 包含了前后的循环占位(位置 0 和 len+1 ),需要减1后取模
336
340
  const newIndex = (Math.round(-newTranslate / this.signWidth) + len - 1) % len;
337
341
  if (this.options.isTitleEnabled) {
338
- this.$pagination.children().eq(newIndex+1).addClass('active').siblings().removeClass('active');
342
+ this.$pagination.children().eq(newIndex + 1).addClass('active').siblings().removeClass('active');
339
343
  this.$titleBox.text(this.options.list[newIndex].title);
340
344
  }
341
345
  if (this.options.pageChanged && newIndex != this.index) {
342
- this.options.pageChanged(this.$inner.children().eq(newIndex+1), this.options.list[newIndex], newIndex);
346
+ this.options.pageChanged(this.$inner.children().eq(newIndex + 1), this.options.list[newIndex], newIndex);
343
347
  }
344
348
  this.index = newIndex;
345
349
  this.startAutoPlay();
@@ -350,15 +354,15 @@ Banner.prototype.bindEvent = function(){
350
354
  if (windowEnv === 'h5') { // 浏览器环境
351
355
  $inner
352
356
  .attr('draggable', 'false')
353
- .on('pointerdown', function(e) {
357
+ .on('pointerdown', function (e) {
354
358
  pStart(e.originalEvent.clientX, () => {
355
359
  this.setPointerCapture(e.originalEvent.pointerId);
356
360
  });
357
361
  })
358
- .on('pointermove', function(e) {
362
+ .on('pointermove', function (e) {
359
363
  pMove(e.originalEvent.clientX);
360
364
  })
361
- .on('pointerup', async function(e) {
365
+ .on('pointerup', async function (e) {
362
366
  await pEnd(() => {
363
367
  this.releasePointerCapture(e.originalEvent.pointerId);
364
368
  });
@@ -380,23 +384,23 @@ Banner.prototype.bindEvent = function(){
380
384
  $inner.on('transitionend', () => {
381
385
  $inner.css('transition', 'none');
382
386
  })
383
- .on('click', function(e){
384
- if(!self.options.click){
385
- return
386
- }
387
- if (windowEnv === 'h5' && Math.abs(e.clientX - originalX) > 10) {
388
- // 防止浏览器中拖动时触发click
389
- return
390
- }
387
+ .on('click', function (e) {
388
+ if (!self.options.click) {
389
+ return
390
+ }
391
+ if (windowEnv === 'h5' && Math.abs(e.clientX - originalX) > 10) {
392
+ // 防止浏览器中拖动时触发click
393
+ return
394
+ }
391
395
 
392
- const $t = self.$inner.children().eq(self.index + 1);
393
- self.options.click($t, self.options.list[self.index], self.index);
394
- });
396
+ const $t = self.$inner.children().eq(self.index + 1);
397
+ self.options.click($t, self.options.list[self.index], self.index);
398
+ });
395
399
  }
396
400
 
397
401
  Banner.prototype.setTranslate = function (transX) {
398
402
  this.currentTranslate = transX;
399
- this.$inner.css('transform',`translateX(${this.currentTranslate}px)`);
403
+ this.$inner.css('transform', `translateX(${this.currentTranslate}px)`);
400
404
  }
401
405
 
402
406
  /**
@@ -420,7 +424,7 @@ Banner.prototype.normalizeTranslate = async function () {
420
424
  * 加载所有背景图片,将data-background-url属性设置为背景图片
421
425
  */
422
426
  Banner.prototype.loadAllBackgrounds = function () {
423
- this.$inner.children().each(function() {
427
+ this.$inner.children().each(function () {
424
428
  $(this).css('background-image', `url(${$(this).attr('data-background-url')})`)
425
429
  });
426
430
  // console.log('banner images loaded');
@@ -1,4 +1,7 @@
1
- import { $, windowEnv } from "../config";
1
+ import { getEnv } from "../config";
2
+
3
+ let $ = null;
4
+
2
5
  // 默认配置
3
6
  const DEFAULTS = {
4
7
  itemHeight: 50, // 单条数据高度
@@ -14,6 +17,8 @@ const DEFAULTS = {
14
17
  };
15
18
 
16
19
  export function List(options = {}) {
20
+ $ = getEnv().$;
21
+
17
22
  this.options = Object.assign({}, DEFAULTS, options);
18
23
  // 标记是否有更新元素用的回调函数
19
24
  this.hasUpdateItem = options.updateItem && (options.updateItem.constructor === Function) ? true : false;
@@ -1,3 +1,4 @@
1
+ import "./waterfall.scss"
1
2
  import { getEnv } from "../config.js";
2
3
  import { remToPx } from "../../utils/utils.js";
3
4
 
@@ -19,7 +20,10 @@ const DEFAULTS = {
19
20
  // 传入 $node, data, index
20
21
  updateItem: null, // 元素更新时的回调函数
21
22
  onscroll: null, // 滚动事件回调函数
22
- shouldOccupySpace: null // 是否是静态数据的回调函数,静态数据能够占用元素
23
+ shouldOccupySpace: null, // 是否是静态数据的回调函数,静态数据能够占用元素
24
+ showLoading: null, // 展示loading的回调函数 params:$node
25
+ hideLoading: null, // 隐藏loading的回调函数
26
+ createLoading: null, // 创建loading的回调函数
23
27
  };
24
28
 
25
29
  export function Waterfall(optionsInput = {}) {
@@ -36,6 +40,8 @@ export function Waterfall(optionsInput = {}) {
36
40
  this.nextDataId = 0; // 下一个数据ID
37
41
  this.renderedDataIds = new Set(); // 已渲染的数据ID集合
38
42
 
43
+ this.$loadingNode = null;
44
+
39
45
 
40
46
  // 间隔字符串转数字
41
47
  if (options.columnGap.constructor === String) {
@@ -125,14 +131,24 @@ Waterfall.prototype.init = function () {
125
131
  this.allReadyNodes = new Map(); // 所有节点(索引 -> DOM)
126
132
  this.renderIndex = 0; // 渲染索引(保留兼容性)
127
133
 
128
-
129
-
130
134
  $container.html(`
131
135
  <div class="waterfall-list-scroll" style="">
132
136
  <div class="waterfall-list-viewport"></div>
133
137
  </div>
134
138
  `);
135
139
 
140
+
141
+
142
+ // 如果有定义loading函数 那么创建一个loading节点元素
143
+ if (options.createLoading) {
144
+ this.$loadingNode = $(
145
+ `<div class="waterfall-loading" style="transform: translate(0px, -99999px)"></div>`
146
+ );
147
+ $container.find('.waterfall-list-viewport').append(this.$loadingNode);
148
+
149
+ options.createLoading(this.$loadingNode);
150
+ }
151
+
136
152
  // 绑定滚动事件(节流处理)
137
153
  $container.off().on('scroll', function () {
138
154
  self.scrollTop = $(this).scrollTop();
@@ -604,7 +620,7 @@ Waterfall.prototype.updateCard = function (data) {
604
620
 
605
621
  const $node = this.activeNodes.get(dataId);
606
622
  const height = $node.height();
607
- console.log('Waterfall: updateCard height', height);
623
+
608
624
  // 重新计算该数据所在列的卡片位置
609
625
  let needUpdate = false
610
626
  const columnItems = this.columnItems;
@@ -619,9 +635,8 @@ Waterfall.prototype.updateCard = function (data) {
619
635
  bool = true
620
636
  const oldHeight = row.bottom - row.top;
621
637
 
622
- console.log('Waterfall: updateCard oldHeight', oldHeight);
623
638
  minus = height - oldHeight;
624
- console.log('Waterfall: updateCard minus', minus);
639
+
625
640
  if (minus === 0) {
626
641
  // 找到了原节点数据,对比后没有变更 那么直接退出
627
642
  return;
@@ -682,6 +697,49 @@ Waterfall.prototype.updatePointCards = function () {
682
697
  }
683
698
  }
684
699
 
700
+ // 展示loading的回调函数
701
+ Waterfall.prototype.showLoading = function (callback = null) {
702
+ const options = this.options;
703
+ const $container = $(options.container);
704
+ let $node = null
705
+ if (this.$loadingNode) {
706
+ let loadingTop = this.getMaxHeight() + options.rowGap
707
+ let h = loadingTop + this.$loadingNode.height() + options.marginBottom
708
+
709
+ this.$loadingNode.css('transform', `translate(0px,${loadingTop}px)`);
710
+ $(options.container).find('.waterfall-list-scroll').css('height', h + 'px');
711
+
712
+ $node = this.$loadingNode
713
+ }
714
+
715
+ if (callback) callback($node)
716
+ }
717
+
718
+ // 隐藏loading的回调函数
719
+ Waterfall.prototype.hideLoading = function (callback = null) {
720
+ const options = this.options;
721
+ const $container = $(options.container);
722
+ let $node = null
723
+ if (this.$loadingNode) {
724
+ let h1 = this.getMaxHeight() + options.marginBottom
725
+ this.$loadingNode.css('transform', `translate(0px,-99999px)`);
726
+ //如果要设置高度,那么这里判断一下当前是否正在做updata 一般这里被调用时,数据已经读到,在updata的同一时间调用了该函数
727
+ // 如果两个时刻高度是一致的 那么数据就是一致的 这里重新设置回来高度即可
728
+ window.requestAnimationFrame(() => {
729
+ let h2 = this.getMaxHeight() + options.marginBottom
730
+ if (h1 === h2) {
731
+ const $scroll = $(options.container).find('.waterfall-list-scroll')
732
+ const h = $scroll.height()
733
+ if (h !== h1) {
734
+ $scroll.css('height', h1 + 'px');
735
+ }
736
+ }
737
+ })
738
+ $node = this.$loadingNode
739
+ }
740
+
741
+ if (callback) callback($node)
742
+ }
685
743
 
686
744
  function createDefaultRow({ top, left }) {
687
745
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tencent.jquery.pix.component",
3
- "version": "1.0.63-beta.3",
3
+ "version": "1.0.63-beta.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [