@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,24 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div>
|
|
3
|
-
<
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@
|
|
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:
|
|
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
|
|
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[
|
|
157
|
-
this.$refs[
|
|
167
|
+
if (this.$refs["iframe"]) {
|
|
168
|
+
this.$refs["iframe"].contentWindow.$midea_harmony_native =
|
|
158
169
|
window.$midea_harmony_native;
|
|
159
|
-
this.$refs[
|
|
160
|
-
this.$refs[
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
204
|
+
iframeEl.dispatchEvent(new TouchEvent(gestureData.eventType, {
|
|
236
205
|
bubbles: true,
|
|
237
206
|
cancelable: true,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
|