@dolphinweex/weex-vue-render 0.2.48 → 0.2.49

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.
Files changed (2) hide show
  1. package/dist/index.common.js +243 -48
  2. package/package.json +1 -1
@@ -1547,7 +1547,7 @@ function calc(x1, y1, x2, y2, x3, y3, x4, y4) {
1547
1547
  * @event
1548
1548
  * @param {event} event
1549
1549
  */
1550
- const touchstartHandler = throttle(function touchstartHandler(event) {
1550
+ function touchstartHandler(event) {
1551
1551
 
1552
1552
  if (Object.keys(gestures).length === 0) {
1553
1553
  docEl.addEventListener('touchmove', touchmoveHandler, true);
@@ -1603,7 +1603,7 @@ const touchstartHandler = throttle(function touchstartHandler(event) {
1603
1603
  touchEvent: event
1604
1604
  });
1605
1605
  }
1606
- },300,true)
1606
+ }
1607
1607
 
1608
1608
  /**
1609
1609
  * take over touchmove events, and handle pan and dual related gestures.
@@ -2919,6 +2919,9 @@ function mapFormEvents (context) {
2919
2919
  var eventMap = {};['input', 'change', 'focus', 'blur', 'return'].forEach(function (type) {
2920
2920
  eventMap[type] = function (event) {
2921
2921
  if (context.$el) {
2922
+ if(context.maxlength){
2923
+ context.value = context.value.slice(0,context.maxlength)
2924
+ }
2922
2925
  event.value = context.$el.value;
2923
2926
  // for the sake of v-model, a input event must be emitted.
2924
2927
  if (type === 'input') {
@@ -3475,6 +3478,18 @@ function applySrc (item, src, placeholderSrc) {
3475
3478
  function isEncoded(url) { //检查 % 后是否是合法的编码
3476
3479
  return /%[0-9A-Fa-f]{2}/.test(url);
3477
3480
  }
3481
+
3482
+ // 优化:如果是clone节点且原始图片已加载,直接复制背景图片
3483
+ if (item._isClone && item._originalNode) {
3484
+ var originalBg = item._originalNode.style.backgroundImage;
3485
+ if (originalBg && originalBg !== 'none') {
3486
+ item.style.backgroundImage = originalBg;
3487
+ item.removeAttribute(lazyloadAttr);
3488
+ finallCb();
3489
+ return;
3490
+ }
3491
+ }
3492
+
3478
3493
  /**
3479
3494
  * 1. apply src immediately in case javscript blocks the image loading
3480
3495
  * before next tick.
@@ -5593,6 +5608,7 @@ function getImage(weex) {
5593
5608
  return {
5594
5609
  data: function data() {
5595
5610
  return {
5611
+ locationSrc:'',
5596
5612
  }
5597
5613
  },
5598
5614
  name: 'weex-image',
@@ -5607,6 +5623,7 @@ function getImage(weex) {
5607
5623
  this.currentSrc = this.src;
5608
5624
  },
5609
5625
  mounted: function () {
5626
+ this.locationSrc = this.removeHtmlAndAfter(window.location.href)
5610
5627
  },
5611
5628
  methods: {
5612
5629
  save: function (callback) {
@@ -5632,17 +5649,71 @@ function getImage(weex) {
5632
5649
  handleClick: function handleClick(event) {
5633
5650
  this.$emit('weex$tap', event);
5634
5651
  },
5635
- _handleTouchStart: function _handleTouchStart (event) {
5652
+ _handleTouchStart: function _handleTouchStart(event) {
5636
5653
  if (this.saveImg) {
5637
5654
  this.save()
5638
5655
  }
5639
- }
5656
+ },
5657
+ removeHtmlAndAfter(url) {
5658
+ const baseUrl = url.split(/[?#]/)[0];
5659
+ // 找到最后一个/和.html的位置
5660
+ const lastSlashIndex = baseUrl.lastIndexOf('/');
5661
+ const htmlIndex = baseUrl.indexOf('.html', lastSlashIndex);
5662
+
5663
+ return htmlIndex !== -1
5664
+ ? baseUrl.substring(0, lastSlashIndex)
5665
+ : baseUrl;
5666
+ },
5667
+ processAndConcatenate(baseUrl, appendStr) {
5668
+ if (appendStr.startsWith('http') || appendStr.startsWith('meiju://') || appendStr.startsWith('file')) {
5669
+ return appendStr
5670
+ }
5671
+ const path = baseUrl + '/'
5672
+ if (!baseUrl && !appendStr) {
5673
+ return appendStr
5674
+ }
5675
+ let processedAppendStr = appendStr;
5676
+
5677
+ if (/^[a-zA-Z]/i.test(appendStr) && appendStr.includes('/')) {
5678
+ return path + appendStr; // 直接返回绝对路径
5679
+ }
5680
+ if (processedAppendStr.startsWith("/")) {
5681
+ return path + appendStr
5682
+ }
5683
+
5684
+ // 去除 @、./、../
5685
+ if (processedAppendStr.startsWith("@")) {
5686
+ processedAppendStr = processedAppendStr.slice(1);
5687
+ }
5688
+ if (processedAppendStr.startsWith("./")) {
5689
+ while (processedAppendStr.startsWith("./")) {
5690
+ processedAppendStr = processedAppendStr.slice(2);
5691
+ }
5692
+ }
5693
+ if (processedAppendStr.startsWith("../")) {
5694
+ while (processedAppendStr.startsWith("../")) {
5695
+ processedAppendStr = processedAppendStr.slice(3);
5696
+ }
5697
+ }
5698
+
5699
+
5700
+ // 查找非路径分隔符和特殊前缀的字符串起始位置
5701
+ let startIndex = 0;
5702
+ while (startIndex < processedAppendStr.length &&
5703
+ (processedAppendStr[startIndex] === '.' || processedAppendStr[startIndex] === '/')) {
5704
+ startIndex++;
5705
+ }
5706
+ processedAppendStr = processedAppendStr.slice(startIndex);
5707
+
5708
+ return path + processedAppendStr;
5709
+ },
5640
5710
  },
5711
+
5641
5712
  render: function render (createElement) {
5642
5713
  return createElement('html:img', {
5643
5714
  attrs: {
5644
5715
  'weex-type': 'img',
5645
- src: this.src,
5716
+ src: this.processAndConcatenate(this.locationSrc, this.src),
5646
5717
  },
5647
5718
  on: {
5648
5719
  'weex$tap': this.handleClick,
@@ -6245,20 +6316,21 @@ var scrollable$1 = {
6245
6316
  },
6246
6317
 
6247
6318
  handleTouchEnd: function handleTouchEnd (event) {
6319
+ weex.sliderHorizontalScrolling = false;
6248
6320
  if (!this._touchParams || !this._refresh && !this._loading) {
6249
6321
  return
6250
6322
  }
6251
6323
  var tp = this._touchParams;
6252
6324
  var isV = tp.isVertical;
6253
- if (this.scrollDirection === 'horizontal' && !isV) {
6254
- // 水平
6255
- // event.stopPropagation();
6256
- }else if (isV) {
6257
- // 垂直
6258
- // event.stopPropagation();
6259
- }else {
6260
- return;
6261
- }
6325
+ // if (this.scrollDirection === 'horizontal' && !isV) {
6326
+ // // 水平
6327
+ // // event.stopPropagation();
6328
+ // }else if (isV) {
6329
+ // // 垂直
6330
+ // // event.stopPropagation();
6331
+ // }else {
6332
+ // return;
6333
+ // }
6262
6334
 
6263
6335
  var inner = this.$refs.inner;
6264
6336
  var ref = this._touchParams;
@@ -7670,6 +7742,9 @@ var slideMixin = {
7670
7742
  this._clones = [];
7671
7743
  this.innerOffset = 0;
7672
7744
  this._indicator = null;
7745
+
7746
+ // 向上寻找nav组件(父级weex-slider)
7747
+ this._findParentNav();
7673
7748
  },
7674
7749
 
7675
7750
  beforeUpdate: function beforeUpdate () {
@@ -7727,9 +7802,45 @@ var slideMixin = {
7727
7802
  this._getWrapperSize();
7728
7803
  this._slideTo(this.currentIndex);
7729
7804
  weex.utils.fireLazyload(this.$el, true);
7805
+ document.addEventListener('visibilitychange', this.handleVisibilityChange);
7806
+ },
7807
+ beforeDestroy() {
7808
+ document.removeEventListener('visibilitychange', this.handleVisibilityChange);
7730
7809
  },
7731
-
7732
7810
  methods: {
7811
+ // 向上寻找nav组件(父级weex-slider),最多向上找10层
7812
+ _findParentNav: function _findParentNav () {
7813
+ var maxLevels = 10; // 最大搜索层数
7814
+ var currentParent = this.$parent;
7815
+ var level = 0;
7816
+
7817
+ this._parentNav = null; // 初始化为null
7818
+
7819
+ while (currentParent && level < maxLevels) {
7820
+ // 判断父组件是否是weex-slider(nav组件)
7821
+ if (currentParent.$options._componentTag === 'slider' ||
7822
+ (currentParent.$vnode && currentParent.$vnode.componentOptions &&
7823
+ currentParent.$vnode.componentOptions.tag === 'slider')) {
7824
+ this._parentNav = currentParent;
7825
+ console.log('找到父级nav组件(weex-slider)在第' + (level + 1) + '层:', this._parentNav);
7826
+ break; // 找到就停止
7827
+ }
7828
+
7829
+ currentParent = currentParent.$parent;
7830
+ level++;
7831
+ }
7832
+
7833
+ if (!this._parentNav && level >= maxLevels) {
7834
+ console.log('在' + maxLevels + '层内未找到父级nav组件(weex-slider)');
7835
+ }
7836
+ },
7837
+
7838
+
7839
+ handleVisibilityChange(){
7840
+ if (!document.hidden) {
7841
+ this._startAutoPlay()
7842
+ }
7843
+ },
7733
7844
  _getWrapperSize: function _getWrapperSize () {
7734
7845
  var wrapper = this.$refs.wrapper;
7735
7846
  if (wrapper) {
@@ -7891,12 +8002,14 @@ var slideMixin = {
7891
8002
  } else if (index >= this.frameCount) {
7892
8003
  // 从最后一张向右滑
7893
8004
  var firstNode = this._cells[0].elm;
7894
- var cloneNode = firstNode.cloneNode(true);
8005
+ var cloneNode = this._getPreloadedClone(0) || this._createOptimizedClone(firstNode);
7895
8006
  cloneNode.style.position = 'absolute';
7896
8007
  this._setPosition(cloneNode, this.frameCount * this._wrapperWidth);
7897
8008
  cloneNode.style.width = `${this._wrapperWidth}px`;
7898
8009
  cloneNode.style.zIndex = '10';
7899
- inner.appendChild(cloneNode);
8010
+ if (!cloneNode.parentNode) {
8011
+ inner.appendChild(cloneNode);
8012
+ }
7900
8013
 
7901
8014
  // 执行向右滑动动画
7902
8015
  inner.style.transition = slideTranstionTime;
@@ -8078,6 +8191,17 @@ var slideMixin = {
8078
8191
  });
8079
8192
  this$1._clones[key] = [];
8080
8193
  });
8194
+
8195
+ // 优化:清理预加载的clone节点
8196
+ if (this._preloadedClones) {
8197
+ Object.keys(this._preloadedClones).forEach(function (key) {
8198
+ var clone = this$1._preloadedClones[key];
8199
+ if (clone && clone.parentNode) {
8200
+ clone.parentNode.removeChild(clone);
8201
+ }
8202
+ });
8203
+ this._preloadedClones = {};
8204
+ }
8081
8205
  },
8082
8206
 
8083
8207
  // reset nodes' index and _inShow state. But leave the styles
@@ -8093,6 +8217,7 @@ var slideMixin = {
8093
8217
  },
8094
8218
 
8095
8219
  _initNodes: function _initNodes () {
8220
+ var this$1 = this;
8096
8221
  this._cells.forEach(function (cell, idx) {
8097
8222
  var node = cell.elm;
8098
8223
  node.index = idx;
@@ -8100,6 +8225,13 @@ var slideMixin = {
8100
8225
  node.style.zIndex = 0;
8101
8226
  // node.style.opacity = 0;
8102
8227
  });
8228
+
8229
+ // 优化:延迟预加载clone节点,避免阻塞初始化
8230
+ setTimeout(function() {
8231
+ if (this$1.infinite && this$1.frameCount > 1) {
8232
+ this$1._preloadClones();
8233
+ }
8234
+ }, 100);
8103
8235
  },
8104
8236
 
8105
8237
  _positionNodes: function _positionNodes (begin, end, step, anim) {
@@ -8156,6 +8288,74 @@ var slideMixin = {
8156
8288
  }
8157
8289
  },
8158
8290
 
8291
+ // 优化:获取预加载的clone节点
8292
+ _getPreloadedClone: function _getPreloadedClone (index) {
8293
+ var key = 'preloaded_' + index;
8294
+ var clone = this._preloadedClones && this._preloadedClones[key];
8295
+ if (clone && clone.parentNode) {
8296
+ // 如果clone已经在DOM中,重置其样式
8297
+ clone.style.visibility = 'visible';
8298
+ clone.style.top = '0px';
8299
+ clone.style.zIndex = '10';
8300
+ return clone;
8301
+ }
8302
+ return null;
8303
+ },
8304
+
8305
+ // 优化:创建优化的clone节点,预设图片
8306
+ _createOptimizedClone: function _createOptimizedClone (originalNode) {
8307
+ var cloneNode = originalNode.cloneNode(true);
8308
+ cloneNode._isClone = true;
8309
+ cloneNode._originalNode = originalNode;
8310
+
8311
+ // 预设所有图片元素的背景图片,避免重新加载
8312
+ var originalImages = originalNode.querySelectorAll('[style*="background-image"]');
8313
+ var clonedImages = cloneNode.querySelectorAll('[style*="background-image"], [data-img-src]');
8314
+
8315
+ for (var i = 0; i < originalImages.length && i < clonedImages.length; i++) {
8316
+ var originalBg = originalImages[i].style.backgroundImage;
8317
+ if (originalBg && originalBg !== 'none') {
8318
+ clonedImages[i].style.backgroundImage = originalBg;
8319
+ clonedImages[i].removeAttribute('data-img-src');
8320
+ clonedImages[i]._isClone = true;
8321
+ clonedImages[i]._originalNode = originalImages[i];
8322
+ }
8323
+ }
8324
+
8325
+ return cloneNode;
8326
+ },
8327
+
8328
+ // 优化:预加载常用的clone节点
8329
+ _preloadClones: function _preloadClones () {
8330
+ if (!this._preloadedClones) {
8331
+ this._preloadedClones = {};
8332
+ }
8333
+
8334
+ // 预加载第一张和最后一张的clone,这是最常用的
8335
+ if (this.frameCount > 1) {
8336
+ var firstKey = 'preloaded_0';
8337
+ var lastKey = 'preloaded_' + (this.frameCount - 1);
8338
+
8339
+ if (!this._preloadedClones[firstKey]) {
8340
+ var firstClone = this._createOptimizedClone(this._cells[0].elm);
8341
+ firstClone.style.visibility = 'hidden';
8342
+ firstClone.style.position = 'absolute';
8343
+ firstClone.style.top = '-9999px';
8344
+ this.$refs.inner.appendChild(firstClone);
8345
+ this._preloadedClones[firstKey] = firstClone;
8346
+ }
8347
+
8348
+ if (!this._preloadedClones[lastKey]) {
8349
+ var lastClone = this._createOptimizedClone(this._cells[this.frameCount - 1].elm);
8350
+ lastClone.style.visibility = 'hidden';
8351
+ lastClone.style.position = 'absolute';
8352
+ lastClone.style.top = '-9999px';
8353
+ this.$refs.inner.appendChild(lastClone);
8354
+ this._preloadedClones[lastKey] = lastClone;
8355
+ }
8356
+ }
8357
+ },
8358
+
8159
8359
  _hideNode: function _hideNode (node) {
8160
8360
  node._inShow = false;
8161
8361
  node.style.zIndex = 0;
@@ -8344,10 +8544,12 @@ var slideMixin = {
8344
8544
  if (!this.scrollable || this.frameCount<=1) {
8345
8545
  return // 🚫 禁止滚动行为
8346
8546
  }
8347
- // if(weex.weexSliderTouchStart){ //解决weex-slider嵌套手势冲突问题
8348
- // return
8349
- // }
8350
- // weex.weexSliderTouchStart = true
8547
+ console.log(weex.weexSliderTouchBoundary,'cdj----weex.weexSliderTouchBoundary')
8548
+ if(weex.weexSliderTouchStart && !weex.weexSliderTouchBoundary){
8549
+ return
8550
+ }
8551
+ weex.weexSliderTouchStart = true
8552
+
8351
8553
  this.lastMoveTime = Date.now();
8352
8554
  this.lastMovePosition = event.touches[0].pageX;
8353
8555
  var touch = event.changedTouches[0];
@@ -8430,6 +8632,13 @@ var slideMixin = {
8430
8632
  const isRightSwipe = offsetX > 0;
8431
8633
  const atFirst = this._preIndex === 0;
8432
8634
  const atLast = this._preIndex === this.frameCount - 1;
8635
+ if (!this.infinite && !this.autoPlay && ((atLast && isLeftSwipe) || (atFirst && isRightSwipe)) && !weex.weexSliderTouchBoundary) {
8636
+ weex.weexSliderTouchBoundary = true
8637
+ this._parentNav._touchParams = ref
8638
+ //如果是边界并继续滑动
8639
+ return
8640
+ }
8641
+
8433
8642
  //修改自动轮播或者无缝轮播边界滚动的过渡动画
8434
8643
  if (this.infinite && this.infinite !== 'false') {
8435
8644
  var inner = this.$refs.inner;
@@ -8444,22 +8653,21 @@ var slideMixin = {
8444
8653
  this._setPosition(lastNode, -this._wrapperWidth);
8445
8654
  lastNode.style.opacity = '1';
8446
8655
  } else if (atLast && isLeftSwipe) {
8447
- // 从最后一张向左滑到第一张
8656
+ // 从最后一张向左滑到第一张 - 优化版本
8448
8657
  var firstNode = this._cells[0].elm;
8449
- var cloneNode = firstNode.cloneNode(true);
8658
+ var cloneNode = this._getPreloadedClone(0) || this._createOptimizedClone(firstNode);
8450
8659
  cloneNode.style.position = 'absolute';
8451
8660
  this._setPosition(cloneNode, this.frameCount * this._wrapperWidth);
8452
8661
  cloneNode.style.width = `${this._wrapperWidth}px`;
8453
- inner.appendChild(cloneNode);
8662
+ if (!cloneNode.parentNode) {
8663
+ inner.appendChild(cloneNode);
8664
+ }
8454
8665
  tp.cloneNode = cloneNode;
8455
8666
  }
8456
8667
  }
8457
8668
  }
8458
8669
  }
8459
- if (!this.infinite && !this.autoPlay && ((atLast && isLeftSwipe) || (atFirst && isRightSwipe))) {
8460
- // ✅ 如果是边界并继续滑动,就放手,不拦截
8461
- return;
8462
- }
8670
+
8463
8671
  if (this._sliding) {
8464
8672
  event.stopPropagation();
8465
8673
  return
@@ -8501,8 +8709,10 @@ var slideMixin = {
8501
8709
  },
8502
8710
 
8503
8711
  _handleTouchEnd: function _handleTouchEnd (event) {
8504
- // weex.weexSliderTouchStart = false
8712
+ weex.weexSliderTouchBoundary = false
8713
+ weex.weexSliderTouchStart = false
8505
8714
  var inner = this.$refs.inner;
8715
+ this._refresh && this._refresh.pullingEnd();
8506
8716
  if (touchSliderInstance == inner) {
8507
8717
  touchSliderInstance= null;
8508
8718
  } else {
@@ -11652,26 +11862,11 @@ if (global.Vue) {
11652
11862
  return weex;
11653
11863
 
11654
11864
  })));
11655
- var isNotReload = false
11656
- const globalEvent333 = weex.requireModule('globalEvent')
11657
- globalEvent333.addEventListener("videoFullscreen",()=>{
11658
- isNotReload = true
11659
- })
11660
11865
 
11661
11866
  // 一多适配不同宽高比例的屏幕,使用resetViewport也能适配宽度,
11662
11867
  // 但项目存在没有使用rem的元素,且页面高度重置方法也因项目而异。
11663
11868
  // 后续联合所有页面统一做了适配后可删除此段代码
11664
- var resetDeviceWidth = function () {
11665
- if( !isNotReload ){
11666
- location.reload()
11667
- }
11668
- if(isNotReload){
11669
- isNotReload = false
11670
- }
11671
- };
11672
-
11673
- window.addEventListener('resize', () => {
11674
- setTimeout(() => {
11675
- resetDeviceWidth()
11676
- }, 100)
11677
- });
11869
+ const globalEventForReload = weex.requireModule('globalEvent')
11870
+ globalEventForReload.addEventListener("WebReload",()=>{
11871
+ location.reload()
11872
+ })
package/package.json CHANGED
@@ -49,5 +49,5 @@
49
49
  "type": "git",
50
50
  "url": "git+ssh://git@github.com/weexteam/weex-vue-render.git"
51
51
  },
52
- "version": "0.2.48"
52
+ "version": "0.2.49"
53
53
  }