From 9d00fbc987a8f9731c9d6fe69475df6e30a32313 Mon Sep 17 00:00:00 2001 From: lanterngamescn Date: Sat, 27 Jun 2026 14:54:40 +0800 Subject: [PATCH] =?UTF-8?q?debug(share):=20onShare=20=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E5=8E=9F=E5=A7=8Bdata+=E8=A7=A3=E6=9E=90=E5=AD=97=E6=AE=B5+?= =?UTF-8?q?=E5=88=86=E6=94=AF=EF=BC=9B=E5=AD=97=E6=AE=B5=E5=BD=92=E4=B8=80?= =?UTF-8?q?string=E4=BF=AE=E6=95=B0=E5=AD=97type=E8=AF=AF=E8=90=BD?= =?UTF-8?q?=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/providers/ShareProvider.ets | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/feature_capabilities/src/main/ets/providers/ShareProvider.ets b/feature_capabilities/src/main/ets/providers/ShareProvider.ets index f810195..a0d11f3 100644 --- a/feature_capabilities/src/main/ets/providers/ShareProvider.ets +++ b/feature_capabilities/src/main/ets/providers/ShareProvider.ets @@ -88,6 +88,19 @@ export class ShareProvider implements CapabilityProvider { this.log.w('share bean empty'); return; } + // 调试:打印 H5 传入的原始 data(base64 截图会很长,hilog 可能截断,属正常)。 + this.log.i(`onShare raw=${data}`); + // H5 可能把数值字段当 number 传(如 type:2 而非 "2"),JSON.parse 后即 number, + // 会使 `bean.type === '2'` 严格比较失配而误落文本分支;故入站即把全字段归一为 string。 + bean.sharefriend = this.toStr(bean.sharefriend); + bean.type = this.toStr(bean.type); + bean.sharetype = this.toStr(bean.sharetype); + bean.webpageUrl = this.toStr(bean.webpageUrl); + bean.title = this.toStr(bean.title); + bean.description = this.toStr(bean.description); + this.log.i(`onShare bean sharefriend=${bean.sharefriend} type=${bean.type} ` + + `sharetype=${bean.sharetype} url=${bean.webpageUrl} ` + + `titleLen=${bean.title.length} descLen=${bean.description.length}`); if (bean.sharefriend === '2') { // 朋友圈语义:不弹面板,直接微信指引窗(契约 §10.1)。 this.startShare(bean, 'wechat'); @@ -134,12 +147,20 @@ export class ShareProvider implements CapabilityProvider { // —— 组装 + 弹指引窗 —— + /** H5 数值字段可能传 number/undefined,统一成 string(防 `=== '2'` 严格比较失配)。 */ + private toStr(v: string | number | boolean | undefined | null): string { + return (v === undefined || v === null) ? '' : `${v}`; + } + private startShare(bean: SharetypeBean, platform: string): void { if (bean.type === '2') { + this.log.i(`startShare -> canvas image (platform=${platform})`); this.startCanvasImageShare(bean, platform); } else if (bean.type === '3') { + this.log.i(`startShare -> link image (platform=${platform})`); this.startLinkImageShare(bean, platform); } else { + this.log.i(`startShare -> text (platform=${platform}, type='${bean.type}')`); this.startTextShare(bean, platform); } }