HBuilderX 版本:2.3.3.20190923
manifest.json 中已配置微信分享相关参数
// #ifdef APP-PLUS
var screenWidth = plus.screen.resolutionWidth
var margin = 25,
iconWidth = 55,
icontextSpace = 5,
textHeight = 12
var left1 = margin / 360 * screenWidth
var iconSpace = (screenWidth - (left1 * 2) - (iconWidth * 4)) / 3
if (iconSpace <= 5) { //屏幕过窄时,缩小边距和图标大小,再算一次
margin = 15
iconWidth = 40
left1 = margin / 360 * screenWidth
iconSpace = (screenWidth - (left1 * 2) - (iconWidth * 4)) / 3
}
var left2 = left1 + iconWidth + iconSpace
var left3 = left1 + (iconWidth + iconSpace) * 2
var left4 = left1 + (iconWidth + iconSpace) * 3
var top1 = left1
var top2 = top1 + iconWidth + icontextSpace + textHeight + left1
var nvMask = new plus.nativeObj.View("nvMask", { //先创建遮罩层
top: '0px',
left: '0px',
height: '100%',
width: '100%',
backgroundColor: 'rgba(0,0,0,0.7)'
});
nvMask.addEventListener("click", function() { //处理遮罩层点击
nvMask.hide();
nvImageMenu.hide();
})
var nvImageMenu = new plus.nativeObj.View("nvImageMenu", { //创建底部图标菜单
bottom: '0px',
left: '0px',
height: '164px',
width: '100%',
backgroundColor: 'rgb(255,255,255)'
});
//绘制底部图标菜单的内容
nvImageMenu.draw([{
tag: 'rect', //菜单顶部的分割灰线
color: '#e7e7e7',
position: {
top: '0px',
height: '1px'
}
},
{
tag: 'font',
id: 'sharecancel', //底部取消按钮的文字
text: '取消分享',
textStyles: {
size: '14px'
},
position: {
bottom: '0px',
height: '44px'
}
},
{
tag: 'rect', //底部取消按钮的顶部边线
color: '#e7e7e7',
position: {
bottom: '45px',
height: '1px'
}
},
{
tag: 'img',
id: 'imgwechatfriend',
src: '/static/wechatfriend.png',
position: {
top: top1,
left: left1,
width: iconWidth,
height: iconWidth
}
},
{
tag: 'font',
id: 'fontwechatfriend',
text: '微信好友',
textStyles: {
size: textHeight
},
position: {
top: top1 + iconWidth + icontextSpace,
left: left1,
width: iconWidth,
height: textHeight
}
},
{
tag: 'img',
id: 'imgwechatmoments',
src: '/static/wechatmoments.png',
position: {
top: top1,
left: left2,
width: iconWidth,
height: iconWidth
}
},
{
tag: 'font',
id: 'fontwechatmoments',
text: '微信朋友圈',
textStyles: {
size: textHeight
},
position: {
top: top1 + iconWidth + icontextSpace,
left: left2 - 2.5,
width: iconWidth + 5,
height: textHeight
}
},
{
tag: 'img',
id: 'imgcopyurl',
src: '/static/copyurl.png',
position: {
top: top1,
left: left3,
width: iconWidth,
height: iconWidth
}
},
{
tag: 'font',
id: 'fontcopyurl',
text: '复制',
textStyles: {
size: textHeight
},
position: {
top: top1 + iconWidth + icontextSpace,
left: left3,
width: iconWidth,
height: textHeight
}
},
])
nvImageMenu.addEventListener("click", function(e) { //处理底部图标菜单的点击事件
if (e.screenY > plus.screen.resolutionHeight - 44) { //点击了底部取消按钮
nvMask.hide();
nvImageMenu.hide();
} else if (e.clientX < 5 || e.clientX > screenWidth - 5 || e.clientY < 5) {
//屏幕左右边缘5像素及菜单顶部5像素不处理点击
} else { //点击图标按钮
var iClickIndex = -1 //点击的图标按钮序号,第一个图标按钮的index为0
var iRow = e.clientY < (top2 - (left1 / 2)) ? 0 : 1
var iCol = -1
if (e.clientX < (left2 - (iconSpace / 2))) {
iCol = 0
} else if (e.clientX < (left3 - (iconSpace / 2))) {
iCol = 1
} else if (e.clientX < (left4 - (iconSpace / 2))) {
iCol = 2
} else {
iCol = 3
}
if (iRow == 0) {
iClickIndex = iCol
} else {
iClickIndex = iCol + 4
}
let obj = getApp().globalData.news_dtl;
if (iClickIndex >= 0 && iClickIndex <= 5) {
var strProvider = "",
strScene = ""
switch (iClickIndex) {
case 0:
strProvider = "weixin"
strScene = "WXSceneSession"
break;
case 1:
strProvider = "weixin"
strScene = "WXSenceTimeline"
break;
case 2:
uni.setClipboardData({
data: `http://www.zmhgj.cn/h5/#/pages/home_page/xw_dtl?id=${obj.id}`,
complete() {
uni.showToast({
title: "已复制到剪贴板"
})
}
})
break;
case 5:
plus.share.sendWithSystem({
content: `http://www.zmhgj.cn/h5/#/pages/home_page/xw_dtl?id=${obj.id}`,
})
break;
}
if (strProvider != "") {
uni.share({
provider: strProvider,
scene: strScene,
type: 0,
href: `http://www.zmhgj.cn/h5/#/pages/home_page/xw_dtl?id=${obj.id}`,
title: `${obj.title}`,
summary: `${obj.newsFrom}`,
imageUrl: 'http://www.zmhgj.cn/static/images/persion_tou.png',
success: (res) => {},
fail: (err) => {}
});
}
}
}
})
export default {
onBackPress() {
//监听back键,关闭弹出菜单
if (nvImageMenu.isVisible()) {
nvImageMenu.hide()
nvMask.hide()
return true
}
},
methods: {
share_click() {
nvMask.show()
nvImageMenu.show()
},
}
}
// #endif
2 个回复
1***@qq.com (作者)
在苹果手机上调试的一直报这个错误:
"errMsg": "share:fail:[Share微信:-95]未知错误,http://ask.dcloud.net.cn/article/287"
-95 分享href或文本为空、图片路径不对或加载失败或其他错误
但是路径是对的,安卓上可以正常分享没问题的。苦恼中...
1***@qq.com (作者)
也没人回复,自己回复一下吧:找到问题啦,其实就是下面这个图片路径找不到,哈哈哈
imageUrl: 'http://www.zmhgj.cn/static/images/persion_tou.png',