@dolphinweex/weex-harmony 0.1.25 → 0.1.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolphinweex/weex-harmony",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "description": "weex harmony adapter",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -200,6 +200,10 @@ export default {
200
200
  lastBestTarget: null,
201
201
  targetChangeTime: null,
202
202
  pendingTarget: null,
203
+ weexListInnerEl: null,
204
+ weexRefreshEl: null,
205
+ originListInnerStyle: null,
206
+ originRefreshStyle: null,
203
207
  };
204
208
  },
205
209
  computed: {
@@ -242,6 +246,28 @@ export default {
242
246
  },
243
247
  },
244
248
  methods: {
249
+ searchDom(){
250
+ //在 slider组件内部时 阻止默认行为和冒泡都无法在长按的时候 阻止其滚动行为 只能查找去禁止
251
+ const currentEl = this.$el;
252
+ let parentEl = currentEl.parentElement;
253
+ let searchDepth = 0; // 搜索深度计数器
254
+ while (parentEl && !parentEl.classList.contains('weex-list-inner') && searchDepth < 5) {
255
+ parentEl = parentEl.parentElement;
256
+ searchDepth++;
257
+ }
258
+
259
+ if (parentEl) {
260
+ this.weexListInnerEl = parentEl;
261
+ this.originListInnerStyle = parentEl.style.touchAction || '';
262
+
263
+ // 在weex-list-inner中查找weex-refresh子元素
264
+ const refreshEl = parentEl.querySelector('.weex-refresh');
265
+ if (refreshEl) {
266
+ this.weexRefreshEl = refreshEl;
267
+ this.originRefreshStyle = refreshEl.style.height || '';
268
+ }
269
+ }
270
+ },
245
271
  updateListItem(data) {
246
272
  console.log('updateListItem收到数据:', JSON.stringify(data));
247
273
  const id = data.itemView.id;
@@ -251,14 +277,16 @@ export default {
251
277
  const dataIndex = this.data.list.findIndex(
252
278
  (item) => item.itemView.id === id
253
279
  );
254
-
280
+ // 更新原始数据以确保watch能触发
281
+ if (dataIndex !== -1) {
282
+ // 使用Vue的$set确保响应式更新
283
+ this.$set(this.data.list, dataIndex, JSON.parse(JSON.stringify(data)));
284
+ }
255
285
  if (index === -1) {
256
286
  return;
257
287
  }
258
288
 
259
- // 保存更新前的可见性状态用于比较
260
- const oldVisibility = this.processedList[index].actionButton.visibility;
261
- const newVisibility = data.actionButton.visibility;
289
+
262
290
 
263
291
  // 检查是否有动画URL的变化
264
292
  const oldBgAnimUrl = this.processedList[index].bgAnimView.animUrl || '';
@@ -266,7 +294,6 @@ export default {
266
294
  this.processedList[index].loadingAnimView.animUrl || '';
267
295
  const oldFrontAnimUrl =
268
296
  this.processedList[index].frontAnimView.animUrl || '';
269
-
270
297
  const newBgAnimUrl = data.bgAnimView.animUrl || '';
271
298
  const newLoadingAnimUrl = data.loadingAnimView.animUrl || '';
272
299
  const newFrontAnimUrl = data.frontAnimView.animUrl || '';
@@ -614,7 +641,6 @@ export default {
614
641
 
615
642
  // 检查长按过程中的移动
616
643
  checkLongPressMove(e) {
617
- this.data.isEditing && e.oriEvent.stopPropagation()
618
644
  if (!this.data.isEditable) {
619
645
  return;
620
646
  }
@@ -624,7 +650,6 @@ export default {
624
650
  this.onTouchMove(e);
625
651
  return;
626
652
  }
627
-
628
653
  const moveX = Math.abs(touch.pageX - this.touchStartX);
629
654
  const moveY = Math.abs(touch.pageY - this.touchStartY);
630
655
 
@@ -640,20 +665,14 @@ export default {
640
665
  if (moveX > this.scrollThreshold || moveY > this.scrollThreshold) {
641
666
  this.cancelLongPress();
642
667
  }
668
+ this.data.isEditing && e.oriEvent.stopPropagation()
669
+ this.data.isEditing && e.oriEvent.preventDefault()
643
670
 
644
- // 不阻止默认行为,允许滚动
645
671
  },
646
672
 
647
673
  // 激活拖拽模式
648
674
  activateDragMode(index) {
649
675
  console.log('长按触发,进入编辑模式');
650
- // 进入编辑模式
651
- this.data.isEditing = true;
652
- this.$emit('onEditStateChanged', true);
653
- // 设置当前拖拽索引
654
- this.draggingIndex = index;
655
- this.isTouchDragging = true;
656
-
657
676
  // 此时添加阻止默认行为的事件监听,但只影响拖拽状态下的行为
658
677
  document.addEventListener('touchmove', this.onTouchMove, {
659
678
  passive: false, // 只有在拖拽模式下才阻止默认行为
@@ -661,38 +680,50 @@ export default {
661
680
  document.addEventListener('touchend', this.onTouchEnd, {
662
681
  passive: true,
663
682
  });
683
+ if (this.data.isEditing) {
684
+ // 设置当前拖拽索引
685
+ this.draggingIndex = index;
686
+ this.isTouchDragging = true;
687
+
688
+ // 使用存储的固定宽高
689
+ this.draggedItemRect = {
690
+ width: this.fixedItemWidth,
691
+ height: this.fixedItemHeight,
692
+ };
693
+
694
+ // 获取当前元素位置用于计算偏移
695
+ const element = document.querySelectorAll('.grid-item')[index];
696
+ if (element) {
697
+ const rect = element.getBoundingClientRect();
698
+ // 计算触摸点相对于元素左上角的偏移
699
+ this.touchOffsetX = this.touchStartX - rect.left;
700
+ this.touchOffsetY = this.touchStartY - rect.top;
701
+
702
+ // 设置克隆元素的初始位置
703
+ this.dragCloneX = rect.left;
704
+ this.dragCloneY = rect.top;
705
+
706
+ // 显示拖拽克隆
707
+ this.isDragClone = true;
708
+
709
+ // 立即执行一次定位以确保初始位置准确
710
+ requestAnimationFrame(() => {
711
+ this.dragCloneX = this.touchStartX - this.touchOffsetX;
712
+ this.dragCloneY = this.touchStartY - this.touchOffsetY;
713
+ });
664
714
 
665
- // 使用存储的固定宽高
666
- this.draggedItemRect = {
667
- width: this.fixedItemWidth,
668
- height: this.fixedItemHeight,
669
- };
670
-
671
- // 获取当前元素位置用于计算偏移
672
- const element = document.querySelectorAll('.grid-item')[index];
673
- if (element) {
674
- const rect = element.getBoundingClientRect();
675
- // 计算触摸点相对于元素左上角的偏移
676
- this.touchOffsetX = this.touchStartX - rect.left;
677
- this.touchOffsetY = this.touchStartY - rect.top;
678
-
679
- // 设置克隆元素的初始位置
680
- this.dragCloneX = rect.left;
681
- this.dragCloneY = rect.top;
682
-
683
- // 显示拖拽克隆
684
- this.isDragClone = true;
685
-
686
- // 立即执行一次定位以确保初始位置准确
687
- requestAnimationFrame(() => {
688
- this.dragCloneX = this.touchStartX - this.touchOffsetX;
689
- this.dragCloneY = this.touchStartY - this.touchOffsetY;
690
- });
715
+ console.log('拖拽克隆已创建');
716
+ }
691
717
 
692
- console.log('拖拽克隆已创建');
718
+ this.longPressTimer = null;
719
+ }
720
+ // 进入编辑模式
721
+ if (!this.data.isEditing) {
722
+ // 设置编辑状态并隐藏weex-refresh
723
+ this.data.isEditing = true;
724
+ this.$emit('onEditStateChanged', true);
725
+ this.applyDragModeStyles(); // 应用编辑模式样式(隐藏refresh)
693
726
  }
694
-
695
- this.longPressTimer = null;
696
727
  },
697
728
 
698
729
  // 取消长按计时器
@@ -822,6 +853,8 @@ export default {
822
853
  this.draggingIndex = bestTarget;
823
854
  this.lastSwapTime = now;
824
855
  }
856
+ this.data.isEditing && e.oriEvent.stopPropagation()
857
+ this.data.isEditing && e.oriEvent.preventDefault()
825
858
  },
826
859
 
827
860
  // 新增:平滑更新拖拽位置的方法
@@ -877,6 +910,12 @@ export default {
877
910
  this.isDragClone = false;
878
911
  this.hoverIndex = null;
879
912
  this.draggingIndex = null;
913
+
914
+ // 如果不再拖拽,恢复touch-action(但保持refresh隐藏,因为仍在编辑状态)
915
+ const elements = this.findParentElements();
916
+ if (elements.listInner) {
917
+ elements.listInner.style.touchAction = this.originListInnerStyle;
918
+ }
880
919
  }
881
920
  },
882
921
 
@@ -884,6 +923,9 @@ export default {
884
923
  onTouchEnd(e) {
885
924
  console.log('全局触摸结束');
886
925
 
926
+ // 恢复拖拽模式前的样式
927
+ this.restoreDragModeStyles();
928
+
887
929
  // 移除全局事件监听
888
930
  document.removeEventListener('touchmove', this.onTouchMove, {
889
931
  passive: false,
@@ -1155,6 +1197,40 @@ export default {
1155
1197
  // 这里可以添加将来的处理逻辑
1156
1198
  return false;
1157
1199
  },
1200
+
1201
+ // 查找父级元素和refresh元素
1202
+ findParentElements() {
1203
+ // 返回存储的元素引用
1204
+ return {
1205
+ listInner: this.weexListInnerEl,
1206
+ refresh: this.weexRefreshEl
1207
+ };
1208
+ },
1209
+
1210
+ // 进入拖拽模式时应用样式
1211
+ applyDragModeStyles() {
1212
+ const elements = this.findParentElements();
1213
+
1214
+ // 设置weex-list-inner的touch-action: none(只在拖拽时)
1215
+ if (elements.listInner && this.isTouchDragging) {
1216
+ elements.listInner.style.touchAction = 'none';
1217
+ }
1218
+ },
1219
+
1220
+ // 退出拖拽模式时恢复样式
1221
+ restoreDragModeStyles() {
1222
+ const elements = this.findParentElements();
1223
+
1224
+ // 恢复weex-list-inner的touch-action(只在拖拽时修改)
1225
+ if (elements.listInner && this.isTouchDragging) {
1226
+ elements.listInner.style.touchAction = this.originListInnerStyle;
1227
+ }
1228
+
1229
+ // 如果不在编辑状态,恢复weex-refresh的display
1230
+ if (elements.refresh && !this.data.isEditing) {
1231
+ elements.refresh.style.display = 'flex';
1232
+ }
1233
+ },
1158
1234
  },
1159
1235
  watch: {
1160
1236
  // 监听初始数据变化
@@ -1281,6 +1357,20 @@ export default {
1281
1357
  },
1282
1358
  deep: true,
1283
1359
  },
1360
+ // 添加对编辑状态的监听
1361
+ 'data.isEditing': {
1362
+ handler(newValue) {
1363
+ const elements = this.findParentElements();
1364
+ if (elements.refresh) {
1365
+ if (newValue) {
1366
+ elements.refresh.style.maxHeight = '0px';
1367
+ } else {
1368
+ elements.refresh.style.maxHeight = '999px'
1369
+ }
1370
+ }
1371
+ },
1372
+ immediate: true
1373
+ },
1284
1374
  },
1285
1375
  mounted() {
1286
1376
  console.log(this.data, 'djdjdjdjdjdjdj');
@@ -1289,6 +1379,8 @@ export default {
1289
1379
  // 获取并存储固定宽高
1290
1380
  this.updateFixedItemSize();
1291
1381
 
1382
+ this.searchDom()
1383
+
1292
1384
  // 监听窗口大小变化,更新grid-box宽度
1293
1385
  window.addEventListener('resize', () => {
1294
1386
  this.updateGridBoxWidth();