@dolphinweex/weex-harmony 0.1.89 → 0.1.90
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
|
@@ -126,40 +126,9 @@ export default {
|
|
|
126
126
|
} else {
|
|
127
127
|
this.debugWarn(`未找到iframe元素`);
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (!parentEl) return null;
|
|
133
|
-
|
|
134
|
-
const candidates = parentEl.querySelectorAll(".midea-common-weex-view");
|
|
135
|
-
// 用 CSS.escape 规避特殊字符(低端内核可用兜底)
|
|
136
|
-
const idSelector =
|
|
137
|
-
window.CSS && CSS.escape
|
|
138
|
-
? `#${CSS.escape(this.embedId)}`
|
|
139
|
-
: `[id="${this.embedId}"]`;
|
|
140
|
-
|
|
141
|
-
for (const el of candidates) {
|
|
142
|
-
if (el.querySelector(idSelector)) return el;
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
};
|
|
146
|
-
this._wrapperEl = findWrapperFromParent(); // 保存容器引用
|
|
147
|
-
|
|
148
|
-
// 直接获取父级元素,如果 hmcomponentindex 属性存在且值为 midea-common-weex-view,则保存引用
|
|
149
|
-
const parentEl = this.$el;
|
|
150
|
-
if (parentEl) {
|
|
151
|
-
const hmComponentIndex = parentEl.getAttribute('hmcomponentindex');
|
|
152
|
-
if (hmComponentIndex === 'midea-common-weex-view') {
|
|
153
|
-
this._parentElement = parentEl;
|
|
154
|
-
} else {
|
|
155
|
-
// 兜底:多数场景 this.$el 就是可控容器,避免因属性缺失导致无法同步高度
|
|
156
|
-
this._parentElement = parentEl;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// 包装器找不到时兜底到当前组件根节点
|
|
160
|
-
if (!this._wrapperEl && this.$el) {
|
|
161
|
-
this._wrapperEl = this.$el;
|
|
162
|
-
this.debugLog(`包装器兜底为当前组件根节点`);
|
|
129
|
+
this.refreshWrapperAndParent();
|
|
130
|
+
if (!this._wrapperEl) {
|
|
131
|
+
this.debugWarn(`未找到 iframe 父级 .midea-common-weex-view`);
|
|
163
132
|
}
|
|
164
133
|
|
|
165
134
|
// 优化手势处理性能
|
|
@@ -190,6 +159,14 @@ export default {
|
|
|
190
159
|
window.addEventListener("message", this._onMessage, false);
|
|
191
160
|
},
|
|
192
161
|
methods: {
|
|
162
|
+
refreshWrapperAndParent() {
|
|
163
|
+
const iframeNode = this.$refs.iframe;
|
|
164
|
+
if (!iframeNode) return;
|
|
165
|
+
const directParent = iframeNode.parentElement;
|
|
166
|
+
// 按约定:iframe 的直接父级就是业务容器(midea-common-weex-view*)
|
|
167
|
+
this._wrapperEl = directParent || null;
|
|
168
|
+
this._parentElement = this._wrapperEl;
|
|
169
|
+
},
|
|
193
170
|
debugLog(...args) {
|
|
194
171
|
if (this.isDebug) {
|
|
195
172
|
console.log('cdj----plugin@midea-common-weex-view.vue', ...args);
|
|
@@ -202,6 +179,7 @@ export default {
|
|
|
202
179
|
},
|
|
203
180
|
onPageFinish() {
|
|
204
181
|
this.debugLog(`onPageFinish 触发: embedId=${this.embedId}`);
|
|
182
|
+
this.refreshWrapperAndParent();
|
|
205
183
|
if (this.$refs["iframe"]) {
|
|
206
184
|
this.debugLog(`iframe引用存在,准备注入全局变量`);
|
|
207
185
|
this.$refs["iframe"].contentWindow.$midea_harmony_native =
|
|
@@ -256,11 +234,11 @@ export default {
|
|
|
256
234
|
}
|
|
257
235
|
|
|
258
236
|
// 结合元素本身尺寸指标,减少某些内核下 getBoundingClientRect 低估问题
|
|
259
|
-
const selfRect = parentRect.height || 0;
|
|
260
|
-
const selfScroll = el.scrollHeight || 0;
|
|
261
|
-
const selfOffset = el.offsetHeight || 0;
|
|
262
|
-
const selfClient = el.clientHeight || 0;
|
|
263
|
-
height = Math.max(height, selfRect, selfScroll, selfOffset, selfClient);
|
|
237
|
+
// const selfRect = parentRect.height || 0;
|
|
238
|
+
// const selfScroll = el.scrollHeight || 0;
|
|
239
|
+
// const selfOffset = el.offsetHeight || 0;
|
|
240
|
+
// const selfClient = el.clientHeight || 0;
|
|
241
|
+
// height = Math.max(height, selfRect, selfScroll, selfOffset, selfClient);
|
|
264
242
|
|
|
265
243
|
return height;
|
|
266
244
|
},
|
|
@@ -346,6 +324,8 @@ export default {
|
|
|
346
324
|
// 根据元素高度更新 iframe 高度
|
|
347
325
|
updateIframeHeightFromElement(element) {
|
|
348
326
|
this.debugLog(`updateIframeHeightFromElement 调用: element=${!!element}, embedId=${this.embedId}`);
|
|
327
|
+
// 每次更新前刷新一次,防止动态重渲染导致引用丢失
|
|
328
|
+
this.refreshWrapperAndParent();
|
|
349
329
|
if (!element) {
|
|
350
330
|
this.debugWarn(`updateIframeHeightFromElement: element为空`);
|
|
351
331
|
return;
|
|
@@ -402,25 +382,36 @@ export default {
|
|
|
402
382
|
|
|
403
383
|
// 更新 iframe 高度(考虑 weex scale)
|
|
404
384
|
const scale = weex.config.env.scale || 1;
|
|
405
|
-
|
|
385
|
+
let newHeightValue = finalHeight / scale;
|
|
406
386
|
|
|
407
|
-
//
|
|
387
|
+
// 父级有 style 设置的高度时:若 iframe 计算高度偏小,直接用父级高度
|
|
388
|
+
// newHeightValue 单位:Weex 虚拟 px;父级 getBoundingClientRect 单位:CSS px
|
|
389
|
+
// 两者转换关系:CSS px = Weex vp * scale,所以 Weex vp = CSS px / scale
|
|
408
390
|
if (this._wrapperEl) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
391
|
+
try {
|
|
392
|
+
const inlineHeight = this._wrapperEl.style && this._wrapperEl.style.height;
|
|
393
|
+
const parentHasExplicitHeight = !!(
|
|
394
|
+
inlineHeight && inlineHeight !== "auto" && inlineHeight !== "100%"
|
|
395
|
+
);
|
|
396
|
+
if (parentHasExplicitHeight) {
|
|
397
|
+
const wrapperCssPx = this._wrapperEl.getBoundingClientRect().height || 0;
|
|
398
|
+
const wrapperWeexVp = wrapperCssPx / scale;
|
|
399
|
+
this.debugLog(`父级有显式高度: inlineHeight=${inlineHeight}, wrapperCssPx=${wrapperCssPx}, wrapperWeexVp=${wrapperWeexVp}, calcWeexVp=${newHeightValue}`);
|
|
400
|
+
if (wrapperWeexVp > 0 && newHeightValue < wrapperWeexVp) {
|
|
401
|
+
this.debugLog(`iframe 偏小,使用父级高度: ${newHeightValue} -> ${wrapperWeexVp}`);
|
|
402
|
+
newHeightValue = wrapperWeexVp;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
} catch (e) {
|
|
406
|
+
this.debugWarn("读取父级高度失败:", e);
|
|
407
|
+
}
|
|
413
408
|
}
|
|
414
409
|
|
|
410
|
+
const newHeight = `${newHeightValue}px`;
|
|
415
411
|
this.debugLog(`计算newHeight=${newHeight} (finalHeight=${finalHeight}, scale=${scale}), 当前height=${this.height}`);
|
|
416
412
|
if (this.height !== newHeight) {
|
|
417
413
|
this.height = newHeight;
|
|
418
414
|
this.debugLog(`✅ iframe 高度已更新: ${finalHeight}px -> ${newHeight} (embedId: ${this.embedId}, max: ${maxHeight}px)`);
|
|
419
|
-
// 如果父级元素存在且符合条件,也给父级元素设置同样显示高度,防止内容被截断
|
|
420
|
-
if (this._parentElement) {
|
|
421
|
-
this._parentElement.style.height = newHeight;
|
|
422
|
-
this.debugLog(`更新父级元素高度: ${newHeight}`);
|
|
423
|
-
}
|
|
424
415
|
} else {
|
|
425
416
|
this.debugLog(`⚠️ 高度未变化,不更新 (当前=${this.height}, 新值=${newHeight})`);
|
|
426
417
|
}
|