uniapp 开发应用打包成 Android app,其中有一个页面,通过 pages.json
配置导航栏,页面内容为 web-view
,用于展示外部网页;
但是需要有分享,所以配置了分享按钮,如下:
,{
"path" : "pages/webview/index",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false,
"app-plus": {
"titleNView": {
"backgroundColor": "#fff",
"titleAlign": "center",
"titleSize": "16px",
"buttons": [
{
"type": "share",
"fontSize": "56rpx",
"background": "rgba(0,0,0,0)"
}
],
"backButton": {
"fontSize": "20px",
"fontWeight": "bold"
}
}
}
},
}
然后分享按钮点击事件:
methods: {
onNavigationBarButtonTap(obj) {
this.showShareView()
},
initShare(){
const shareInfo = {
href: this.src,
title: this.title,
desc: this.title,
imgUrl: "/static/logo.png"
};
const shareList = [{
icon: "/static/sharemenu/wx.png",
text: "微信好友",
},
{
icon: "/static/sharemenu/pyq.png",
text: "朋友圈"
},
// {
// icon: "/static/sharemenu/weibo.png",
// text: "微博"
// },
// {
// icon: "/static/sharemenu/qq.png",
// text: "QQ"
// },
// {
// icon: "/static/sharemenu/copy.png",
// text: "复制"
// },
// {
// icon: "/static/sharemenu/more.png",
// text: "更多"
// }
];
const shareObj = {
href: shareInfo.href || "",
title: shareInfo.title || "",
summary: shareInfo.desc || "",
type: 0,
imageUrl: shareInfo.imgUrl,
success: (res) => {
console.log("success:" + JSON.stringify(res));
},
fail: (err) => {
console.log("fail:" + JSON.stringify(err));
}
};
//初始化分享;
this.shareObj.init(shareList,(index) => {
console.log("点击按钮的序号: " + index);
this.toast('点击:' + index)
switch (index) {
case 0:
uni.share(Object.assign({},shareObj,{
provider:"weixin",
scene:"WXSceneSession" //分享到聊天界面
}));
break;
case 1:
uni.share(Object.assign({},shareObj,{
provider:"weixin",
scene:"WXSenceTimeline" //分享到朋友圈
}));
break;
case 2:
uni.share(Object.assign({},shareObj,{
provider:"sinaweibo"
}));
break;
case 3:
uni.share(Object.assign({},shareObj,{
provider:"qq",
type:1
}));
break;
case 4:
uni.setClipboardData({
data: shareInfo.href,
complete() {
uni.showToast({
title: "已复制到剪贴板"
})
}
})
break;
case 5:
plus.share.sendWithSystem({
type: "web",
title: shareInfo.title || "",
thumbs: [shareInfo.imgUrl || ""],
href: shareInfo.href || "",
content: shareInfo.desc || "",
})
break;
};
});
},
}
点击分享到”微信好友“时候,也就是
uni.share(Object.assign({},shareObj,{
provider:"weixin",
scene:"WXSceneSession" //分享到聊天界面
}));
的时候,错误提示如下: