@dolphinweex/weex-harmony 0.1.89 → 0.1.91
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;
|
|
@@ -370,57 +350,49 @@ export default {
|
|
|
370
350
|
this.debugLog(`计算得到elementHeight=${elementHeight}px`);
|
|
371
351
|
|
|
372
352
|
if (elementHeight > 0) {
|
|
373
|
-
//
|
|
374
|
-
//
|
|
353
|
+
// isPluginMenu=false:始终不按视口裁剪,保持原逻辑不变。
|
|
354
|
+
// isPluginMenu=true:改为不裁剪,避免多组件时下方 iframe 被裁成一条线、且裁剪值同步到父级压扁整块。
|
|
375
355
|
let maxHeight = Number.POSITIVE_INFINITY;
|
|
376
|
-
this.debugLog(`初始maxHeight=${maxHeight}px (isPluginMenu=${this.isPluginMenu})`);
|
|
377
|
-
|
|
378
356
|
if (this.isPluginMenu) {
|
|
379
|
-
maxHeight =
|
|
380
|
-
if (this.$refs.iframe) {
|
|
381
|
-
try {
|
|
382
|
-
const rect = this.$refs.iframe.getBoundingClientRect();
|
|
383
|
-
this.debugLog(`iframe位置: top=${rect.top}, left=${rect.left}, width=${rect.width}, height=${rect.height}`);
|
|
384
|
-
if (rect.top > 0) {
|
|
385
|
-
maxHeight = window.innerHeight - rect.top;
|
|
386
|
-
this.debugLog(`plugin-menu 调整后maxHeight=${maxHeight}px (top=${rect.top})`);
|
|
387
|
-
}
|
|
388
|
-
} catch (e) {
|
|
389
|
-
this.debugWarn('获取 iframe 位置失败:', e);
|
|
390
|
-
}
|
|
391
|
-
} else {
|
|
392
|
-
this.debugWarn(`this.$refs.iframe 不存在`);
|
|
393
|
-
}
|
|
394
|
-
maxHeight = Math.max(maxHeight, 0);
|
|
357
|
+
maxHeight = Number.POSITIVE_INFINITY; // 仅对 plugin-menu 取消视口裁剪,不影响 isPluginMenu=false
|
|
395
358
|
}
|
|
396
|
-
|
|
397
|
-
this.debugLog(`最终maxHeight=${maxHeight}px`);
|
|
359
|
+
this.debugLog(`maxHeight=${maxHeight} (isPluginMenu=${this.isPluginMenu})`);
|
|
398
360
|
|
|
399
|
-
// 非 plugin-menu 不裁剪;plugin-menu 才按 maxHeight 限制
|
|
400
361
|
const finalHeight = elementHeight > maxHeight ? maxHeight : elementHeight;
|
|
401
|
-
this.debugLog(`finalHeight=${finalHeight}px (
|
|
362
|
+
this.debugLog(`finalHeight=${finalHeight}px (elementHeight=${elementHeight}, maxHeight=${maxHeight})`);
|
|
402
363
|
|
|
403
364
|
// 更新 iframe 高度(考虑 weex scale)
|
|
404
365
|
const scale = weex.config.env.scale || 1;
|
|
405
|
-
|
|
366
|
+
let newHeightValue = finalHeight / scale;
|
|
406
367
|
|
|
407
|
-
//
|
|
368
|
+
// 父级有 style 设置的高度时:若 iframe 计算高度偏小,直接用父级高度
|
|
369
|
+
// 关键:直接解析 inline style 字符串(rem/px),而不用 getBoundingClientRect,
|
|
370
|
+
// 避免因为内容撑大或旧代码写入导致取到错误的"当前渲染高度"
|
|
408
371
|
if (this._wrapperEl) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
372
|
+
try {
|
|
373
|
+
const inlineHeight = this._wrapperEl.style && this._wrapperEl.style.height;
|
|
374
|
+
const parentHasExplicitHeight = !!(
|
|
375
|
+
inlineHeight && inlineHeight !== "auto" && inlineHeight !== "100%"
|
|
376
|
+
);
|
|
377
|
+
if (parentHasExplicitHeight) {
|
|
378
|
+
const wrapperCssPx = this._wrapperEl.getBoundingClientRect().height || 0;
|
|
379
|
+
const wrapperWeexVp = wrapperCssPx / scale;
|
|
380
|
+
this.debugLog(`父级有显式高度: inlineHeight=${inlineHeight}, wrapperCssPx=${wrapperCssPx}, wrapperWeexVp=${wrapperWeexVp}, calcWeexVp=${newHeightValue}`);
|
|
381
|
+
if (wrapperWeexVp > 0 && newHeightValue < wrapperWeexVp) {
|
|
382
|
+
this.debugLog(`iframe 偏小,使用父级高度: ${newHeightValue} -> ${wrapperWeexVp}`);
|
|
383
|
+
newHeightValue = wrapperWeexVp;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
} catch (e) {
|
|
387
|
+
this.debugWarn("读取父级高度失败:", e);
|
|
388
|
+
}
|
|
413
389
|
}
|
|
414
390
|
|
|
391
|
+
const newHeight = `${newHeightValue}px`;
|
|
415
392
|
this.debugLog(`计算newHeight=${newHeight} (finalHeight=${finalHeight}, scale=${scale}), 当前height=${this.height}`);
|
|
416
393
|
if (this.height !== newHeight) {
|
|
417
394
|
this.height = newHeight;
|
|
418
|
-
this.debugLog(`✅ iframe 高度已更新: ${finalHeight}px -> ${newHeight} (embedId: ${this.embedId}
|
|
419
|
-
// 如果父级元素存在且符合条件,也给父级元素设置同样显示高度,防止内容被截断
|
|
420
|
-
if (this._parentElement) {
|
|
421
|
-
this._parentElement.style.height = newHeight;
|
|
422
|
-
this.debugLog(`更新父级元素高度: ${newHeight}`);
|
|
423
|
-
}
|
|
395
|
+
this.debugLog(`✅ iframe 高度已更新: ${finalHeight}px -> ${newHeight} (embedId: ${this.embedId})`);
|
|
424
396
|
} else {
|
|
425
397
|
this.debugLog(`⚠️ 高度未变化,不更新 (当前=${this.height}, 新值=${newHeight})`);
|
|
426
398
|
}
|