@dolphinweex/weex-harmony 0.1.75 → 0.1.76

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.75",
3
+ "version": "0.1.76",
4
4
  "description": "weex harmony adapter",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -256,16 +256,39 @@ export default {
256
256
  const elementHeight = element.offsetHeight || element.clientHeight || element.scrollHeight;
257
257
 
258
258
  if (elementHeight > 0) {
259
+ // 限制最大高度,防止死循环
260
+ // 策略:使用 window.innerHeight 减去 iframe 距离视口顶部的距离
261
+ let maxHeight = window.innerHeight;
262
+
263
+ if (this.$refs.iframe) {
264
+ try {
265
+ const rect = this.$refs.iframe.getBoundingClientRect();
266
+ // 如果 top > 0,说明 iframe 顶部在视口下方或视口内,减去 top 得到剩余可用高度
267
+ // 如果 top <= 0,说明 iframe 顶部已滚出视口上方,此时最大高度限制为 window.innerHeight (防止无限增高)
268
+ if (rect.top > 0) {
269
+ maxHeight = window.innerHeight - rect.top;
270
+ }
271
+ } catch (e) {
272
+ console.warn('获取 iframe 位置失败:', e);
273
+ }
274
+ }
275
+
276
+ // 确保 maxHeight 不为负数
277
+ maxHeight = Math.max(maxHeight, 0);
278
+
279
+ // 如果计算出的高度超过了最大限制,则使用最大限制
280
+ const finalHeight = elementHeight > maxHeight ? maxHeight : elementHeight;
281
+
259
282
  // 更新包装器高度
260
283
  if (this._wrapperEl) {
261
- this._wrapperEl.style.height = `${elementHeight}px`;
284
+ this._wrapperEl.style.height = `${finalHeight}px`;
262
285
  }
263
286
 
264
287
  // 更新 iframe 高度(考虑 weex scale)
265
- const newHeight = `${elementHeight / weex.config.env.scale}px`;
288
+ const newHeight = `${finalHeight / weex.config.env.scale}px`;
266
289
  if (this.height !== newHeight) {
267
290
  this.height = newHeight;
268
- console.log(`iframe 高度已更新: ${elementHeight}px -> ${newHeight} (embedId: ${this.embedId})`);
291
+ console.log(`iframe 高度已更新: ${finalHeight}px -> ${newHeight} (embedId: ${this.embedId}, max: ${maxHeight}px)`);
269
292
  }
270
293
  }
271
294
  },