@dolphinweex/weex-harmony 0.1.88 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolphinweex/weex-harmony",
3
- "version": "0.1.88",
3
+ "version": "0.1.90",
4
4
  "description": "weex harmony adapter",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -77,11 +77,11 @@ export default {
77
77
  }
78
78
  },
79
79
  created() {
80
- const componentType = this.embedType.replace('native/','')
81
- this.embedId = `embedId_${this._uid}_${this.generateNaiveId()}_${componentType}`
80
+ this.embedId = `embedId_${this._uid}_${this.generateNaiveId()}`
82
81
  console.log("[sameLayerRendering] web component created.");
83
82
  weexModule.callNative("transferSameLayerArgs", {
84
83
  componentId: this.embedId,
84
+ embedType: this.embedType,
85
85
  ...this.hosSameLayerArgs,
86
86
  });
87
87
  },
@@ -157,6 +157,7 @@ export default {
157
157
  this.$nextTick(() => {
158
158
  weexModule.callNative("transferSameLayerArgs", {
159
159
  componentId: this.embedId,
160
+ embedType: this.embedType,
160
161
  ...newVal,
161
162
  });
162
163
  });
@@ -126,32 +126,9 @@ export default {
126
126
  } else {
127
127
  this.debugWarn(`未找到iframe元素`);
128
128
  }
129
- // 从父组件根节点内查找:既是 .midea-common-weex-view,又包含当前 iframe 的 embedId
130
- const findWrapperFromParent = () => {
131
- const parentEl = this.$parent && this.$parent.$el;
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
- }
129
+ this.refreshWrapperAndParent();
130
+ if (!this._wrapperEl) {
131
+ this.debugWarn(`未找到 iframe 父级 .midea-common-weex-view`);
155
132
  }
156
133
 
157
134
  // 优化手势处理性能
@@ -182,6 +159,14 @@ export default {
182
159
  window.addEventListener("message", this._onMessage, false);
183
160
  },
184
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
+ },
185
170
  debugLog(...args) {
186
171
  if (this.isDebug) {
187
172
  console.log('cdj----plugin@midea-common-weex-view.vue', ...args);
@@ -194,6 +179,7 @@ export default {
194
179
  },
195
180
  onPageFinish() {
196
181
  this.debugLog(`onPageFinish 触发: embedId=${this.embedId}`);
182
+ this.refreshWrapperAndParent();
197
183
  if (this.$refs["iframe"]) {
198
184
  this.debugLog(`iframe引用存在,准备注入全局变量`);
199
185
  this.$refs["iframe"].contentWindow.$midea_harmony_native =
@@ -246,6 +232,13 @@ export default {
246
232
  if (height <= 0) {
247
233
  height = totalOffsetHeight;
248
234
  }
235
+
236
+ // 结合元素本身尺寸指标,减少某些内核下 getBoundingClientRect 低估问题
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);
249
242
 
250
243
  return height;
251
244
  },
@@ -331,6 +324,8 @@ export default {
331
324
  // 根据元素高度更新 iframe 高度
332
325
  updateIframeHeightFromElement(element) {
333
326
  this.debugLog(`updateIframeHeightFromElement 调用: element=${!!element}, embedId=${this.embedId}`);
327
+ // 每次更新前刷新一次,防止动态重渲染导致引用丢失
328
+ this.refreshWrapperAndParent();
334
329
  if (!element) {
335
330
  this.debugWarn(`updateIframeHeightFromElement: element为空`);
336
331
  return;
@@ -355,56 +350,68 @@ export default {
355
350
  this.debugLog(`计算得到elementHeight=${elementHeight}px`);
356
351
 
357
352
  if (elementHeight > 0) {
358
- // 限制最大高度,防止死循环
359
- // 策略:使用 window.innerHeight 减去 iframe 距离视口顶部的距离
360
- let maxHeight = window.innerHeight;
361
- this.debugLog(`初始maxHeight(window.innerHeight)=${maxHeight}px`);
353
+ // 默认不按当前视口剩余高度裁剪,避免可滚动页面中 iframe 被错误截断。
354
+ // plugin-menu 页面保持原有“限制在可视区”策略。
355
+ let maxHeight = Number.POSITIVE_INFINITY;
356
+ this.debugLog(`初始maxHeight=${maxHeight}px (isPluginMenu=${this.isPluginMenu})`);
362
357
 
363
- if (this.$refs.iframe) {
364
- try {
365
- const rect = this.$refs.iframe.getBoundingClientRect();
366
- this.debugLog(`iframe位置: top=${rect.top}, left=${rect.left}, width=${rect.width}, height=${rect.height}`);
367
- // 如果 top > 0,说明 iframe 顶部在视口下方或视口内,减去 top 得到剩余可用高度
368
- // 如果 top <= 0,说明 iframe 顶部已滚出视口上方,此时最大高度限制为 window.innerHeight (防止无限增高)
369
- if (rect.top > 0) {
370
- maxHeight = window.innerHeight - rect.top;
371
- this.debugLog(`调整后maxHeight=${maxHeight}px (top=${rect.top})`);
358
+ if (this.isPluginMenu) {
359
+ maxHeight = window.innerHeight;
360
+ if (this.$refs.iframe) {
361
+ try {
362
+ const rect = this.$refs.iframe.getBoundingClientRect();
363
+ this.debugLog(`iframe位置: top=${rect.top}, left=${rect.left}, width=${rect.width}, height=${rect.height}`);
364
+ if (rect.top > 0) {
365
+ maxHeight = window.innerHeight - rect.top;
366
+ this.debugLog(`plugin-menu 调整后maxHeight=${maxHeight}px (top=${rect.top})`);
367
+ }
368
+ } catch (e) {
369
+ this.debugWarn('获取 iframe 位置失败:', e);
372
370
  }
373
- } catch (e) {
374
- this.debugWarn('获取 iframe 位置失败:', e);
371
+ } else {
372
+ this.debugWarn(`this.$refs.iframe 不存在`);
375
373
  }
376
- } else {
377
- this.debugWarn(`this.$refs.iframe 不存在`);
374
+ maxHeight = Math.max(maxHeight, 0);
378
375
  }
379
376
 
380
- // 确保 maxHeight 不为负数
381
- maxHeight = Math.max(maxHeight, 0);
382
377
  this.debugLog(`最终maxHeight=${maxHeight}px`);
383
378
 
384
- // 如果计算出的高度超过了最大限制,则使用最大限制
385
- const finalHeight = !this.isPluginMenu ? elementHeight > maxHeight ? maxHeight : elementHeight : elementHeight
379
+ // 非 plugin-menu 不裁剪;plugin-menu 才按 maxHeight 限制
380
+ const finalHeight = elementHeight > maxHeight ? maxHeight : elementHeight;
386
381
  this.debugLog(`finalHeight=${finalHeight}px (isPluginMenu=${this.isPluginMenu}, elementHeight=${elementHeight}, maxHeight=${maxHeight})`);
387
382
 
388
- // 更新包装器高度
389
- if (this._wrapperEl) {
390
- this._wrapperEl.style.height = `${finalHeight}px`;
391
- this.debugLog(`更新包装器高度: ${finalHeight}px`);
392
- } else {
393
- this.debugLog(`包装器元素不存在`);
394
- }
395
-
396
383
  // 更新 iframe 高度(考虑 weex scale)
397
384
  const scale = weex.config.env.scale || 1;
398
- const newHeight = `${finalHeight / scale}px`;
385
+ let newHeightValue = finalHeight / scale;
386
+
387
+ // 父级有 style 设置的高度时:若 iframe 计算高度偏小,直接用父级高度
388
+ // newHeightValue 单位:Weex 虚拟 px;父级 getBoundingClientRect 单位:CSS px
389
+ // 两者转换关系:CSS px = Weex vp * scale,所以 Weex vp = CSS px / scale
390
+ if (this._wrapperEl) {
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
+ }
408
+ }
409
+
410
+ const newHeight = `${newHeightValue}px`;
399
411
  this.debugLog(`计算newHeight=${newHeight} (finalHeight=${finalHeight}, scale=${scale}), 当前height=${this.height}`);
400
412
  if (this.height !== newHeight) {
401
413
  this.height = newHeight;
402
414
  this.debugLog(`✅ iframe 高度已更新: ${finalHeight}px -> ${newHeight} (embedId: ${this.embedId}, max: ${maxHeight}px)`);
403
- // 如果父级元素存在且符合条件,也给父级元素设置高度
404
- if (this._parentElement) {
405
- this._parentElement.style.height = `${finalHeight}px`;
406
- this.debugLog(`更新父级元素高度: ${finalHeight}px`);
407
- }
408
415
  } else {
409
416
  this.debugLog(`⚠️ 高度未变化,不更新 (当前=${this.height}, 新值=${newHeight})`);
410
417
  }
@@ -257,7 +257,7 @@ export default {
257
257
  onPreviewImageClick(res) {
258
258
  this.$emit('onPreviewImageClick', res);
259
259
  },
260
- onCaptureCompletion(){
260
+ onCaptureCompletion(res){
261
261
  this.$emit('onCaptureCompletion', res);
262
262
  }
263
263
  },