配置分享 configShare
配置分享 configShare
配置右上角分享按钮,若当前处于禁用分享的状态,会自动取消禁用分享
API
configShare(options: Options) => Promise<void>;
Example
基本用法
zanNativeBridge.configShare({
title: '分享标题',
desc: '分享描述',
link: 'https://www.youzan.com',
imgUrl: 'https://img.yzcdn.cn/public_files/2019/06/15/a93560b87122b31e8e3eead33f165bb6.jpg'
}).catch(() => {});
小程序 WebView 内分享
小程序端通过监听 message 事件获取到配置后,在 onShareAppMessage 中返回即可。
zanNativeBridge.configShare({
title: '分享标题',
desc: '分享描述',
link: 'https://www.youzan.com',
imgUrl: 'https://img.yzcdn.cn/public_files/2019/06/15/a93560b87122b31e8e3eead33f165bb6.jpg',
weappPath: '/packages/home/index'
}).catch(() => {});
// 小程序端代码
// 接受到的 message 结构为:
// {
// type: 'ZNB.share',
// config: {
// title: '分享标题',
// imageUrl: 'https://img.yzcdn.cn/public_files/2019/06/15/a93560b87122b31e8e3eead33f165bb6.jpg',
// path: '/packages/home/index'
// }
// }
Page({
onMessage(event) {
const messages = event.detail.data;
const shareMessages = messages.filter(message => message.type === 'ZNB.share');
this.shareConfig = shareMessages.pop().config;
},
onShareAppMessage() {
return this.shareConfig;
}
});
自定义分享渠道
zanNativeBridge.configShare({
title: '分享标题',
desc: '分享描述',
link: 'https://www.youzan.com',
imgUrl: 'https://img.yzcdn.cn/1.jpeg',
channels: ['appMessage'],
}).catch(() => {});
在微信内可以通过channels字段配置不同渠道的分享信息,channels字段的可选值如下:
| 可选值 | 说明 |
|---|---|
'appMessage' |
微信 |
'timeline' |
朋友圈 |
'qq' |
|
'qzone' |
QQ 空间 |
Options
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| title | 标题 | string | - |
| desc | 描述 | string | - |
| link | 链接,不支持相对路径,须包含完整域名 | string | - |
| imgUrl | 图标 | string | - |
| weappPath | 分享的小程序路径 | string |
默认使用 WebView 页面路径拼接 link 字段,WebView 页面可在 init 函数中配置 |
| channels | 分享的渠道 | array | 腾讯系默认配置:['appMessage', 'timeline', 'qq', 'qzone'] |
| showOptionMenu | 是否显示右上角分享菜单 | boolean | true |
兼容性
| 平台 | 是否支持 |
|---|---|
| browser | ✖️ |
| ✔ | |
| weapp | ✔ |
| alipay | ✖️ |
| youzan | ✖️ |
| guang | ✖️ |