@dolphinweex/weex-harmony 0.1.65 → 0.1.67

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.65",
3
+ "version": "0.1.67",
4
4
  "description": "weex harmony adapter",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -1,24 +1,14 @@
1
1
  <template>
2
2
  <div>
3
- <div
4
- style="position: relative"
3
+ <!-- <text v-if="progressText.length > 0">{{progressText}}</text> -->
4
+ <iframe
5
+ :id="embedId"
5
6
  v-if="url.length > 0 && pluginType != 'old-h5'"
6
- ref="iframeWrapper"
7
- @touchstart="handleWrapperTouchStart"
8
- @touchmove="handleWrapperTouchMove"
9
- @touchend="handleWrapperTouchEnd"
10
- >
11
- <iframe
12
- :id="embedId"
13
- :src="url"
14
- :style="{
15
- backgroundColor: backgroundColor,
16
- height: height,
17
- }"
18
- ref="iframe"
19
- @load="onPageFinish"
20
- ></iframe>
21
- </div>
7
+ :src="url"
8
+ :style="{ backgroundColor: backgroundColor, height: height }"
9
+ ref="iframe"
10
+ @load="onPageFinish"
11
+ ></iframe>
22
12
 
23
13
  <BaseSameLayer
24
14
  class="common-view-iframe"
@@ -47,9 +37,7 @@ export default {
47
37
  embedId: `embedId_iframe_${
48
38
  Date.now().toString(36) + Math.random().toString(36).substring(2)
49
39
  }`,
50
- height: '100%',
51
- _wrapperTouchParams: null, // wrapper触摸参数
52
- _parentScroller: null, // 父级scroller元素引用
40
+ height: "100%",
53
41
  };
54
42
  },
