@dolphinweex/weex-vue-render 0.2.47 → 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 +253 -50
  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;
@@ -7136,6 +7208,15 @@ function getLoading () {
7136
7208
  }
7137
7209
  },
7138
7210
  methods: {
7211
+ isElementFullyInViewport(el) {
7212
+ const rect = this.$el.getBoundingClientRect();
7213
+ return (
7214
+ rect.top >= 0 &&
7215
+ rect.left >= 0 &&
7216
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) + 5 &&
7217
+ rect.right <= (window.innerWidth || document.documentElement.clientWidth) + 5
7218
+ );
7219
+ },
7139
7220
  pulling: function pulling (offsetY) {
7140
7221
  if ( offsetY === void 0 ) offsetY = 0;
7141
7222
  this.height = offsetY;
@@ -7146,7 +7227,7 @@ function getLoading () {
7146
7227
  },
7147
7228
  pullingEnd: function pullingEnd () {
7148
7229
  this.$el && (this.$el.style.transition = "height .2s");
7149
- if ( this.height >= Math.max(this.viewHeight, 200)) {
7230
+ if ( this.height >= Math.max(this.viewHeight, 150) && this.isElementFullyInViewport()) {
7150
7231
  this.pulling(this.viewHeight);
7151
7232
  if (this.$el) {
7152
7233
  dispatchNativeEvent(this.$el, 'loading');
@@ -7661,6 +7742,9 @@ var slideMixin = {
7661
7742
  this._clones = [];
7662
7743
  this.innerOffset = 0;
7663
7744
  this._indicator = null;
7745
+
7746
+ // 向上寻找nav组件(父级weex-slider)
7747
+ this._findParentNav();
7664
7748
  },
7665
7749
 
7666
7750
  beforeUpdate: function beforeUpdate () {
@@ -7718,9 +7802,45 @@ var slideMixin = {
7718
7802
  this._getWrapperSize();
7719
7803
  this._slideTo(this.currentIndex);
7720
7804
  weex.utils.fireLazyload(this.$el, true);
7805
+ document.addEventListener('visibilitychange', this.handleVisibilityChange);
7806
+ },
7807
+ beforeDestroy() {
7808
+ document.removeEventListener('visibilitychange', this.handleVisibilityChange);
7721
7809
  },
7722
-
7723
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
+ },
7724
7844
  _getWrapperSize: function _getWrapperSize () {
7725
7845
  var wrapper = this.$refs.wrapper;
7726
7846
  if (wrapper) {
@@ -7882,12 +8002,14 @@ var slideMixin = {
7882
8002
  } else if (index >= this.frameCount) {
7883
8003
  // 从最后一张向右滑
7884
8004
  var firstNode = this._cells[0].elm;
7885
- var cloneNode = firstNode.cloneNode(true);
8005
+ var cloneNode = this._getPreloadedClone(0) || this._createOptimizedClone(firstNode);
7886
8006
  cloneNode.style.position = 'absolute';
7887
8007
  this._setPosition(cloneNode, this.frameCount * this._wrapperWidth);
7888
8008
  cloneNode.style.width = `${this._wrapperWidth}px`;
7889
8009
  cloneNode.style.zIndex = '10';
7890
- inner.appendChild(cloneNode);
8010
+ if (!cloneNode.parentNode) {
8011
+ inner.appendChild(cloneNode);
8012
+ }
7891
8013
 
7892
8014
  // 执行向右滑动动画
7893
8015
  inner.style.transition = slideTranstionTime;
@@ -8069,6 +8191,17 @@ var slideMixin = {
8069
8191
  });
8070
8192
  this$1._clones[key] = [];
8071
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
+ }
8072
8205
  },
8073
8206
 
8074
8207
  // reset nodes' index and _inShow state. But leave the styles
@@ -8084,6 +8217,7 @@ var slideMixin = {
8084
8217
  },
8085
8218
 
8086
8219
  _initNodes: function _initNodes () {
8220
+ var this$1 = this;
8087
8221
  this._cells.forEach(function (cell, idx) {
8088
8222
  var node = cell.elm;
8089
8223
  node.index = idx;
@@ -8091,6 +8225,13 @@ var slideMixin = {
8091
8225
  node.style.zIndex = 0;
8092
8226
  // node.style.opacity = 0;
8093
8227
  });
8228
+
8229
+ // 优化:延迟预加载clone节点,避免阻塞初始化
8230
+ setTimeout(function() {
8231
+ if (this$1.infinite && this$1.frameCount > 1) {
8232
+ this$1._preloadClones();
8233
+ }
8234
+ }, 100);
8094
8235
  },
8095
8236
 
8096
8237
  _positionNodes: function _positionNodes (begin, end, step, anim) {
@@ -8147,6 +8288,74 @@ var slideMixin = {
8147
8288
  }
8148
8289
  },
8149
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
+
8150
8359
  _hideNode: function _hideNode (node) {
8151
8360
  node._inShow = false;
8152
8361
  node.style.zIndex = 0;
@@ -8335,10 +8544,12 @@ var slideMixin = {
8335
8544
  if (!this.scrollable || this.frameCount<=1) {
8336
8545
  return // 🚫 禁止滚动行为
8337
8546
  }
8338
- // if(weex.weexSliderTouchStart){ //解决weex-slider嵌套手势冲突问题
8339
- // return
8340
- // }
8341
- // 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
+
8342
8553
  this.lastMoveTime = Date.now();
8343
8554
  this.lastMovePosition = event.touches[0].pageX;
8344
8555
  var touch = event.changedTouches[0];
@@ -8421,6 +8632,13 @@ var slideMixin = {
8421
8632
  const isRightSwipe = offsetX > 0;
8422
8633
  const atFirst = this._preIndex === 0;
8423
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
+
8424
8642
  //修改自动轮播或者无缝轮播边界滚动的过渡动画
8425
8643
  if (this.infinite && this.infinite !== 'false') {
8426
8644
  var inner = this.$refs.inner;
@@ -8435,22 +8653,21 @@ var slideMixin = {
8435
8653
  this._setPosition(lastNode, -this._wrapperWidth);
8436
8654
  lastNode.style.opacity = '1';
8437
8655
  } else if (atLast && isLeftSwipe) {
8438
- // 从最后一张向左滑到第一张
8656
+ // 从最后一张向左滑到第一张 - 优化版本
8439
8657
  var firstNode = this._cells[0].elm;
8440
- var cloneNode = firstNode.cloneNode(true);
8658
+ var cloneNode = this._getPreloadedClone(0) || this._createOptimizedClone(firstNode);
8441
8659
  cloneNode.style.position = 'absolute';
8442
8660
  this._setPosition(cloneNode, this.frameCount * this._wrapperWidth);
8443
8661
  cloneNode.style.width = `${this._wrapperWidth}px`;
8444
- inner.appendChild(cloneNode);
8662
+ if (!cloneNode.parentNode) {
8663
+ inner.appendChild(cloneNode);
8664
+ }
8445
8665
  tp.cloneNode = cloneNode;
8446
8666
  }
8447
8667
  }
8448
8668
  }
8449
8669
  }
8450
- if (!this.infinite && !this.autoPlay && ((atLast && isLeftSwipe) || (atFirst && isRightSwipe))) {
8451
- // ✅ 如果是边界并继续滑动,就放手,不拦截
8452
- return;
8453
- }
8670
+
8454
8671
  if (this._sliding) {
8455
8672
  event.stopPropagation();
8456
8673
  return
@@ -8492,8 +8709,10 @@ var slideMixin = {
8492
8709
  },
8493
8710
 
8494
8711
  _handleTouchEnd: function _handleTouchEnd (event) {
8495
- // weex.weexSliderTouchStart = false
8712
+ weex.weexSliderTouchBoundary = false
8713
+ weex.weexSliderTouchStart = false
8496
8714
  var inner = this.$refs.inner;
8715
+ this._refresh && this._refresh.pullingEnd();
8497
8716
  if (touchSliderInstance == inner) {
8498
8717
  touchSliderInstance= null;
8499
8718
  } else {
@@ -8613,7 +8832,6 @@ var slider$1 = {
8613
8832
  watch: {
8614
8833
  index: function index () {
8615
8834
  this.currentIndex = this._normalizeIndex(this.index);
8616
- console.log('cdj----index',this.infinite,this.currentIndex)
8617
8835
  }
8618
8836
  },
8619
8837
 
@@ -11644,26 +11862,11 @@ if (global.Vue) {
11644
11862
  return weex;
11645
11863
 
11646
11864
  })));
11647
- var isNotReload = false
11648
- const globalEvent333 = weex.requireModule('globalEvent')
11649
- globalEvent333.addEventListener("videoFullscreen",()=>{
11650
- isNotReload = true
11651
- })
11652
11865
 
11653
11866
  // 一多适配不同宽高比例的屏幕,使用resetViewport也能适配宽度,
11654
11867
  // 但项目存在没有使用rem的元素,且页面高度重置方法也因项目而异。
11655
11868
  // 后续联合所有页面统一做了适配后可删除此段代码
11656
- var resetDeviceWidth = function () {
11657
- if( !isNotReload ){
11658
- location.reload()
11659
- }
11660
- if(isNotReload){
11661
- isNotReload = false
11662
- }
11663
- };
11664
-
11665
- window.addEventListener('resize', () => {
11666
- setTimeout(() => {
11667
- resetDeviceWidth()
11668
- }, 100)
11669
- });
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.47"
52
+ "version": "0.2.49"
53
53
  }