//写一个init的函数来获取微信配置信息。apis里面是jS接口列表。back是接口用wx.接口名。对应apis里面的接口。使用wxapi的时候都调用一次
var init = function (apis, back) {
api("WechatShare/share", { url: (location + '').replace(/#.+/, "") },10).then(db => {
var config = {
debug: false,
jsApiList: apis,
...db
};
wx.ready(() => {
back&&back(config);
});
});
}
export default {
// 自己写的函数,便于传值
hideMenuItems() {
init([
'hideOptionMenu'
], wx.hideOptionMenu)
},
showMenuItems(title,imgUrl,spid,uid, type = 4,desc) { //,desc可以选填副标题
init(["onMenuShareTimeline",
"showAllNonBaseMenuItem",
"onMenuShareAppMessage",
"showOptionMenu"
], (cf) => {
var link="http://zlwx.w6soft.com/index.php/Login/wxshare?state=" + type + "@" + spid + "@" + uid;
wx.showOptionMenu();
wx.onMenuShareTimeline( {
title,// 分享标题
link:link+"@2", // 分享链接
imgUrl: imgUrl || "", // 分享图标
success: function () {
mui.toast("分享成功")
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
}); //分享到朋友圈
wx.onMenuShareAppMessage({ //分享给朋友
title, // 分享标题
desc: desc||title , // 分享描述
link:link+"@1", // 分享链接
imgUrl,
type: 'link', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
mui.toast("分享成功")
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
})
},
//微信获取当前地址
getlocal(fun,cancel){ //cancal是个用户关闭获取地址的调用函数
init([
"getLocation"
],(cf)=>{
wx.getLocation({
type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
fun(latitude,longitude);
},
cancel
});
});
},
}