55
43
  components: {
@@ -134,8 +122,11 @@ export default {
134
122
  return null;
135
123
  };
136
124
  this._wrapperEl = findWrapperFromParent(); // 保存容器引用
125
+ // 优化手势处理性能
126
+ this._rafId = null;
127
+ this._pendingGesture = null;
137
128
  this._onMessage = (event) => {
138
- if (event.data.type === 'IFRAME_CONTENT_HEIGHT') {
129
+ if(event.data.type==='IFRAME_CONTENT_HEIGHT'){
139
130
  const h = Number(event.data.height) || 0;
140
131
  if (!h) {
141
132
  return;
@@ -148,106 +139,96 @@ export default {
148
139
  }else{
149
140
  document.getElementsByTagName('iframe')[0].height = event.data.height
150
141
  }
142
+ // 处理iframe手势跨窗口传递冒泡
143
+ if (event.data.type === 'IFRAME_GESTURE') {
144
+ const gestureData = event.data;
145
+
146
+ // touchmove 使用RAF节流,其他事件立即处理
147
+ if (gestureData.eventType === 'touchmove') {
148
+ this._pendingGesture = gestureData;
149
+ if (!this._rafId) {
150
+ this._rafId = requestAnimationFrame(() => {
151
+ if (this._pendingGesture) {
152
+ this.handleGestureBubble(this._pendingGesture);
153
+ this._pendingGesture = null;
154
+ }
155
+ this._rafId = null;
156
+ });
157
+ }
158
+ } else {
159
+ this.handleGestureBubble(gestureData);
160
+ }
161
+ }
151
162
  };
152
163
  window.addEventListener("message", this._onMessage, false);
153
164
  },
154
165
  methods: {
155
166
  onPageFinish() {
156
- if (this.$refs['iframe']) {
157
- this.$refs['iframe'].contentWindow.$midea_harmony_native =
167
+ if (this.$refs["iframe"]) {
168
+ this.$refs["iframe"].contentWindow.$midea_harmony_native =
158
169
  window.$midea_harmony_native;
159
- this.$refs['iframe'].contentWindow.isIframe = true;
160
- this.$refs['iframe'].contentWindow.postMessage(
170
+ this.$refs["iframe"].contentWindow.isIframe = true;
171
+ this.$refs["iframe"].contentWindow.postMessage(
161
172
  JSON.stringify(window.$midea_harmony_native),
162
- '*'
173
+ "*"
163
174
  );
164
175
  }
165
176
  },
177
+ handleGestureBubble(gestureData) {
178
+ const iframeEl = this.$refs.iframe;
179
+ if (!iframeEl) return;
166
180
 
167
- handleWrapperTouchStart(e) {
168
- // iframe会接收到事件并处理自己的滚动
169
- // 找到父级scroller(轮播图容器)或者气他?
170
- this._findParentScroller();
171
- // 如果找到了父级scroller,手动触发它的touchstart处理QxQ
172
- if (this._parentScroller) {
173
- this._forwardEventToParent(e, 'touchstart');
174
- }
175
- const touch = e.touches[0];
176
- this._wrapperTouchParams = {
177
- startX: touch.pageX,
178
- startY: touch.pageY,
179
- };
180
- },
181
-
182
- handleWrapperTouchMove(e) {
183
- if (!this._wrapperTouchParams) return;
184
- // iframe正在处理自己的滚动(不阻止)同时转发事件给父级scroller
185
- if (this._parentScroller) {
186
- this._forwardEventToParent(e, 'touchmove');
187
- }
188
- const touch = e.touches[0];
189
- const offsetX = touch.pageX - this._wrapperTouchParams.startX;
190
- const offsetY = touch.pageY - this._wrapperTouchParams.startY;
191
- const absX = Math.abs(offsetX);
192
- const absY = Math.abs(offsetY);
193
-
194
- if (absX > absY && absX > 10) {
195
- console.log('📱 横向滑动:iframe内滚动 + 父级轮播图同时响应');
196
- } else if (absY > absX && absY > 10) {
197
- console.log('📜 纵向滑动:iframe内容滚动');
198
- }
199
- },
200
-
201
- handleWrapperTouchEnd(e) {
202
- // 转发touchend事件给父级
203
- if (this._parentScroller) {
204
- this._forwardEventToParent(e, 'touchend');
205
- }
206
- this._wrapperTouchParams = null;
207
- },
208
-
209
- // 查找父级scroller元素
210
- _findParentScroller() {
211
- if (this._parentScroller) return;
212
- let parent = this.$parent;
213
- while (parent) {
214
- const el = parent.$el;
215
- if (
216
- el &&
217
- el.classList &&
218
- (el.classList.contains('weex-scroller') ||
219
- el.classList.contains('weex-slider') ||
220
- el.classList.contains('weex-list'))
221
- ) {
222
- this._parentScroller = el;
223
- console.log('✅ 找到父级scroller,将转发事件');
224
- return;
225
- }
226
- parent = parent.$parent;
227
- }
228
- console.warn('⚠️ 未找到父级scroller');
229
- },
181
+ const rect = iframeEl.getBoundingClientRect();
182
+ const offsetX = rect.left;
183
+ const offsetY = rect.top;
184
+ const pageOffsetX = offsetX + window.pageXOffset;
185
+ const pageOffsetY = offsetY + window.pageYOffset;
186
+
187
+ // 创建Touch对象并转换坐标
188
+ const createTouches = (touchesData) => touchesData.map(t => new Touch({
189
+ identifier: t.identifier,
190
+ target: iframeEl,
191
+ clientX: t.clientX + offsetX,
192
+ clientY: t.clientY + offsetY,
193
+ screenX: t.screenX,
194
+ screenY: t.screenY,
195
+ pageX: t.pageX + pageOffsetX,
196
+ pageY: t.pageY + pageOffsetY,
197
+ radiusX: t.radiusX || 0,
198
+ radiusY: t.radiusY || 0,
199
+ rotationAngle: t.rotationAngle || 0,
200
+ force: t.force || 0
201
+ }));
230
202
 
231
- // 手动转发事件到父级scroller
232
- _forwardEventToParent(originalEvent, eventType) {
233
- if (!this._parentScroller) return;
234
203
  try {
235
- const newEvent = new TouchEvent(eventType, {
204
+ iframeEl.dispatchEvent(new TouchEvent(gestureData.eventType, {
236
205
  bubbles: true,
237
206
  cancelable: true,
238
- touches: originalEvent.touches,
239
- targetTouches: originalEvent.targetTouches,
240
- changedTouches: originalEvent.changedTouches,
241
- view: window,
242
- });
243
-
244
- // 直接触发到父级scroller元素
245
- this._parentScroller.dispatchEvent(newEvent);
246
- } catch (err) {
247
- console.warn('无法转发触摸事件', err);
207
+ composed: true,
208
+ touches: createTouches(gestureData.touches),
209
+ targetTouches: createTouches(gestureData.targetTouches),
210
+ changedTouches: createTouches(gestureData.changedTouches),
211
+ ctrlKey: gestureData.ctrlKey,
212
+ shiftKey: gestureData.shiftKey,
213
+ altKey: gestureData.altKey,
214
+ metaKey: gestureData.metaKey
215
+ }));
216
+ } catch (e) {
217
+ console.warn('手势事件冒泡失败:', e);
248
218
  }
249
219
  },
250
220
  },
221
+ beforeDestroy() {
222
+ // 清理RAF避免内存泄漏
223
+ if (this._rafId) {
224
+ cancelAnimationFrame(this._rafId);
225
+ this._rafId = null;
226
+ }
227
+ // 清理消息监听
228
+ if (this._onMessage) {
229
+ window.removeEventListener("message", this._onMessage, false);
230
+ }
231
+ },
251
232
  };
252
233
  </script>
253
234