debug(share): onShare 打印原始data+解析字段+分支;字段归一string修数字type误落文本
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user